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 `shape` argument.

What it means

Consistency check in InputLayer.__init__: with input_tensor provided, a `shape` argument that disagrees with the tensor's non-batch dimensions (or has a different rank) is rejected — the wrapped tensor already defines its shape.

Solutions

  1. Omit `shape` when passing input_tensor
  2. Pass shape equal to input_tensor.shape[1:] with matching rank (e.g., use tuple(input_tensor.shape[1:]) or (None,) sequences with matching length)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/layers/core/input_layer.py:55 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/4de1447165e5ac39. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/layers/core/input_layer.py:55

                    "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:
                raise ValueError(
                    "When providing the `input_tensor` argument, you "
                    "cannot provide an incompatible `dtype` argument."
                )
            if sparse is not None and input_tensor.sparse != sparse:
                raise ValueError(
                    "When providing the `input_tensor` argument, you "
                    "cannot provide an incompatible `sparse` argument."
                )

View on GitHub (pinned to 7a34a03db6)