{"record":{"id":"5da9258f79ed9df7","repo":"keras-team/keras","slug":"adapt-yielded-a-batch-with-incompatible-shape-e","errorCode":null,"errorMessage":"adapt() yielded a batch with incompatible shape. Expected {self._build_input_shape}, got {tuple(batch.shape)}.","messagePattern":"adapt\\(\\) yielded a batch with incompatible shape\\. Expected (.+?), got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/normalization.py","lineNumber":374,"sourceCode":"                ):\n                    steps = int(cardinality.numpy())\n\n            progbar = Progbar(target=steps, unit_name=\"step\")\n\n            for i, batch in enumerate(data):\n                batch = _extract_batch(batch)\n                batch = backend.convert_to_tensor(\n                    batch, dtype=self.compute_dtype\n                )\n                for d in self._keep_axis:\n                    batch_dim = batch.shape[d]\n                    expected = self._build_input_shape[d]\n                    if (\n                        batch_dim is not None\n                        and expected is not None\n                        and batch_dim != expected\n                    ):\n                        raise ValueError(\n                            \"adapt() yielded a batch with incompatible \"\n                            \"shape. Expected \"\n                            f\"{self._build_input_shape}, got \"\n                            f\"{tuple(batch.shape)}.\"\n                        )\n                batch_mean = ops.mean(batch, axis=self._reduce_axis)\n                batch_var = ops.var(batch, axis=self._reduce_axis)\n                if self._reduce_axis:\n                    batch_reduce_shape = (\n                        batch.shape[d] for d in self._reduce_axis\n                    )\n                    batch_count = math.prod(batch_reduce_shape)\n                else:\n                    batch_count = 1\n\n                total_count += batch_count\n                batch_weight = float(batch_count) / total_count\n                existing_weight = 1.0 - batch_weight","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/normalization.py#L356-L392","documentation":"Error \"adapt() yielded a batch with incompatible shape. Expected {self._build_input_shape}, got {tuple(batch.shape)}.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/layers/preprocessing/normalization.py:374 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"}