keras-team/keras · error · ValueError

If using `weights` as `"imagenet"` with `include_top` as tru

Error message

If using `weights` as `"imagenet"` with `include_top` as true, `classes` should be 1000

What it means

Error "If using `weights` as `"imagenet"` with `include_top` as true, `classes` should be 1000" thrown in keras-team/keras.

Source

Thrown at keras/src/applications/nasnet.py:129

    Returns:
        A model instance.
    """
    if backend.image_data_format() == "channels_first":
        raise ValueError(
            "NASNet does not support the `channels_first` image data "
            "format. Switch to `channels_last` by editing your local "
            "config file at ~/.keras/keras.json"
        )
    if not (weights in {"imagenet", None} or file_utils.exists(weights)):
        raise ValueError(
            "The `weights` argument should be either "
            "`None` (random initialization), `imagenet` "
            "(pre-training on ImageNet), "
            "or the path to the weights file to be loaded."
        )

    if weights == "imagenet" and include_top and classes != 1000:
        raise ValueError(
            'If using `weights` as `"imagenet"` with `include_top` '
            "as true, `classes` should be 1000"
        )

    if (
        isinstance(input_shape, tuple)
        and None in input_shape
        and weights == "imagenet"
    ):
        raise ValueError(
            "When specifying the input shape of a NASNet and loading "
            "`ImageNet` weights, the input_shape argument must be static"
            f" (no None entries). Got: `input_shape={input_shape}`."
        )

    if default_size is None:
        default_size = 331

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/applications/nasnet.py:129 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/739112d6614f58d2. Report an issue: GitHub.