{"record":{"id":"8b532973587c1e62","repo":"keras-team/keras","slug":"invalid-data-format-argument-data-format","errorCode":null,"errorMessage":"Invalid `data_format` argument: {data_format}","messagePattern":"Invalid `data_format` argument: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/reshaping/up_sampling2d.py","lineNumber":144,"sourceCode":"        width_factor,\n        data_format,\n        interpolation=\"nearest\",\n    ):\n        \"\"\"Resizes the images contained in a 4D tensor.\n\n        Args:\n            x: Tensor or variable to resize.\n            height_factor: Positive integer.\n            width_factor: Positive integer.\n            data_format: One of `\"channels_first\"`, `\"channels_last\"`.\n            interpolation: A string, one of `\"bicubic\"`, `\"bilinear\"`,\n            `\"lanczos3\"`, `\"lanczos5\"`, or `\"nearest\"`.\n\n        Returns:\n            A tensor.\n        \"\"\"\n        if data_format not in {\"channels_last\", \"channels_first\"}:\n            raise ValueError(f\"Invalid `data_format` argument: {data_format}\")\n\n        if data_format == \"channels_first\":\n            x = ops.transpose(x, [0, 2, 3, 1])\n        # https://github.com/keras-team/keras/issues/294\n        # Use `ops.repeat` for `nearest` interpolation to enable XLA\n        if interpolation == \"nearest\":\n            x = ops.repeat(x, height_factor, axis=1)\n            x = ops.repeat(x, width_factor, axis=2)\n        else:\n            # multiply the height and width factor on each dim\n            # by hand (versus using element-wise multiplication\n            # by np.array([height_factor, width_factor]) then\n            # list-ifying the tensor by calling `.tolist()`)\n            # since when running under torchdynamo, `new_shape`\n            # will be traced as a symbolic variable (specifically\n            # a `FakeTensor`) which does not have a `tolist()` method.\n            shape = ops.shape(x)\n            new_shape = (","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/reshaping/up_sampling2d.py#L126-L162","documentation":"UpSampling2D._resize_images (used by call) requires data_format to be exactly 'channels_last' or 'channels_first'. The public constructor already standardizes data_format, so hitting this guard means the value bypassed standardization — an internal/private call or subclass path with a non-standard string like 'NCHW', 'NHWC', or a typo.","triggerScenarios":"Calling the layer's internal _resize_images(x, size, data_format) with e.g. data_format='NCHW' or 'channel_last'; or subclass/wrapper code that forwards a raw, non-standardized string.","commonSituations":"Subclassing UpSampling2D or reusing its helpers with framework-style format strings ('NHWC'/'NCHW' from TF/PyTorch vocabulary); dynamically threading data_format through custom layers where one path skips standardize_data_format.","solutions":["Use exactly 'channels_last' or 'channels_first' (Keras vocabulary), not 'NHWC'/'NCHW'","If you subclass or call internals, run keras.backend.standardize_data_format(data_format) first — or better, call the public layer API instead of _resize_images","Prefer omitting data_format and letting keras.config set it globally"],"exampleFix":"# before\nout = upsample._resize_images(x, size=2, data_format='NCHW')\n\n# after\nout = upsample._resize_images(x, size=2, data_format='channels_first')","handlingStrategy":"validation","validationCode":"def valid_data_format(df):\n    return df in {'channels_last', 'channels_first'}\n\nassert valid_data_format(df), f'bad data_format: {df}'","typeGuard":"def is_keras_data_format(v) -> bool:\n    return v in ('channels_last', 'channels_first')","tryCatchPattern":null,"preventionTips":["Use only 'channels_last'/'channels_first' — never NHWC/NCHW strings","Avoid calling private _resize* helpers; use the public layer","Centralize data_format through keras.config instead of per-layer strings"],"tags":["keras","upsampling2d","data-format","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}