keras-team/keras · error · ValueError
Argument `input_tensor` must be a KerasTensor. Received…
Error message
Argument `input_tensor` must be a KerasTensor. Received invalid type: input_tensor={input_tensor} (of type {type(input_tensor)}) What it means
Type guard in InputLayer.__init__: when `input_tensor` is supplied it must already be a backend KerasTensor so the layer can wrap it as the graph source; passing a tf.Tensor, numpy array, or symbolic tensor from another graph fails this isinstance check.
Solutions
- Pass a tensor created via keras.Input(...) / keras.ops source KerasTensor
- Omit input_tensor and let InputLayer create the tensor from shape/dtype
- Convert raw tensors by feeding them as layer inputs rather than as input_tensor
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at keras/src/layers/core/input_layer.py:36 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/2c0ef9f50977a7cd.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/core/input_layer.py:36
batch_shape=None,
input_tensor=None,
optional=False,
name=None,
**kwargs,
):
super().__init__(name=name)
if "input_shape" in kwargs:
warnings.warn(
"Argument `input_shape` is deprecated. Use `shape` instead."
)
shape = kwargs.pop("input_shape")
if "batch_input_shape" in kwargs:
batch_shape = kwargs.pop("batch_input_shape")
if input_tensor is not None:
if not isinstance(input_tensor, backend.KerasTensor):
raise ValueError(
"Argument `input_tensor` must be a KerasTensor. "
f"Received invalid type: input_tensor={input_tensor} "
f"(of type {type(input_tensor)})"
)
if batch_size is not None:
if (
len(input_tensor.shape) < 1
or input_tensor.shape[0] != batch_size
):
raise ValueError(
"When providing the `input_tensor` argument, you "
"cannot provide an incompatible `batch_size` argument."
)
if shape is not None:
if (
len(shape) != len(input_tensor.shape) - 1
or shape != input_tensor.shape[1:]
):View on GitHub (pinned to 7a34a03db6)