keras-team/keras · error · ValueError
Invalid value received for argument `noise_shape`. Expected…
Error message
Invalid value received for argument `noise_shape`. Expected all dimensions to be positive integers or None. Received negative or zero value at index {i}: {dim} What it means
Raised while Dropout._validate_noise_shape checks each dimension of `noise_shape`: an entry that is an int but is zero or negative is rejected. Dropout mask dimensions must be positive integers (or None), since a mask with a non-positive axis cannot be built.
Solutions
- Ensure every explicit dimension in `noise_shape` is >= 1; use None for dimensions that should mirror the input
- Check for off-by-one computations or sign errors when constructing the shape dynamically
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/regularization/dropout.py:91 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/7faf6f8b1f264408.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/regularization/dropout.py:91
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:
return backend.random.dropout(
inputs,
self.rate,
noise_shape=self.noise_shape,
seed=self.seed_generator,
)
return inputs
View on GitHub (pinned to 7a34a03db6)