{"record":{"id":"4492d412a4490038","repo":"keras-team/keras","slug":"if-using-weights-imagenet-with-include-top-a-4492d4","errorCode":null,"errorMessage":"If using `weights=\"imagenet\"` with `include_top` as true, `classes` should be 1000.  Received classes={classes}","messagePattern":"If using `weights=\"imagenet\"` with `include_top` as true, `classes` should be 1000\\.  Received classes=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/applications/mobilenet_v3.py","lineNumber":180,"sourceCode":"    input_tensor=None,\n    classes=1000,\n    pooling=None,\n    dropout_rate=0.2,\n    classifier_activation=\"softmax\",\n    include_preprocessing=True,\n    name=None,\n):\n    if not (weights in {\"imagenet\", None} or file_utils.exists(weights)):\n        raise ValueError(\n            \"The `weights` argument should be either \"\n            \"`None` (random initialization), `imagenet` \"\n            \"(pre-training on ImageNet), \"\n            \"or the path to the weights file to be loaded.  \"\n            f\"Received weights={weights}\"\n        )\n\n    if weights == \"imagenet\" and include_top and classes != 1000:\n        raise ValueError(\n            'If using `weights=\"imagenet\"` with `include_top` '\n            \"as true, `classes` should be 1000.  \"\n            f\"Received classes={classes}\"\n        )\n\n    # Determine proper input shape and default size.\n    # If both input_shape and input_tensor are used, they should match\n    if input_shape is not None and input_tensor is not None:\n        try:\n            is_input_t_tensor = backend.is_keras_tensor(input_tensor)\n        except ValueError:\n            try:\n                is_input_t_tensor = backend.is_keras_tensor(\n                    operation_utils.get_source_inputs(input_tensor)\n                )\n            except ValueError:\n                raise ValueError(\n                    \"input_tensor: \",","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/applications/mobilenet_v3.py#L162-L198","documentation":"MobileNetV3 constraint in keras/src/applications/mobilenet_v3.py: the ImageNet checkpoints were trained with a 1000-class top, so weights=\"imagenet\" plus include_top=True requires classes=1000; any other class count would break loading the classifier weights.","triggerScenarios":"Thrown at keras/src/applications/mobilenet_v3.py:180 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Keep classes=1000 with imagenet weights and include_top=True","Set include_top=False and add your own classifier for a custom class count","Train with weights=None for a different number of output classes"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}