{"record":{"id":"f1cab21d36da304f","repo":"keras-team/keras","slug":"if-using-weights-imagenet-as-true-classes-s","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.py","lineNumber":283,"sourceCode":"          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(),\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":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/applications/efficientnet.py#L265-L301","documentation":"In the cropping output spec, top_cropping (explicit or inferred as height - target_height - bottom_cropping) must be >= 0. Negative top cropping means you asked to crop more than the image height allows (or to grow via negative crop).","triggerScenarios":"Explicit negative top_cropping, or croppings left None with target_height > height.","commonSituations":"Upsizing attempts via negative crop values; symmetric crop arithmetic going negative on small images; off-by-one target sizes.","solutions":["Use pad_images to enlarge instead of negative cropping","Ensure target_height <= height - top_cropping - bottom_cropping","Clamp crop amounts to the available extent"],"exampleFix":"# before\nout = ops.image.crop_images(img, target_height=(256, 256))  # img is 128 tall\n# after\nout = ops.image.pad_images(img, target_height=(256, 256))","handlingStrategy":"validation","validationCode":"if height is not None and target_height + (top_cropping or 0) + (bottom_cropping or 0) > height:\n    raise ValueError('crop window exceeds image height')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use pad_images to enlarge, never negative crops","Center-crop math: crop = max(0, (size - target)//2)"],"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"}