keras-team/keras · error · ValueError
Inputs to a layer should be tensors. Got '{x}' (of type {typ
Error message
Inputs to a layer should be tensors. Got '{x}' (of type {type(x)}) as input for layer '{layer_name}'. What it means
Error "Inputs to a layer should be tensors. Got '{x}' (of type {type(x)}) as input for layer '{layer_name}'." thrown in keras-team/keras.
Source
Thrown at keras/src/layers/input_spec.py:188
+ "})`."
)
raise ValueError(
f'Layer "{layer_name}" expects {len(input_spec)} input(s),'
f" but it received {len(inputs)} input tensors. "
f"Inputs received: {inputs}"
)
for input_index, (x, spec) in enumerate(zip(inputs, input_spec)):
if spec is None:
continue
if x is None and spec.optional:
continue
# Having a shape/dtype is the only commonality of the various
# tensor-like objects that may be passed. The most common kind of
# invalid type we are guarding for is a Layer instance (Functional API),
# which does not have a `shape` attribute.
if not hasattr(x, "shape"):
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(View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/input_spec.py:188 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/4bdd7e9219735af0.
Report an issue: GitHub.