keras-team/keras · error · ValueError

Received: input_number={input_number}

Error message

Received: input_number={input_number}

What it means

Raised by RandomZoom's _check_factor_range when a zoom factor is greater than 1.0 or <= -1.0. The range is asymmetric: a lower bound of exactly -1.0 is rejected because a zoom factor of -1.0 would collapse the image to nothing, while +1.0 is allowed.

Source

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

                    + 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):
        if input_number > 1.0 or input_number <= -1.0:
            raise ValueError(
                self._FACTOR_VALIDATION_ERROR
                + f"Received: input_number={input_number}"
            )

    def _transform_images(self, images, transformation, interpolation):
        return self._zoom_inputs(images, transformation, interpolation)

    def transform_labels(self, labels, transformation, training=True):
        return labels

    def get_transformed_x_y(self, x, y, transform):
        a0, a1, a2, b0, b1, b2, c0, c1 = self.backend.numpy.split(
            transform, 8, axis=-1
        )

        k = c0 * x + c1 * y + 1
        x_transformed = (a0 * x + a1 * y + a2) / k
        y_transformed = (b0 * x + b1 * y + b2) / k

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Keep factors in (-1.0, 1.0], e.g. RandomZoom(0.2) for up to ±20% zoom
  2. Convert percentages: divide by 100

Example fix

// before
layer = RandomZoom(height_factor=20)  // meant 20%
// after
layer = RandomZoom(height_factor=0.2)
Defensive patterns

Strategy: validation

Validate before calling

vals = f if isinstance(f, (tuple, list)) else [f]
assert all(-1.0 < x <= 1.0 for x in vals), 'zoom factors must be in (-1.0, 1.0]'

Type guard

def in_zoom_range(x):
    return isinstance(x, (int, float)) and -1.0 < x <= 1.0

Try / catch

try:
    layer = RandomZoom(h, w)
except ValueError:
    h = max(-0.99, min(1.0, h / 100)) if abs(h) > 1 else h
    layer = RandomZoom(h, w)

Prevention

When it happens

Trigger: Calling RandomZoom(height_factor=(-1.0, 0.5)) or RandomZoom(2.0).

Common situations: Assuming symmetric ±1 bounds like RandomTranslation; passing percent values (e.g. 20 for 20%).

Related errors


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