keras-team/keras · error · ValueError

Input {input_index} with name '{spec.name}' of layer '{layer

Error message

Input {input_index} with name '{spec.name}' of layer '{layer_name}' is incompatible with the layer: expected axis {axis} of input shape to have value {value}, but received input with shape {shape}

What it means

Error "Input {input_index} with name '{spec.name}' of layer '{layer_name}' is incompatible with the layer: expected axis {axis} of input shape to have value {value}, but received input with shape {shape}" thrown in keras-team/keras.

Source

Thrown at keras/src/layers/input_spec.py:239

        # Check dtype.
        if spec.dtype is not None:
            dtype = backend.standardize_dtype(x.dtype)
            if dtype != spec.dtype:
                raise ValueError(
                    f"Input {input_index} with name '{spec.name}' of layer "
                    f"'{layer_name}' is incompatible with the layer: "
                    f"expected dtype={spec.dtype}, "
                    f"found dtype={dtype}"
                )

        # Check specific shape axes.
        if spec.axes:
            for axis, value in spec.axes.items():
                if value is not None and shape[axis] not in {
                    value,
                    None,
                }:
                    raise ValueError(
                        f"Input {input_index} with name '{spec.name}' of layer "
                        f"'{layer_name}' is incompatible with the layer: "
                        f"expected axis {axis} of input shape to have value "
                        f"{value}, but received input with shape {shape}"
                    )
        # Check shape.
        if spec.shape is not None:
            spec_shape = spec.shape
            if spec.allow_last_axis_squeeze:
                if shape and shape[-1] == 1:
                    shape = shape[:-1]
                if spec_shape and spec_shape[-1] == 1:
                    spec_shape = spec_shape[:-1]
            for spec_dim, dim in zip(spec_shape, shape):
                if spec_dim is not None and dim is not None:
                    if spec_dim != dim:
                        raise ValueError(
                            f"Input {input_index} with name '{spec.name}' of "

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/layers/input_spec.py:239 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/71944fb18d84fc6c. Report an issue: GitHub.