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 max_ndim={spec.max_ndim}, found ndim={ndim} What it means
Rank upper-bound check in assert_input_compatibility: the input's ndim exceeds spec.max_ndim declared by the layer's InputSpec. Unlike the exact-ndim branch, only an upper bound is enforced, so the fix is to reduce rank or raise the bound.
Solutions
- Flatten or squeeze unneeded axes so ndim <= max_ndim
- Verify a batch dimension was not accidentally added twice
- Adjust the layer's InputSpec max_ndim if the extra rank is legitimate
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/input_spec.py:206 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/ae60a143024d139c.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/input_spec.py:206
raise ValueError(
f"Inputs to a layer should be tensors. Got '{x}' "
f"(of type {type(x)}) as input for layer '{layer_name}'."
)
shape = backend.standardize_shape(x.shape)
ndim = len(shape)
# Check ndim.
if spec.ndim is not None and not spec.allow_last_axis_squeeze:
if ndim != spec.ndim:
raise ValueError(
f"Input {input_index} with name '{spec.name}' of layer "
f"'{layer_name}' is incompatible with the layer: "
f"expected ndim={spec.ndim}, found ndim={ndim}. "
f"Full shape received: {shape}"
)
if spec.max_ndim is not None:
if ndim is not None and ndim > spec.max_ndim:
raise ValueError(
f"Input {input_index} with name '{spec.name}' of layer "
f"'{layer_name}' is incompatible with the layer: "
f"expected max_ndim={spec.max_ndim}, "
f"found ndim={ndim}"
)
if spec.min_ndim is not None:
if ndim is not None and ndim < spec.min_ndim:
raise ValueError(
f"Input {input_index} with name '{spec.name}' of layer "
f"'{layer_name}' is incompatible with the layer: "
f"expected min_ndim={spec.min_ndim}, "
f"found ndim={ndim}. "
f"Full shape received: {shape}"
)
# Check dtype.
if spec.dtype is not None:
dtype = backend.standardize_dtype(x.dtype)
if dtype != spec.dtype:View on GitHub (pinned to 7a34a03db6)