{"record":{"id":"7ab4dcdf24f14bd9","repo":"keras-team/keras","slug":"nasnet-does-not-support-the-channels-first-image","errorCode":null,"errorMessage":"NASNet does not support the `channels_first` image data format. Switch to `channels_last` by editing your local config file at ~/.keras/keras.json","messagePattern":"NASNet does not support the `channels_first` image data format\\. Switch to `channels_last` by editing your local config file at ~/\\.keras/keras\\.json","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/applications/nasnet.py","lineNumber":115,"sourceCode":"            - `max` means that global max pooling will\n                be applied.\n        classes: Optional number of classes to classify images\n            into, only to be specified if `include_top` is `True`, and\n            if no `weights` argument is specified.\n        default_size: Specifies the default image size of the model\n        classifier_activation: A `str` or callable.\n            The activation function to use on the \"top\" layer.\n            Ignored unless `include_top=True`.\n            Set `classifier_activation=None` to return the logits\n            of the \"top\" layer. When loading pretrained weights,\n            `classifier_activation` can only be `None` or `\"softmax\"`.\n        name: The name of the model (string).\n\n    Returns:\n        A model instance.\n    \"\"\"\n    if backend.image_data_format() == \"channels_first\":\n        raise ValueError(\n            \"NASNet 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` as `\"imagenet\"` with `include_top` '\n            \"as true, `classes` should be 1000\"\n        )\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/applications/nasnet.py#L97-L133","documentation":"NASNet builders in keras/src/applications/nasnet.py only support the channels_last image data format; the pretrained weight files and layout code assume NHWC. The error fires when the global Keras configuration (~/.keras/keras.json image_data_format) is channels_first, and points the user to edit that config to switch formats.","triggerScenarios":"Thrown at keras/src/applications/nasnet.py:115 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Edit ~/.keras/keras.json and set \"image_data_format\": \"channels_last\", then restart Python","Temporarily set keras.config.image_data_format() / backend setting to channels_last at runtime","Convert your input tensors to channels_last ordering instead of changing model expectations only if the config is also switched"],"exampleFix":null,"handlingStrategy":"fallback","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"}