keras-team/keras · error · ValueError
`brightness_range should be tuple or list of two floats. Rec
Error message
`brightness_range should be tuple or list of two floats. Received: {brightness_range} What it means
brightness_range, if given, must be a tuple or list of exactly two elements (typically floats bounding the random brightness shift).
Source
Thrown at keras/src/legacy/preprocessing/image.py:1082
"`featurewise_std_normalization`, "
"which overrides setting of "
"`featurewise_center`."
)
if samplewise_std_normalization:
if not samplewise_center:
self.samplewise_center = True
warnings.warn(
"This ImageDataGenerator specifies "
"`samplewise_std_normalization`, "
"which overrides setting of "
"`samplewise_center`."
)
if brightness_range is not None:
if (
not isinstance(brightness_range, (tuple, list))
or len(brightness_range) != 2
):
raise ValueError(
"`brightness_range should be tuple or list of two floats. "
f"Received: {brightness_range}"
)
self.brightness_range = brightness_range
def flow(
self,
x,
y=None,
batch_size=32,
shuffle=True,
sample_weight=None,
seed=None,
save_to_dir=None,
save_prefix="",
save_format="png",
ignore_class_split=False,
subset=None,View on GitHub (pinned to 7a34a03db6)
Solutions
- Use brightness_range=[0.5, 1.5] (2 elements, tuple or list)
- Omit it for no brightness augmentation
Example fix
// before ImageDataGenerator(brightness_range=0.5) // after ImageDataGenerator(brightness_range=[0.5, 1.5])
Defensive patterns
Strategy: validation
Validate before calling
assert brightness_range is None or (isinstance(brightness_range,(list,tuple)) and len(brightness_range)==2)
Type guard
def br_ok(b): return b is None or (isinstance(b,(list,tuple)) and len(b)==2)
Try / catch
try: ImageDataGenerator(brightness_range=b) except ValueError as e: if 'brightness_range' in str(e): b = [0.5, 1.5]
Prevention
- Remember brightness_range has no scalar shorthand
When it happens
Trigger: ImageDataGenerator(brightness_range=0.5) (scalar) or brightness_range=[0.5,1.5,2.0].
Common situations: Assuming scalar like zoom_range; YAML tuple parsed as list of wrong length.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- `factor` argument cannot have an upper bound lesser than the
- `factor` argument must have values larger than -1. Received:
- `factor` argument cannot have an upper bound less than the l
- `zoom_range` should be a float or a tuple or list of two flo
- Unknown activation function '{activation}' cannot be seriali
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/a079c08caddf9c96.
Report an issue: GitHub.