keras-team/keras · error · ValueError

If using `weights="imagenet"` with `include_top` as true, `c

Error message

If using `weights="imagenet"` with `include_top` as true, `classes` should be 1000.  Received classes={classes}

What it means

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

Source

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

    input_tensor=None,
    classes=1000,
    pooling=None,
    dropout_rate=0.2,
    classifier_activation="softmax",
    include_preprocessing=True,
    name=None,
):
    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.  "
            f"Received weights={weights}"
        )

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

    # Determine proper input shape and default size.
    # If both input_shape and input_tensor are used, they should match
    if input_shape is not None and input_tensor is not None:
        try:
            is_input_t_tensor = backend.is_keras_tensor(input_tensor)
        except ValueError:
            try:
                is_input_t_tensor = backend.is_keras_tensor(
                    operation_utils.get_source_inputs(input_tensor)
                )
            except ValueError:
                raise ValueError(
                    "input_tensor: ",

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/applications/mobilenet_v3.py:180 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/4492d412a4490038. Report an issue: GitHub.