keras-team/keras · error · ValueError

Received: input_number={input_number}

Error message

Received: input_number={input_number}

What it means

Raised by Solarization's _check_factor_range when a threshold_factor value is greater than 1.0 or less than 0. The threshold is expressed as a fraction of the value range, so it must lie in [0, 1].

Source

Thrown at keras/src/layers/preprocessing/image_preprocessing/solarization.py:121

                    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)
            lower, upper = [0, 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 < 0:
            raise ValueError(
                self._FACTOR_VALIDATION_ERROR
                + f"Received: input_number={input_number}"
            )

    def get_random_transformation(self, data, training=True, seed=None):
        if not training:
            return None

        if isinstance(data, dict):
            images = data["images"]
        else:
            images = data
        images_shape = self.backend.shape(images)
        if len(images_shape) == 4:
            factor_shape = (images_shape[0], 1, 1, 1)
        else:
            factor_shape = (1, 1, 1)

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Normalize the threshold to a fraction of the value range, e.g. 128/255 ≈ 0.5 for uint8 data
  2. Keep values within [0, 1]

Example fix

// before
layer = Solarization(value_range=(0, 255), threshold_factor=128)
// after
layer = Solarization(value_range=(0, 255), threshold_factor=128/255)
Defensive patterns

Strategy: validation

Validate before calling

vals = tf if isinstance(tf, (tuple, list)) else [tf]
assert all(0.0 <= x <= 1.0 for x in vals), 'threshold_factor must be within [0, 1]'

Type guard

def in_unit_range(x):
    return isinstance(x, (int, float)) and 0.0 <= x <= 1.0

Try / catch

try:
    layer = Solarization(value_range=(0, 255), threshold_factor=tf)
except ValueError:
    tf = max(0.0, min(1.0, tf / value_range[1]))
    layer = Solarization(value_range=(0, 255), threshold_factor=tf)

Prevention

When it happens

Trigger: Calling Solarization(threshold_factor=1.5) or threshold_factor=(-0.2, 0.8).

Common situations: Passing an absolute pixel value (e.g. 128) instead of a fraction (128/255 ≈ 0.5); migrating from TF Addons' Solarize which took 8-bit thresholds.

Related errors


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