{"record":{"id":"38d1ad697be3d16f","repo":"keras-team/keras","slug":"invalid-data-format-data-format","errorCode":null,"errorMessage":"Invalid data_format: {data_format}","messagePattern":"Invalid data_format: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/reshaping/up_sampling3d.py","lineNumber":134,"sourceCode":"            height_factor: Positive integer.\n            width_factor: Positive integer.\n            data_format: One of `\"channels_first\"`, `\"channels_last\"`.\n\n        Returns:\n            Resized tensor.\n        \"\"\"\n        if data_format == \"channels_first\":\n            output = ops.repeat(x, depth_factor, axis=2)\n            output = ops.repeat(output, height_factor, axis=3)\n            output = ops.repeat(output, width_factor, axis=4)\n            return output\n        elif data_format == \"channels_last\":\n            output = ops.repeat(x, depth_factor, axis=1)\n            output = ops.repeat(output, height_factor, axis=2)\n            output = ops.repeat(output, width_factor, axis=3)\n            return output\n        else:\n            raise ValueError(f\"Invalid data_format: {data_format}\")\n","sourceCodeStart":116,"sourceCodeEnd":135,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/reshaping/up_sampling3d.py#L116-L135","documentation":"UpSampling3D._resize_volumes raises when data_format matches neither 'channels_first' nor 'channels_last' after the if/elif chain. Like the 2D case, the public constructor normally validates earlier, so this fires on direct/internal calls with non-standard strings ('NCDHW', typos, None).","triggerScenarios":"Invoking _resize_volumes directly (custom subclass, monkey-patch, or copied helper code) with data_format='NCDHW', 'none', or an unset variable; a wrapper that passes the raw user string down unchecked.","commonSituations":"Porting PyTorch-style format names (NCDHW/NDHWC) into Keras layer code; custom 3D upsampling wrappers that accept arbitrary strings and forward them unchecked.","solutions":["Pass exactly 'channels_first' or 'channels_last'","Route custom code through keras.backend.standardize_data_format() before calling the helper, or use the public UpSampling3D layer API","Set data_format once via keras.config.image_data_format and omit per-layer arguments"],"exampleFix":"# before\nout = up3d._resize_volumes(x, 2, 2, 2, data_format='NCDHW')\n\n# after\nout = up3d._resize_volumes(x, 2, 2, 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":["Map PyTorch NCDHW/NDHWC to channels_first/channels_last at the boundary","Prefer the public UpSampling3D layer over internal helpers","Run standardize_data_format on any user-supplied format string in custom layers"],"tags":["keras","upsampling3d","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"}