keras-team/keras · error · ValueError
Input with name ' ' of layer ' ' is incompatible with the…
Error message
Input {input_index} with name '{spec.name}' of layer '{layer_name}' is incompatible with the layer: expected shape={spec.shape}, found shape={shape} What it means
Full-shape check in assert_input_compatibility (after the per-axis checks): when spec.shape is set, the input's shape must match it; with allow_last_axis_squeeze a trailing 1 on the input may be squeezed first. The mismatch is usually a wrong batch/feature layout rather than a rank problem.
Solutions
- Reshape the input to the exact expected shape (mind batch vs per-sample shape)
- Fix off-by-one feature dimensions in upstream preprocessing
- Align the InputSpec shape with the true data shape if the spec is overly strict
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/input_spec.py:256 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/dbd1b596a7dc45ea.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/input_spec.py:256
}:
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 "
f"layer '{layer_name}' is incompatible with the "
f"layer: expected shape={spec.shape}, found "
f"shape={shape}"
)
View on GitHub (pinned to 7a34a03db6)