keras-team/keras · error · ValueError

If `include_top` is True, you should specify a static…

Error message

If `include_top` is True, you should specify a static `input_shape`. Received: input_shape={input_shape}

What it means

obtain_input_shape in keras/src/applications/imagenet_utils.py: with include_top=True the classifier needs a fixed feature-map size, so the input spatial dimensions must be static. The error fires when input_shape is None (or contains None spatial entries) while a flatten/dense top is required, because the top cannot be built for unknown spatial size.

Solutions

  1. Pass a fully specified input_shape, e.g. (224, 224, 3), when include_top=True
  2. Set include_top=False if dynamic spatial size is needed
  3. Let the builder default input_shape by omitting it only when include_top is False
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

                if (
                    input_shape[0] is not None and input_shape[0] < min_size
                ) or (input_shape[1] is not None and input_shape[1] < min_size):
                    raise ValueError(
                        "Input size must be at least "
                        f"{min_size}x{min_size}; Received: "
                        f"input_shape={input_shape}"
                    )
    else:
        if require_flatten:
            input_shape = default_shape
        else:
            if data_format == "channels_first":
                input_shape = (3, None, None)
            else:
                input_shape = (None, None, 3)
    if require_flatten:
        if None in input_shape:
            raise ValueError(
                "If `include_top` is True, "
                "you should specify a static `input_shape`. "
                f"Received: input_shape={input_shape}"
            )
    return input_shape


def correct_pad(inputs, kernel_size):
    """Returns a tuple for zero-padding for 2D convolution with downsampling.

    Args:
      inputs: Input tensor.
      kernel_size: An integer or tuple/list of 2 integers.

    Returns:
      A tuple.
    """
    img_dim = 2 if backend.image_data_format() == "channels_first" else 1

View on GitHub (pinned to 7a34a03db6)