Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions keras/src/layers/normalization/batch_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ def compute_output_shape(self, input_shape):
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. "
f"Received: mask.shape={mask.shape}, inputs.shape={inputs.shape}"
)

input_dtype = standardize_dtype(inputs.dtype)
if input_dtype in ("float16", "bfloat16"):
# BN is prone to overflowing for float16/bfloat16 inputs, so we opt
Expand Down