{"record":{"id":"b03f09c3c2bb93b2","repo":"huggingface/transformers","slug":"unsupported-channel-dimension-input-data-format","errorCode":null,"errorMessage":"Unsupported channel dimension: {input_data_format}","messagePattern":"Unsupported channel dimension: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_transforms.py","lineNumber":808,"sourceCode":"        data_format (`ChannelDimension`, *optional*):\n            The channel dimension format for the output image. Can be one of:\n                - `ChannelDimension.FIRST`: image in (num_channels, height, width) format.\n                - `ChannelDimension.LAST`: image in (height, width, num_channels) format.\n            If unset, will use same as the input image.\n        input_data_format (`ChannelDimension`, *optional*):\n            The channel dimension format for the input image. Can be one of:\n                - `ChannelDimension.FIRST`: image in (num_channels, height, width) format.\n                - `ChannelDimension.LAST`: image in (height, width, num_channels) format.\n            If unset, will use the inferred format of the input image.\n    \"\"\"\n    input_data_format = infer_channel_dimension_format(image) if input_data_format is None else input_data_format\n\n    if input_data_format == ChannelDimension.LAST:\n        image = image[..., ::-1]\n    elif input_data_format == ChannelDimension.FIRST:\n        image = image[::-1, ...]\n    else:\n        raise ValueError(f\"Unsupported channel dimension: {input_data_format}\")\n\n    if data_format is not None:\n        image = to_channel_dimension_format(image, data_format, input_channel_dim=input_data_format)\n    return image\n\n\ndef split_to_tiles(images: \"torch.Tensor\", num_tiles_height: int, num_tiles_width: int) -> \"torch.Tensor\":\n    # Split image into number of required tiles (width x height)\n    batch_size, num_channels, height, width = images.size()\n    images = images.view(\n        batch_size,\n        num_channels,\n        num_tiles_height,\n        height // num_tiles_height,\n        num_tiles_width,\n        width // num_tiles_width,\n    )\n    # Permute dimensions to reorder the axes","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_transforms.py#L790-L826","documentation":"Raised by `transformers.image_transforms.flip_channel_order()` when `input_data_format` (after inference) is neither `ChannelDimension.FIRST` ('channels_first') nor `ChannelDimension.LAST` ('channels_last'). The function reverses channel order (RGB<->BGR) by slicing along the axis implied by the format; an unknown format means the axis cannot be located, so it refuses rather than flipping the wrong axis. If `input_data_format` is None, it is first inferred with `infer_channel_dimension_format`, which can itself raise earlier.","triggerScenarios":"Calling `flip_channel_order(image, input_data_format='channel_first')` (typo, missing 's'), 'NCHW', 'first', or any string not equal to the two enum values. Also passing an explicitly invalid value so inference is skipped and the bad value reaches the else-branch directly.","commonSituations":"Mixing conventions across libraries: torchvision/torchaudio layouts ('NCHW'), Keras ('channels_last' works but variants don't), or older code using plain strings like 'first'/'last'. Custom preprocessing pipelines threading a user-supplied format string through without validation.","solutions":["Pass `ChannelDimension.FIRST` or `ChannelDimension.LAST`, or the exact strings 'channels_first' / 'channels_last'.","Leave `input_data_format=None` to let the library infer the axis from the array shape.","If the value comes from config/user input, normalize it against the enum before calling: `input_data_format = ChannelDimension(input_data_format)` raises a clear error for bad values."],"exampleFix":"// before\nflipped = flip_channel_order(img, input_data_format=\"NCHW\")  # ValueError\n\n// after\nfrom transformers.image_utils import ChannelDimension\nflipped = flip_channel_order(img, input_data_format=ChannelDimension.FIRST)\n// or let it infer:\nflipped = flip_channel_order(img, input_data_format=None)","handlingStrategy":"validation","validationCode":"from transformers.image_utils import ChannelDimension\n\ninput_data_format = ChannelDimension(input_data_format)  # raises clear error for bad values\nflipped = flip_channel_order(image, input_data_format=input_data_format)","typeGuard":"from transformers.image_utils import ChannelDimension\n\ndef is_channel_dim(v) -> bool:\n    return v in (ChannelDimension.FIRST, ChannelDimension.LAST, \"channels_first\", \"channels_last\")","tryCatchPattern":null,"preventionTips":["Thread ChannelDimension enum values (not free strings) through custom preprocessing code.","Normalize external layout strings once with ChannelDimension(value) at the config boundary.","Remember valid strings are exactly 'channels_first' and 'channels_last'."],"tags":["image-processing","channel-dimension","enum","argument-validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}