keras-team/keras · error · ValueError
{self._VALUE_RANGE_VALIDATION_ERROR}Received: value_range={v
Error message
{self._VALUE_RANGE_VALIDATION_ERROR}Received: value_range={value_range} What it means
AutoContrast and other image preprocessing layers sharing this helper require value_range to be a tuple or list describing the valid pixel range of the input images, e.g. (0, 255) or (0.0, 1.0). The constructor raises this ValueError when value_range is not a tuple/list at all - for example a bare int, a string, or None.
Source
Thrown at keras/src/layers/preprocessing/image_preprocessing/auto_contrast.py:46
Defaults to `(0, 255)`.
"""
_USE_BASE_FACTOR = False
_VALUE_RANGE_VALIDATION_ERROR = (
"The `value_range` argument should be a list of two numbers. "
)
def __init__(
self,
value_range=(0, 255),
**kwargs,
):
super().__init__(**kwargs)
self._set_value_range(value_range)
def _set_value_range(self, value_range):
if not isinstance(value_range, (tuple, list)):
raise ValueError(
self._VALUE_RANGE_VALIDATION_ERROR
+ f"Received: value_range={value_range}"
)
if len(value_range) != 2:
raise ValueError(
self._VALUE_RANGE_VALIDATION_ERROR
+ f"Received: value_range={value_range}"
)
self.value_range = sorted(value_range)
def transform_images(self, images, transformation=None, training=True):
original_images = images
images = self._transform_value_range(
images,
original_range=self.value_range,
target_range=(0, 255),
dtype=self.compute_dtype,
)View on GitHub (pinned to 7a34a03db6)
Solutions
- Pass a two-element tuple/list matching your data, e.g. value_range=(0, 255) for uint8 images or (0.0, 1.0) for normalized floats.
- Ensure the value is a literal tuple/list, not a scalar or string.
Example fix
# before layer = keras.layers.AutoContrast(value_range=255) # after layer = keras.layers.AutoContrast(value_range=(0, 255))
Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(value_range, (tuple, list)), f"value_range must be tuple/list, got {type(value_range)}" Type guard
def is_valid_value_range(v):
return isinstance(v, (tuple, list)) and len(v) == 2
Prevention
- Standardize pipeline constants like VALUE_RANGE_255 = (0, 255) and reuse them.
When it happens
Trigger: keras.layers.AutoContrast(value_range=255), value_range=None, or value_range="0-255".
Common situations: Assuming value_range is a single max value; forgetting the argument in code that builds layers from a config dict where the key may be absent or set to a scalar.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- The `value_range` argument should be a list of two numbers.
- Layer {self.__class__.__name__} does not take a `factor` arg
- The `factor` argument should be a number (or a list of two n
- Invalid quantization mode. Expected one of {dtype_policies.Q
- Invalid value for argument `output_mode`. Expected one of {a
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/2fe56f05c7d59441.
Report an issue: GitHub.