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) Received: {name}={factor} What it means
RandomGaussianBlur._set_kernel_size validates the kernel_size argument in __init__. A kernel size must be a single odd integer or a 2-element sequence of odd integers (one per axis). When a sequence of any other length is given, this ValueError fires at construction.
Source
Thrown at keras/src/layers/preprocessing/image_preprocessing/random_gaussian_blur.py:77
):
super().__init__(data_format=data_format, **kwargs)
self._set_factor(factor)
self.kernel_size = self._set_kernel_size(kernel_size, "kernel_size")
self.sigma = self._set_factor_by_name(sigma, "sigma")
self.value_range = value_range
self.seed = seed
self.generator = SeedGenerator(seed)
def _set_kernel_size(self, factor, name):
error_msg = f"{name} must be an odd number. Received: {name}={factor}"
if isinstance(factor, (tuple, list)):
if len(factor) != 2:
error_msg = (
f"The `{name}` argument should be a number "
"(or a list of two numbers) "
f"Received: {name}={factor}"
)
raise ValueError(error_msg)
if (factor[0] % 2 == 0) or (factor[1] % 2 == 0):
raise ValueError(error_msg)
lower, upper = factor
elif isinstance(factor, (int, float)):
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]}]. "View on GitHub (pinned to 7a34a03db6)
Solutions
- Pass kernel_size=[kh, kw] with both odd, e.g. [3, 3]
- Or a single odd integer, e.g. kernel_size=5
- Sanitize config lists to length 1 or 2 before construction
Example fix
# before layers.RandomGaussianBlur(kernel_size=[3, 3, 3]) # after layers.RandomGaussianBlur(kernel_size=[3, 3])
Defensive patterns
Strategy: validation
Validate before calling
ks = [3, 3] assert isinstance(ks, int) or len(ks) == 2, "kernel_size must be int or 2-element list"
Type guard
def is_valid_kernel_size(v) -> bool:
return isinstance(v, int) or (isinstance(v, (tuple, list)) and len(v) == 2) Try / catch
try:
layer = RandomGaussianBlur(kernel_size=ks)
except ValueError:
layer = RandomGaussianBlur(kernel_size=3) Prevention
- Use scalar kernel_size unless anisotropic blur is needed
- Schema-check config lists for length 1 or 2
When it happens
Trigger: kernel_size=[3, 3, 3] (three entries), kernel_size=[3], or kernel_size=[] passed to layers.RandomGaussianBlur().
Common situations: Configs that add a channel dimension to kernel sizes; reusing a 3-element kernel spec from a 3D-conv setting; YAML list typos.
Related errors
- {name} must be an odd number. Received: {name}={factor}
- Unknown `interpolation` {interpolation}. Expected of one {se
- Unknown `fill_mode` {fill_mode}. Expected of one {self._SUPP
- 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
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/444df9ed61f4cd0b.
Report an issue: GitHub.