keras-team/keras · error · ValueError
`factor` should be between 0 and 1. Received: factor={factor
Error message
`factor` should be between 0 and 1. Received: factor={factor} What it means
Error "`factor` should be between 0 and 1. Received: factor={factor}" thrown in keras-team/keras.
Source
Thrown at keras/src/layers/preprocessing/image_preprocessing/random_grayscale.py:58
Input shape:
3D (unbatched) or 4D (batched) tensor with shape:
`(..., height, width, channels)`, in `"channels_last"` format,
or `(..., channels, height, width)`, in `"channels_first"` format.
Output shape:
Same as input shape. The output maintains the same number of channels
as the input, even for grayscale-converted images where all channels
will have the same value.
Example:
{{base_image_preprocessing_color_example}}
"""
def __init__(self, factor=0.5, data_format=None, seed=None, **kwargs):
super().__init__(**kwargs)
if factor < 0 or factor > 1:
raise ValueError(
f"`factor` should be between 0 and 1. Received: factor={factor}"
)
self.factor = factor
self.data_format = backend.standardize_data_format(data_format)
self.seed = seed
self.generator = self.backend.random.SeedGenerator(seed)
def get_random_transformation(self, images, training=True, seed=None):
if seed is None:
seed = self._get_seed_generator(self.backend._backend)
# Base case: Unbatched data
batch_size = 1
if len(images.shape) == 4:
# This is a batch of images (4D input)
batch_size = self.backend.core.shape(images)[0]
random_values = self.backend.random.uniform(
shape=(batch_size,),View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/preprocessing/image_preprocessing/random_grayscale.py:58 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/0b33e34a9e52fa42.
Report an issue: GitHub.