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_v2.py:122
Set `classifier_activation=None` to return the logits of the "top"
layer. When loading pretrained weights, `classifier_activation`
can only be `None` or `"softmax"`.
name: String, the name of the model.
Returns:
A model instance.
"""
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` '
f"as true, `classes` should be 1000. 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(
f"input_tensor: {input_tensor}"
"is not type input_tensor. "View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/applications/mobilenet_v2.py:122 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/c811fd1cd407d01e.
Report an issue: GitHub.