keras-team/keras · error · ValueError

`input_shape` must be a tuple of three integers.

Error message

`input_shape` must be a tuple of three integers.

What it means

obtain_input_shape in keras/src/applications/imagenet_utils.py: a supplied `input_shape` must be a tuple (or list) of exactly three integers — (rows, cols, channels) or (channels, rows, cols) depending on data_format. It fires when input_shape has the wrong length or contains non-integer entries.

Solutions

  1. Provide a 3-tuple of ints, e.g. (224, 224, 3) for channels_last
  2. Remove None entries or extra batch dimensions — do not include the batch axis
  3. Wrap scalars/lists as tuple(int(v) for v in shape) to guarantee the type
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/applications/imagenet_utils.py:363 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/a448f1ffb53101eb. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/applications/imagenet_utils.py:363

        if data_format == "channels_first":
            default_shape = (3, default_size, default_size)
        else:
            default_shape = (default_size, default_size, 3)
    if weights == "imagenet" and require_flatten:
        if input_shape is not None:
            if input_shape != default_shape:
                raise ValueError(
                    "When setting `include_top=True` "
                    "and loading `imagenet` weights, "
                    f"`input_shape` should be {default_shape}.  "
                    f"Received: input_shape={input_shape}"
                )
        return default_shape
    if input_shape:
        if data_format == "channels_first":
            if input_shape is not None:
                if len(input_shape) != 3:
                    raise ValueError(
                        "`input_shape` must be a tuple of three integers."
                    )
                if input_shape[0] != 3 and weights == "imagenet":
                    raise ValueError(
                        "The input must have 3 channels; Received "
                        f"`input_shape={input_shape}`"
                    )
                if (
                    input_shape[1] is not None and input_shape[1] < min_size
                ) or (input_shape[2] is not None and input_shape[2] < min_size):
                    raise ValueError(
                        f"Input size must be at least {min_size}"
                        f"x{min_size}; Received: "
                        f"input_shape={input_shape}"
                    )
        else:
            if input_shape is not None:
                if len(input_shape) != 3:

View on GitHub (pinned to 7a34a03db6)