{"record":{"id":"bd5d31cd16c99f5e","repo":"keras-team/keras","slug":"if-using-weights-imagenet-as-true-classes-s-bd5d31","errorCode":null,"errorMessage":"If using `weights=\"imagenet\"` as true, `classes` should be 1000","messagePattern":"If using `weights=\"imagenet\"` as true, `classes` should be 1000","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/applications/efficientnet_v2.py","lineNumber":905,"sourceCode":"\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,\n        data_format=backend.image_data_format(),\n        require_flatten=include_top,\n        weights=weights,\n    )\n\n    if input_tensor is None:\n        img_input = layers.Input(shape=input_shape)\n    else:\n        if not backend.is_keras_tensor(input_tensor):","sourceCodeStart":887,"sourceCodeEnd":923,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/applications/efficientnet_v2.py#L887-L923","documentation":"Width-axis cropping check: left_cropping (explicit or inferred as width - target_width - right_cropping) must be >= 0; negative means the horizontal crop configuration is impossible.","triggerScenarios":"Negative left_cropping argument, or None with right_cropping + target_width > width.","commonSituations":"Center-crop math going negative on narrow images; aspect-ratio-preserving pipelines; swapped width/height.","solutions":["Ensure target_width + left + right cropping <= width","Use pad_images to enlarge","Double-check which axis is width under your data_format"],"exampleFix":"# before\nout = ops.image.crop_images(img, target_width=(64, 64))  # img width 32\n# after\nout = ops.image.pad_images(img, target_width=(64, 64))","handlingStrategy":"validation","validationCode":"left = left_cropping or 0\nright = right_cropping or 0\nif width is not None and left + right + target_width > width:\n    raise ValueError('horizontal crop exceeds width')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp center-crop amounts to >= 0","Pad first when the image is smaller than the crop window"],"tags":["keras","cropping","validation"],"backgroundTag":"invalid-argument-validation","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}