{"record":{"id":"71a897cdd69d1f36","repo":"keras-team/keras","slug":"when-setting-include-top-true-and-loading-image","errorCode":null,"errorMessage":"When setting `include_top=True` and loading `imagenet` weights, `input_shape` should be {default_shape}.  Received: input_shape={input_shape}","messagePattern":"When setting `include_top=True` and loading `imagenet` weights, `input_shape` should be (.+?)\\.  Received: input_shape=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/applications/imagenet_utils.py","lineNumber":352,"sourceCode":"            default_shape = (input_shape[0], default_size, default_size)\n        else:\n            if input_shape[-1] not in {1, 3}:\n                warnings.warn(\n                    \"This model usually expects 1 or 3 input channels. \"\n                    \"However, it was passed an input_shape \"\n                    f\"with {input_shape[-1]} input channels.\",\n                    stacklevel=2,\n                )\n            default_shape = (default_size, default_size, input_shape[-1])\n    else:\n        if data_format == \"channels_first\":\n            default_shape = (3, default_size, default_size)\n        else:\n            default_shape = (default_size, default_size, 3)\n    if weights == \"imagenet\" and require_flatten:\n        if input_shape is not None:\n            if input_shape != default_shape:\n                raise ValueError(\n                    \"When setting `include_top=True` \"\n                    \"and loading `imagenet` weights, \"\n                    f\"`input_shape` should be {default_shape}.  \"\n                    f\"Received: input_shape={input_shape}\"\n                )\n        return default_shape\n    if input_shape:\n        if data_format == \"channels_first\":\n            if input_shape is not None:\n                if len(input_shape) != 3:\n                    raise ValueError(\n                        \"`input_shape` must be a tuple of three integers.\"\n                    )\n                if input_shape[0] != 3 and weights == \"imagenet\":\n                    raise ValueError(\n                        \"The input must have 3 channels; Received \"\n                        f\"`input_shape={input_shape}`\"\n                    )","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/applications/imagenet_utils.py#L334-L370","documentation":"obtain_input_shape in keras/src/applications/imagenet_utils.py: when loading pretrained \"imagenet\" weights with include_top=True, the classifier weights fix the spatial size, so input_shape must exactly equal the model's default shape (e.g. (224,224,3)). Any other shape — including correct channel count but wrong width/height — is rejected because the dense top cannot be reshaped to it.","triggerScenarios":"Thrown at keras/src/applications/imagenet_utils.py:352 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass input_shape equal to the model's default_size, e.g. (224, 224, 3), or omit input_shape entirely to use the default","Set include_top=False if you need custom spatial dimensions and will add your own head","Use random initialization (weights=None) if a non-standard input size is required with a top"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}