{"record":{"id":"39c1a56bea686866","repo":"keras-team/keras","slug":"the-weights-argument-should-be-either-none-ra-39c1a5","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/efficientnet.py","lineNumber":275,"sourceCode":"              last convolutional layer, 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.\n      classifier_activation: A `str` or callable. The activation function to use\n          on the \"top\" layer. Ignored unless `include_top=True`. Set\n          `classifier_activation=None` to return the logits of the \"top\" layer.\n\n    Returns:\n        A model instance.\n    \"\"\"\n    if blocks_args == \"default\":\n        blocks_args = DEFAULT_BLOCKS_ARGS\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`'\n            \" as true, `classes` should be 1000\"\n        )\n\n    # Determine proper input shape\n    input_shape = imagenet_utils.obtain_input_shape(\n        input_shape,\n        default_size=default_size,\n        min_size=32,\n        data_format=backend.image_data_format(),","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/applications/efficientnet.py#L257-L293","documentation":"Width-axis counterpart: the input width dim is None and target_width was not specified, so the cropping op cannot determine its output width in the symbolic shape.","triggerScenarios":"Variable-width inputs (Input(shape=(H, None, 3))) with a cropping layer lacking target_width.","commonSituations":"Variable-resolution models; Keras 3 symbolic tracing where TF1-style code assumed lazy shapes.","solutions":["Specify target_width on the operation","Fix the input width in keras.Input","Handle fully-dynamic crops with raw slicing outside the layer"],"exampleFix":"# before\ninputs = keras.Input(shape=(224, None, 3))\nx = Cropping2D(2)(inputs)\n# after\ninputs = keras.Input(shape=(224, 224, 3))\nx = Cropping2D(2)(inputs)","handlingStrategy":"validation","validationCode":"if images.shape[-2] is None and target_width is None:\n    raise ValueError('fixed input width or target_width required')","typeGuard":"def has_static_width(images) -> bool:\n    return images.shape[-2] is not None","tryCatchPattern":null,"preventionTips":["Set explicit target_width for variable-width pipelines","Use fixed Input shapes in functional models"],"tags":["keras","dynamic-shape","cropping"],"backgroundTag":"unknown-tensor-dimension","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}