{"record":{"id":"511f266ad0c1376d","repo":"huggingface/transformers","slug":"unsupported-data-format-input-data-format","errorCode":null,"errorMessage":"Unsupported data format: {input_data_format}","messagePattern":"Unsupported data format: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_utils.py","lineNumber":346,"sourceCode":"    \"\"\"\n    Returns the channel dimension axis of the image.\n\n    Args:\n        image (`np.ndarray`):\n            The image to get the channel dimension axis of.\n        input_data_format (`ChannelDimension` or `str`, *optional*):\n            The channel dimension format of the image. If `None`, will infer the channel dimension from the image.\n\n    Returns:\n        The channel dimension axis of the image.\n    \"\"\"\n    if input_data_format is None:\n        input_data_format = infer_channel_dimension_format(image)\n    if input_data_format == ChannelDimension.FIRST:\n        return image.ndim - 3\n    elif input_data_format == ChannelDimension.LAST:\n        return image.ndim - 1\n    raise ValueError(f\"Unsupported data format: {input_data_format}\")\n\n\ndef get_image_size(\n    image: Union[np.ndarray, \"PIL.Image.Image\"], channel_dim: ChannelDimension | None = None\n) -> tuple[int, int]:\n    \"\"\"\n    Returns the (height, width) dimensions of the image.\n\n    Args:\n        image (`np.ndarray | PIL.Image.Image`):\n            The image to get the dimensions of.\n        channel_dim (`ChannelDimension`, *optional*):\n            Which dimension the channel dimension is in. If `None`, will infer the channel dimension from the image.\n\n    Returns:\n        A tuple of the image's height and width.\n    \"\"\"\n    if isinstance(image, PIL.Image.Image):","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_utils.py#L328-L364","documentation":"Raised by `transformers.image_utils.get_channel_dimension_axis` when `input_data_format` (after optional inference) is neither `ChannelDimension.FIRST` nor `ChannelDimension.LAST`. The function computes the axis index of the channel dimension (ndim-3 for first, ndim-1 for last); an unrecognized format string makes the axis undefined, so it raises. If `input_data_format` is None, inference runs first and can raise its own errors (e.g. 'Unable to infer channel dimension format').","triggerScenarios":"Calling `get_channel_dimension_axis(image, 'NCHW')`, 'first', 'channels-first' (hyphen instead of underscore), or any malformed string. Also passing a lowercase enum value variant that doesn't match 'channels_first'/'channels_last'.","commonSituations":"Threading user- or config-supplied layout strings through custom preprocessing; conventions borrowed from other frameworks (NHWC/NCHW) that don't match transformers' enum values; typos in serialized config.","solutions":["Use `ChannelDimension.FIRST` / `ChannelDimension.LAST` or exact strings 'channels_first' / 'channels_last'.","Normalize external values through the enum: `ChannelDimension(value)` gives a clear error for bad inputs.","Pass None to let the axis be inferred from the image shape."],"exampleFix":"// before\naxis = get_channel_dimension_axis(img, input_data_format=\"NCHW\")  # ValueError\n\n// after\nfrom transformers.image_utils import ChannelDimension\naxis = get_channel_dimension_axis(img, input_data_format=ChannelDimension.FIRST)\naxis = get_channel_dimension_axis(img)  # infer","handlingStrategy":"validation","validationCode":"from transformers.image_utils import ChannelDimension\n\ninput_data_format = ChannelDimension(input_data_format)  # fail fast on bad strings\naxis = get_channel_dimension_axis(image, input_data_format=input_data_format)","typeGuard":"from transformers.image_utils import ChannelDimension\n\ndef is_valid_data_format(v) -> bool:\n    return v in (ChannelDimension.FIRST, ChannelDimension.LAST, \"channels_first\", \"channels_last\")","tryCatchPattern":null,"preventionTips":["Type layout fields as ChannelDimension, not free-form strings.","Validate config-supplied layout values with ChannelDimension(value) at load time.","Use exact strings 'channels_first'/'channels_last' when enums are impractical."],"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"}