keras-team/keras · error · ValueError
Invalid input shape for input {x} with name '{self._inputs[i
Error message
Invalid input shape for input {x} with name '{self._inputs[i].name}' and path '{path}'. Expected shape {ref_shape}, but input has incompatible shape {x.shape} What it means
Error "Invalid input shape for input {x} with name '{self._inputs[i].name}' and path '{path}'. Expected shape {ref_shape}, but input has incompatible shape {x.shape}" thrown in keras-team/keras.
Source
Thrown at keras/src/models/functional.py:316
if x is None:
adjusted.append(x)
continue
x_rank = len(x.shape)
ref_rank = len(ref_shape)
if x_rank == ref_rank:
adjusted.append(x)
continue
if x_rank == ref_rank + 1:
if x.shape[-1] == 1:
adjusted.append(ops.squeeze(x, axis=-1))
continue
if x_rank == ref_rank - 1:
if ref_shape[-1] == 1:
adjusted.append(ops.expand_dims(x, axis=-1))
continue
flat_paths_and_inputs = tree.flatten_with_path(self._inputs_struct)
path = ".".join(str(p) for p in flat_paths_and_inputs[i][0])
raise ValueError(
f"Invalid input shape for input {x} with name "
f"'{self._inputs[i].name}' and path '{path}'. Expected shape "
f"{ref_shape}, but input has incompatible shape {x.shape}"
)
# Add back metadata.
for i in range(len(flat_inputs)):
if hasattr(flat_inputs[i], "_keras_history"):
adjusted[i]._keras_history = flat_inputs[i]._keras_history
mask = backend.get_keras_mask(flat_inputs[i])
if mask is not None:
backend.set_keras_mask(adjusted[i], mask)
return adjusted
def _standardize_inputs(self, inputs):
raise_exception = False
if (
isinstance(self._inputs_struct, list)
and len(self._inputs_struct) == 1View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/models/functional.py:316 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/01a07d1684a28c32.
Report an issue: GitHub.