{"record":{"id":"3c6612d55a982892","repo":"keras-team/keras","slug":"the-weights-argument-should-be-either-none-ra-3c6612","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.Received: weights={weights}","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\\.Received: weights=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/applications/efficientnet_v2.py","lineNumber":896,"sourceCode":"            only to be specified if `include_top` is `True`, and if no `weights`\n            argument is specified.\n        classifier_activation: A string 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.\n        include_preprocessing: Boolean, whether to include the preprocessing\n            layer (`Rescaling`) at the bottom of the network.\n            Defaults to `True`.\n\n    Returns:\n        A model instance.\n    \"\"\"\n\n    if blocks_args == \"default\":\n        blocks_args = DEFAULT_BLOCKS_ARGS[name]\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        )\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,","sourceCodeStart":878,"sourceCodeEnd":914,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/applications/efficientnet_v2.py#L878-L914","documentation":"The cropping operation's target_height must be >= 0; a negative final cropped height is rejected during output-shape computation.","triggerScenarios":"Passing a negative target_height, often from a subtraction like target = size - 2*crop that underflows.","commonSituations":"Computed crop targets on small images; config typos; -1 sentinel dynamic dims leaking into the call.","solutions":["Validate target_height >= 0 before calling","Fix the arithmetic that produced the negative value","Skip cropping for degenerate sizes"],"exampleFix":"# before\nout = ops.image.crop_images(img, target_height=(h - 2 * c, w - 2 * c))  # h < 2c\n# after\nif h - 2 * c < 0:\n    raise ValueError('image too small to crop')\nout = ops.image.crop_images(img, target_height=(h - 2 * c, w - 2 * c))","handlingStrategy":"validation","validationCode":"target_height = int(target_height)\nif target_height < 0:\n    raise ValueError('target_height must be >= 0')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard computed targets (size - margins) against underflow","Reject degenerate small inputs early"],"tags":["keras","cropping","shape-validation"],"backgroundTag":"invalid-argument-validation","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}