keras-team/keras · error · ValueError
The mask provided should be one dimension less than the inpu
Error message
The mask provided should be one dimension less than the inputs. Received: mask.shape={mask.shape}, inputs.shape={inputs.shape} What it means
Error "The mask provided should be one dimension less than the inputs. Received: mask.shape={mask.shape}, inputs.shape={inputs.shape}" thrown in keras-team/keras.
Source
Thrown at keras/src/layers/normalization/batch_normalization.py:339
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")
# BN is prone to overflow with float16/bfloat16 inputs, so we upcast to
# float32 for the subsequent computations.
inputs = ops.cast(inputs, compute_dtype)
moving_mean = ops.cast(self.moving_mean, inputs.dtype)
moving_variance = ops.cast(self.moving_variance, inputs.dtype)
if self.scale:
gamma = ops.cast(self.gamma, inputs.dtype)
else:
gamma = None
View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/normalization/batch_normalization.py:339 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/82fba81ccff195a1.
Report an issue: GitHub.