{"record":{"id":"f1d3c36e2a534769","repo":"keras-team/keras","slug":"if-using-weights-imagenet-with-include-top-tr","errorCode":null,"errorMessage":"If using `weights=\"imagenet\"` with `include_top=True`, `classes` should be 1000. Received classes={classes}","messagePattern":"If using `weights=\"imagenet\"` with `include_top=True`, `classes` should be 1000\\. Received classes=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/applications/convnext.py","lineNumber":409,"sourceCode":"    Returns:\n        A model instance.\n    \"\"\"\n    if backend.image_data_format() == \"channels_first\":\n        raise ValueError(\n            \"ConvNeXt does not support the `channels_first` image data \"\n            \"format. Switch to `channels_last` by editing your local \"\n            \"config file at ~/.keras/keras.json\"\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=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:","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/applications/convnext.py#L391-L427","documentation":"Raised by _extract_patches_3d when strides, after int expansion, is not a length-3 sequence. Strides default to the patch size; if you override them you must give one stride per spatial dim (d, h, w) so the extractor knows the sampling step along each axis.","triggerScenarios":"extract_patches_3d(vols, size=(4,4,4), strides=(2,2)) or strides=[2] on 5D inputs; passing a 2D stride tuple from an image pipeline into a volume pipeline; strides computed as (s, s) + something that dropped an axis.","commonSituations":"Reusing an image-model stride config for video/voxel models; strides derived from size[:-1] or another slicing bug; frameworks that accept 2-tuples elsewhere (conv2d) making the 3-tuple requirement easy to miss.","solutions":["Pass strides as an int (same stride on all 3 axes) or a length-3 tuple matching (depth, height, width)","Omit strides entirely if you want non-overlapping patches (defaults to size)","Mirror the shape of size when building strides programmatically: strides = tuple(s // 2 for s in size)"],"exampleFix":"before: extract_patches_3d(v, size=(4,4,4), strides=(2,2)) -> ValueError; after: extract_patches_3d(v, size=(4,4,4), strides=2)","handlingStrategy":"validation","validationCode":"if strides is not None and not isinstance(strides, int):\n    strides = tuple(strides)\n    assert len(strides) == 3, f\"strides for 3D must have length 3, got {len(strides)}\"","typeGuard":"def valid_3d_strides(strides) -> bool:\n    return strides is None or isinstance(strides, int) or (isinstance(strides, (tuple, list)) and len(strides) == 3)","tryCatchPattern":null,"preventionTips":["Prefer a single int stride unless per-axis control is required","Build strides from size with the same length","Remember strides default to size (non-overlapping) when omitted"],"tags":["keras","image-ops","strides","argument-validation"],"backgroundTag":"invalid-argument-shape","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}