{"record":{"id":"470b73eef408242a","repo":"keras-team/keras","slug":"axis-self-axis-of-input-tensor-should-have-a-def","errorCode":null,"errorMessage":"Axis {self.axis} of input tensor should have a defined dimension but the layer received an input with shape {input_shape}.","messagePattern":"Axis (.+?) of input tensor should have a defined dimension but the layer received an input with shape (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/normalization/group_normalization.py","lineNumber":107,"sourceCode":"        self.supports_masking = True\n        self.autocast = False\n        self.groups = groups\n        self.axis = axis\n        self.epsilon = epsilon\n        self.center = center\n        self.scale = scale\n        self.beta_initializer = initializers.get(beta_initializer)\n        self.gamma_initializer = initializers.get(gamma_initializer)\n        self.beta_regularizer = regularizers.get(beta_regularizer)\n        self.gamma_regularizer = regularizers.get(gamma_regularizer)\n        self.beta_constraint = constraints.get(beta_constraint)\n        self.gamma_constraint = constraints.get(gamma_constraint)\n\n    def build(self, input_shape):\n        dim = input_shape[self.axis]\n\n        if dim is None:\n            raise ValueError(\n                f\"Axis {self.axis} of input tensor should have a defined \"\n                \"dimension but the layer received an input with shape \"\n                f\"{input_shape}.\"\n            )\n\n        if self.groups == -1:\n            self.groups = dim\n\n        if dim < self.groups:\n            raise ValueError(\n                f\"Number of groups ({self.groups}) cannot be more than the \"\n                f\"number of channels ({dim}).\"\n            )\n\n        if dim % self.groups != 0:\n            raise ValueError(\n                f\"Number of groups ({self.groups}) must be a multiple \"\n                f\"of the number of channels ({dim}).\"","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/normalization/group_normalization.py#L89-L125","documentation":"Raised in GroupNormalization.build() when the dimension of the input tensor at self.axis is None (unknown), which happens when the layer is built from a symbolic/placeholder input whose axis extent is undetermined. GroupNormalization must slice the axis into self.groups channels, so an undefined extent cannot be validated or normalized.","triggerScenarios":"Thrown at keras/src/layers/normalization/group_normalization.py:107 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Build the layer against an input whose dimension at the given axis is statically known (e.g. pass an explicit Input(shape=(...)) with a fixed channel count)","If using a dataset with unknown shapes, set shapes explicitly or use tf.ensure_shape / a FixedSize padding so the axis extent is defined","Use groups=-1 to infer groups from the channel dimension once the shape is known"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}