keras-team/keras · error · ValueError
The `{name}` argument should be a number (or a list of two n
Error message
The `{name}` argument should be a number (or a list of two numbers) in the range [{self._FACTOR_BOUNDS[0]}, {self._FACTOR_BOUNDS[1]}]. Received: factor={factor} What it means
RandomGaussianBlur._set_factor_by_name validates numeric factors (e.g. the blur sigma/factor) in __init__. A sequence form must be exactly two numbers denoting lower and upper bounds; sequences of any other length raise this ValueError immediately.
Source
Thrown at keras/src/layers/preprocessing/image_preprocessing/random_gaussian_blur.py:100
if factor % 2 == 0:
raise ValueError(error_msg)
lower, upper = factor, factor
else:
raise ValueError(error_msg)
return lower, upper
def _set_factor_by_name(self, factor, name):
error_msg = (
f"The `{name}` argument should be a number "
"(or a list of two numbers) "
"in the range "
f"[{self._FACTOR_BOUNDS[0]}, {self._FACTOR_BOUNDS[1]}]. "
f"Received: factor={factor}"
)
if isinstance(factor, (tuple, list)):
if len(factor) != 2:
raise ValueError(error_msg)
if (
factor[0] > self._FACTOR_BOUNDS[1]
or factor[1] < self._FACTOR_BOUNDS[0]
):
raise ValueError(error_msg)
lower, upper = sorted(factor)
elif isinstance(factor, (int, float)):
if (
factor < self._FACTOR_BOUNDS[0]
or factor > self._FACTOR_BOUNDS[1]
):
raise ValueError(error_msg)
factor = abs(factor)
lower, upper = [max(-factor, self._FACTOR_BOUNDS[0]), factor]
else:
raise ValueError(error_msg)
return lower, upper
View on GitHub (pinned to 7a34a03db6)
Solutions
- Pass a 2-element list [lower, upper], e.g. factor=[0.0, 2.0]
- Or a single number such as factor=1.0
- Flatten nested config lists before construction
Example fix
# before layers.RandomGaussianBlur(factor=[0.5]) # after layers.RandomGaussianBlur(factor=[0.0, 0.5])
Defensive patterns
Strategy: validation
Validate before calling
f = [0.0, 2.0] assert isinstance(f, (tuple, list)) and len(f) == 2, "factor must be [lower, upper]"
Type guard
def is_factor_pair(v) -> bool:
return isinstance(v, (tuple, list)) and len(v) == 2 Try / catch
try:
layer = RandomGaussianBlur(factor=f)
except ValueError:
layer = RandomGaussianBlur(factor=1.0) Prevention
- Use [lower, upper] pairs or scalars in configs
- Flatten nested YAML structures before layer construction
When it happens
Trigger: factor=[0.1, 0.2, 0.3] or factor=[0.1] passed to layers.RandomGaussianBlur(); an empty list from a config.
Common situations: Config generators emitting variable-length lists; nested YAML structures that wrap the pair once more; copy-paste from layers taking per-axis triples.
Related errors
- The `{name}` argument should be a number (or a list of two n
- The `{name}` argument should be a number (or a list of two n
- Unknown `interpolation` {interpolation}. Expected of one {se
- Unknown `fill_mode` {fill_mode}. Expected of one {self._SUPP
- The `fill_value` argument should be a number (or a list of t
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/9c23f92f08df0f08.
Report an issue: GitHub.