{"record":{"id":"2356bd7ec7283d6e","repo":"keras-team/keras","slug":"you-must-call-build-input-shape-on-the-layer-b","errorCode":null,"errorMessage":"You must call `.build(input_shape)` on the layer before using it.","messagePattern":"You must call `\\.build\\(input_shape\\)` on the layer before using it\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/normalization.py","lineNumber":432,"sourceCode":"\n    def finalize_state(self):\n        if self.input_mean is not None or not self.built:\n            return\n\n        # In the adapt case, we make constant tensors for mean and variance with\n        # proper broadcast shape and dtype each time `finalize_state` is called.\n        self.mean = ops.reshape(self.adapt_mean, self._broadcast_shape)\n        self.mean = ops.cast(self.mean, self.compute_dtype)\n        self.variance = ops.reshape(self.adapt_variance, self._broadcast_shape)\n        self.variance = ops.cast(self.variance, self.compute_dtype)\n\n    def call(self, inputs):\n        # This layer can be called in tf.data\n        # even with another backend after it has been adapted.\n        # However it must use backend-native logic for adapt().\n        if self.mean is None:\n            # May happen when in tf.data when mean/var was passed explicitly\n            raise ValueError(\n                \"You must call `.build(input_shape)` \"\n                \"on the layer before using it.\"\n            )\n        inputs = self.backend.core.convert_to_tensor(\n            inputs, dtype=self.compute_dtype\n        )\n        # Ensure the weights are in the correct backend. Without this, it is\n        # possible to cause breakage when using this layer in tf.data.\n        mean = self.convert_weight(self.mean)\n        variance = self.convert_weight(self.variance)\n        if self.invert:\n            return self.backend.numpy.add(\n                mean,\n                self.backend.numpy.multiply(\n                    inputs,\n                    self.backend.numpy.maximum(\n                        self.backend.numpy.sqrt(variance), backend.epsilon()\n                    ),","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/normalization.py#L414-L450","documentation":"Error \"You must call `.build(input_shape)` on the layer before using it.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/layers/preprocessing/normalization.py:432 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}