keras-team/keras · error · ValueError

adapt() yielded a batch with incompatible shape. Expected {s

Error message

adapt() yielded a batch with incompatible shape. Expected {self._build_input_shape}, got {tuple(batch.shape)}.

What it means

Error "adapt() yielded a batch with incompatible shape. Expected {self._build_input_shape}, got {tuple(batch.shape)}." thrown in keras-team/keras.

Source

Thrown at keras/src/layers/preprocessing/normalization.py:374

                ):
                    steps = int(cardinality.numpy())

            progbar = Progbar(target=steps, unit_name="step")

            for i, batch in enumerate(data):
                batch = _extract_batch(batch)
                batch = backend.convert_to_tensor(
                    batch, dtype=self.compute_dtype
                )
                for d in self._keep_axis:
                    batch_dim = batch.shape[d]
                    expected = self._build_input_shape[d]
                    if (
                        batch_dim is not None
                        and expected is not None
                        and batch_dim != expected
                    ):
                        raise ValueError(
                            "adapt() yielded a batch with incompatible "
                            "shape. Expected "
                            f"{self._build_input_shape}, got "
                            f"{tuple(batch.shape)}."
                        )
                batch_mean = ops.mean(batch, axis=self._reduce_axis)
                batch_var = ops.var(batch, axis=self._reduce_axis)
                if self._reduce_axis:
                    batch_reduce_shape = (
                        batch.shape[d] for d in self._reduce_axis
                    )
                    batch_count = math.prod(batch_reduce_shape)
                else:
                    batch_count = 1

                total_count += batch_count
                batch_weight = float(batch_count) / total_count
                existing_weight = 1.0 - batch_weight

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/layers/preprocessing/normalization.py:374 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/5da9258f79ed9df7. Report an issue: GitHub.