keras-team/keras · error · ValueError
When providing the `input_tensor` argument, you cannot…
Error message
When providing the `input_tensor` argument, you cannot provide an incompatible `batch_size` argument.
What it means
Consistency check in InputLayer.__init__: when wrapping an existing input_tensor, an explicit batch_size that conflicts with the tensor's first dimension (including a tensor with no leading batch axis) is rejected, since the wrapped tensor already fixes its own batch size.
Solutions
- Set batch_size=None and let the tensor's own shape be authoritative
- Make batch_size match input_tensor.shape[0] exactly
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/core/input_layer.py:46 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/ddd2316e244ac5c2.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/core/input_layer.py:46
"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:]
):
raise ValueError(
"When providing the `input_tensor` argument, you "
"cannot provide an incompatible `shape` argument."
)
if batch_shape is not None and batch_shape != input_tensor.shape:
raise ValueError(
"When providing the `input_tensor` argument, you "
"cannot provide an incompatible `batch_shape` argument."
)
if dtype is not None and input_tensor.dtype != dtype:View on GitHub (pinned to 7a34a03db6)