keras-team/keras · error · ValueError
Invalid value received for argument `noise_shape`. Expected…
Error message
Invalid value received for argument `noise_shape`. Expected all elements to be integers or None. Received element at index {i}: {dim} (type: {type(dim).__name__}) What it means
Raised while Dropout._validate_noise_shape iterates over the elements of `noise_shape`: an entry that is not None and not a Python int (e.g. a float, numpy scalar, or string) fails the isinstance check and the whole shape is rejected. Each dimension must be an integer or None.
Solutions
- Convert non-int entries to Python ints, e.g. noise_shape=(int(batch_size), 1, int(features))
- Replace numpy scalars or floats with plain ints; use None only for dimensions that should follow the input shape
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/regularization/dropout.py:83 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/f2c46a5ec8877000.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/regularization/dropout.py:83
f"Expected a tuple or list of integers. "
f"Received: noise_shape={noise_shape}"
)
if not isinstance(noise_shape, tuple):
try:
noise_shape = tuple(noise_shape)
except TypeError:
raise ValueError(
f"Invalid value received for argument `noise_shape`. "
f"Expected an iterable of integers "
f"(e.g., a tuple or list). "
f"Received: noise_shape={noise_shape}"
)
for i, dim in enumerate(noise_shape):
if dim is not None:
if not isinstance(dim, int):
raise ValueError(
f"Invalid value received for argument `noise_shape`. "
f"Expected all elements to be integers or None. "
f"Received element at index {i}: {dim} "
f"(type: {type(dim).__name__})"
)
if dim <= 0:
raise ValueError(
f"Invalid value received for argument `noise_shape`. "
f"Expected all dimensions to be positive integers "
f"or None. "
f"Received negative or zero value at index {i}: {dim}"
)
return noise_shape
def call(self, inputs, training=False):
if training and self.rate > 0:View on GitHub (pinned to 7a34a03db6)