keras-team/keras · error · ValueError

input_tensor: is type: which is not a valid type

Error message

input_tensor: {input_tensor}is type: {type(input_tensor)}which is not a valid type

What it means

MobileNetV3 builder in keras/src/applications/mobilenet_v3.py: the input_tensor passed together with input_shape is of a type rejected by backend.is_keras_tensor, so the error reports the concrete type. It fires for non-symbolic objects (NumPy arrays, eager tensors, foreign-framework tensors) supplied as input_tensor.

Solutions

  1. Replace input_tensor with a keras.Input symbol of matching shape
  2. Drop input_tensor and specify input_shape instead
  3. Verify type(input_tensor) is a Keras symbolic tensor before passing
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at keras/src/applications/mobilenet_v3.py:235 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/282eed5d543c7fea. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/applications/mobilenet_v3.py:235

                        "input_shape[1] must equal "
                        "input_tensor.shape[2].  Received "
                        f"input_shape={input_shape}, "
                        "input_tensor.shape="
                        f"{input_tensor.shape}"
                    )
        else:
            raise ValueError(
                "input_tensor specified: ",
                input_tensor,
                "is not a keras tensor",
            )

    # If input_shape is None, infer shape from input_tensor
    if input_shape is None and input_tensor is not None:
        try:
            backend.is_keras_tensor(input_tensor)
        except ValueError:
            raise ValueError(
                "input_tensor: ",
                input_tensor,
                "is type: ",
                type(input_tensor),
                "which is not a valid type",
            )

        if backend.is_keras_tensor(input_tensor):
            if backend.image_data_format() == "channels_first":
                rows = input_tensor.shape[2]
                cols = input_tensor.shape[3]
                input_shape = (3, cols, rows)
            else:
                rows = input_tensor.shape[1]
                cols = input_tensor.shape[2]
                input_shape = (cols, rows, 3)
    # If input_shape is None and input_tensor is None using standard shape
    if input_shape is None and input_tensor is None:

View on GitHub (pinned to 7a34a03db6)