keras-team/keras · warning · ValueError

`zoom_range` should be a tuple or list of two floats. Receiv

Error message

`zoom_range` should be a tuple or list of two floats. Received: {zoom_range}

What it means

Deprecated function keras.src.legacy.preprocessing.image.random_zoom requires zoom_range as a sequence of exactly two floats [zx_min, zx_max]; a scalar float is not accepted here (unlike the constructor).

Source

Thrown at keras/src/legacy/preprocessing/image.py:1638

        order=interpolation_order,
    )
    return x


@keras_export("keras._legacy.preprocessing.image.random_zoom")
def random_zoom(
    x,
    zoom_range,
    row_axis=1,
    col_axis=2,
    channel_axis=0,
    fill_mode="nearest",
    cval=0.0,
    interpolation_order=1,
):
    """DEPRECATED."""
    if len(zoom_range) != 2:
        raise ValueError(
            "`zoom_range` should be a tuple or list of two floats. "
            f"Received: {zoom_range}"
        )

    if zoom_range[0] == 1 and zoom_range[1] == 1:
        zx, zy = 1, 1
    else:
        zx, zy = np.random.uniform(zoom_range[0], zoom_range[1], 2)
    x = apply_affine_transform(
        x,
        zx=zx,
        zy=zy,
        row_axis=row_axis,
        col_axis=col_axis,
        channel_axis=channel_axis,
        fill_mode=fill_mode,
        cval=cval,
        order=interpolation_order,

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Pass a 2-element list: random_zoom(x, [0.8, 1.2])
  2. Prefer the non-deprecated random_zoom in keras.ops or use the generator's zoom
  3. If scalar desired, expand: [1-z, 1+z]

Example fix

// before
random_zoom(x, zoom_range=0.2)
// after
random_zoom(x, zoom_range=[0.8, 1.2])
Defensive patterns

Strategy: validation

Validate before calling

assert len(zoom_range) == 2

Type guard

def zoom2(z): return isinstance(z,(list,tuple)) and len(z)==2

Try / catch

try: random_zoom(x, zr)
except ValueError as e: if 'zoom_range' in str(e): zr = [0.8, 1.2]

Prevention

When it happens

Trigger: Directly calling random_zoom(x, zoom_range=0.2) or with a 1-element list.

Common situations: Copy-pasting a scalar zoom from ImageDataGenerator config into the standalone function; porting old Keras scripts.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/aa9242898f9592c0. Report an issue: GitHub.