{"record":{"id":"327ee6fc63305793","repo":"huggingface/transformers","slug":"unrecognized-image-type-type-image","errorCode":null,"errorMessage":"Unrecognized image type {type(image)}","messagePattern":"Unrecognized image type (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_utils.py","lineNumber":115,"sourceCode":"\ndef is_pil_image(img):\n    return is_vision_available() and isinstance(img, PIL.Image.Image)\n\n\nclass ImageType(ExplicitEnum):\n    PIL = \"pillow\"\n    TORCH = \"torch\"\n    NUMPY = \"numpy\"\n\n\ndef get_image_type(image):\n    if is_pil_image(image):\n        return ImageType.PIL\n    if is_torch_tensor(image):\n        return ImageType.TORCH\n    if is_numpy_array(image):\n        return ImageType.NUMPY\n    raise ValueError(f\"Unrecognized image type {type(image)}\")\n\n\ndef is_valid_image(img):\n    return is_pil_image(img) or is_numpy_array(img) or is_torch_tensor(img)\n\n\ndef is_valid_list_of_images(images: list):\n    return images and all(is_valid_image(image) for image in images)\n\n\ndef concatenate_list(input_list):\n    if isinstance(input_list[0], list):\n        return [item for sublist in input_list for item in sublist]\n    elif isinstance(input_list[0], np.ndarray):\n        return np.concatenate(input_list, axis=0)\n    elif isinstance(input_list[0], torch.Tensor):\n        return torch.cat(input_list, dim=0)\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_utils.py#L97-L133","documentation":"Raised by `transformers.image_utils.get_image_type()` when the input is not a PIL.Image.Image, not a torch.Tensor, and not a numpy.ndarray. This helper classifies images into an ImageType enum (PIL/TORCH/NUMPY); anything outside those three categories is unsupported. Downstream helpers like `is_valid_image` use the same three-way check, so unsupported types are rejected consistently across the image pipeline.","triggerScenarios":"Calling `get_image_type()` with a TensorFlow/JAX tensor, a raw Python list or nested list, a file-path string, a bytes object, or a torch tensor that fails `is_torch_tensor` because torch is not importable in the environment.","commonSituations":"Users pass file paths or URLs expecting the function to load them (it doesn't — use `load_image`); TensorFlow pipelines feed tf.Tensor into a transformers image processor; or a minimal environment where torch is absent so torch tensors are not recognized.","solutions":["Convert the input before use: `np.array(x)` for lists/tf tensors, or `torch.tensor(x)` for torch pipelines.","For path/URL/base64 strings, use `transformers.image_utils.load_image(image)` instead of classification helpers.","Ensure the array is a real np.ndarray, not a pandas/bytes/other array-like."],"exampleFix":"// before\ntype_ = get_image_type(\"cat.jpg\")        # ValueError\ntype_ = get_image_type([[1,2],[3,4]])   # ValueError\n\n// after\nfrom transformers.image_utils import load_image\nimg = load_image(\"cat.jpg\")              # str -> PIL image\ntype_ = get_image_type(img)              # ImageType.PIL","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"from transformers.image_utils import is_valid_image\n\ndef as_supported_image(x):\n    if not is_valid_image(x):\n        raise TypeError(f\"Expected PIL/numpy/torch image, got {type(x)}; load strings with load_image()\")\n    return x","tryCatchPattern":null,"preventionTips":["Load path/URL/base64 strings with load_image before any type classification.","Convert tf tensors and lists to np.ndarray at your pipeline entry point.","Never assume get_image_type will convert — it only classifies."],"tags":["image-processing","type-checking","argument-validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}