keras-team/keras · error · ValueError
Number of groups ( ) cannot be more than the number of…
Error message
Number of groups ({self.groups}) cannot be more than the number of channels ({dim}). What it means
Raised in GroupNormalization.build() after resolving dim = input_shape[self.axis]: the requested groups exceeds the channel count on that axis. Each group needs at least one channel, so groups>dim is structurally impossible.
Solutions
- Reduce the groups argument so it is <= the number of channels on the normalization axis
- Set groups=-1 to have the layer automatically use the full channel count as the number of groups
- Verify the axis argument points at the intended channel axis (e.g. -1 for channels-last, 1 for channels-first)
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/normalization/group_normalization.py:117 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/1b111873338a6018.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/normalization/group_normalization.py:117
self.gamma_regularizer = regularizers.get(gamma_regularizer)
self.beta_constraint = constraints.get(beta_constraint)
self.gamma_constraint = constraints.get(gamma_constraint)
def build(self, input_shape):
dim = input_shape[self.axis]
if dim is None:
raise ValueError(
f"Axis {self.axis} of input tensor should have a defined "
"dimension but the layer received an input with shape "
f"{input_shape}."
)
if self.groups == -1:
self.groups = dim
if dim < self.groups:
raise ValueError(
f"Number of groups ({self.groups}) cannot be more than the "
f"number of channels ({dim})."
)
if dim % self.groups != 0:
raise ValueError(
f"Number of groups ({self.groups}) must be a multiple "
f"of the number of channels ({dim})."
)
self.input_spec = InputSpec(
ndim=len(input_shape), axes={self.axis: dim}
)
if self.scale:
self.gamma = self.add_weight(
shape=(dim,),
name="gamma",View on GitHub (pinned to 7a34a03db6)