keras-team/keras · error · ValueError
Axis {axis} is out of bounds for input shape {input_shape}.
Error message
Axis {axis} is out of bounds for input shape {input_shape}. Received: axis={self.axis} What it means
Error "Axis {axis} is out of bounds for input shape {input_shape}. Received: axis={self.axis}" thrown in keras-team/keras.
Source
Thrown at keras/src/layers/normalization/batch_normalization.py:327
)
self.input_spec = InputSpec(
ndim=len(input_shape), axes={self.axis: input_shape[self.axis]}
)
reduction_axes = list(range(len(input_shape)))
del reduction_axes[self.axis]
self._reduction_axes = reduction_axes
def compute_output_shape(self, input_shape):
if isinstance(self.axis, int):
axes = [self.axis]
else:
axes = self.axis
for axis in axes:
if axis >= len(input_shape) or axis < -len(input_shape):
raise ValueError(
f"Axis {axis} is out of bounds for "
f"input shape {input_shape}. "
f"Received: axis={self.axis}"
)
return input_shape
def call(self, inputs, training=None, mask=None):
# Check if the mask has one less dimension than the inputs.
if mask is not None:
if len(mask.shape) != len(inputs.shape) - 1:
# Raise a value error
raise ValueError(
"The mask provided should be one dimension less "
"than the inputs. Received: "
f"mask.shape={mask.shape}, inputs.shape={inputs.shape}"
)
compute_dtype = backend.result_type(inputs.dtype, "float32")View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/normalization/batch_normalization.py:327 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/04ac2c516a60efb8.
Report an issue: GitHub.