{"record":{"id":"ca3028a71c5fb15a","repo":"keras-team/keras","slug":"the-weights-argument-should-be-either-none-ra-ca3028","errorCode":null,"errorMessage":"The `weights` argument should be either `None` (random initialization), 'imagenet' (pre-training on ImageNet), or the path to the weights file to be loaded.","messagePattern":"The `weights` argument should be either `None` \\(random initialization\\), 'imagenet' \\(pre-training on ImageNet\\), or the path to the weights file to be loaded\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/applications/xception.py","lineNumber":96,"sourceCode":"                last convolutional block, and thus\n                the output of the model will be a 2D tensor.\n            - `max` means that global max pooling will\n                be applied.\n        classes: optional number of classes to classify images\n            into, only to be specified if `include_top` is `True`, and\n            if no `weights` argument is specified. Defaults to `1000`.\n        classifier_activation: A `str` or callable. The activation function to\n            use on the \"top\" layer. Ignored unless `include_top=True`. Set\n            `classifier_activation=None` to return the logits of the \"top\"\n            layer.  When loading pretrained weights, `classifier_activation` can\n            only be `None` or `\"softmax\"`.\n        name: The name of the model (string).\n\n    Returns:\n        A model instance.\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        )\n\n    if weights == \"imagenet\" and include_top and classes != 1000:\n        raise ValueError(\n            \"If using `weights='imagenet'` with `include_top=True`, \"\n            \"`classes` should be 1000.  \"\n            f\"Received classes={classes}\"\n        )\n\n    # Determine proper input shape\n    input_shape = imagenet_utils.obtain_input_shape(\n        input_shape,\n        default_size=299,\n        min_size=71,","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/applications/xception.py#L78-L114","documentation":"Guard in the Xception application constructor: the `weights` argument is validated against the set {'imagenet', None} and checked for existence as a file path. A value that is neither — typically a misspelled identifier or a path that does not exist — fails file_utils.exists and falls through to this error.","triggerScenarios":"Thrown at keras/src/applications/xception.py:96 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass weights=None for random initialization.","Pass weights='imagenet' for ImageNet pre-training.","Pass a valid path to an Xception weights file; verify the path exists with os.path.exists before calling."],"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"}