keras-team/keras · error · ValueError

Received: {factor_name}={factor}

Error message

Received: {factor_name}={factor}

What it means

Raised by RandomZoom's _set_factor when height_factor or width_factor is a sequence whose length is not 2. Zoom factors must be a single positive fraction or a [lower, upper] pair; a zoom factor of 1.0 or more on the lower bound is invalid because it would mean no zoom or magnification beyond the input.

Source

Thrown at keras/src/layers/preprocessing/image_preprocessing/random_zoom.py:151

            )
        if interpolation not in self._SUPPORTED_INTERPOLATION:
            raise NotImplementedError(
                f"Unknown `interpolation` {interpolation}. Expected of one "
                f"{self._SUPPORTED_INTERPOLATION}."
            )

        self.fill_mode = fill_mode
        self.fill_value = fill_value
        self.interpolation = interpolation
        self.seed = seed
        self.generator = SeedGenerator(seed)
        self.data_format = backend.standardize_data_format(data_format)
        self.supports_jit = False

    def _set_factor(self, factor, factor_name):
        if isinstance(factor, (tuple, list)):
            if len(factor) != 2:
                raise ValueError(
                    self._FACTOR_VALIDATION_ERROR
                    + f"Received: {factor_name}={factor}"
                )
            self._check_factor_range(factor[0])
            self._check_factor_range(factor[1])
            lower, upper = sorted(factor)
        elif isinstance(factor, (int, float)):
            self._check_factor_range(factor)
            factor = abs(factor)
            lower, upper = [-factor, factor]
        else:
            raise ValueError(
                self._FACTOR_VALIDATION_ERROR
                + f"Received: {factor_name}={factor}"
            )
        return lower, upper

    def _check_factor_range(self, input_number):

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Pass a single fraction, e.g. RandomZoom(0.2)
  2. Pass exactly two bounds, e.g. RandomZoom(height_factor=(0.1, 0.3))

Example fix

// before
layer = RandomZoom(height_factor=[0.1, 0.2, 0.3])
// after
layer = RandomZoom(height_factor=(0.1, 0.3))
Defensive patterns

Strategy: validation

Validate before calling

for name, f in (("height_factor", h), ("width_factor", w)):
    if f is not None:
        assert isinstance(f, (int, float)) or (isinstance(f, (tuple, list)) and len(f) == 2), name

Type guard

import numbers
def is_zoom_factor(f):
    return f is None or isinstance(f, numbers.Number) or (isinstance(f, (tuple, list)) and len(f) == 2 and all(isinstance(x, numbers.Number) for x in f))

Try / catch

try:
    layer = RandomZoom(h, w)
except ValueError as e:
    raise ValueError(f"Bad zoom factors: h={h!r}, w={w!r}") from e

Prevention

When it happens

Trigger: Calling RandomZoom(height_factor=[0.1, 0.2, 0.3]) or width_factor=(0.2,).

Common situations: Config-driven augmentation pipelines producing variable-length lists; merging height/width ranges incorrectly.

Related errors


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