huggingface/transformers · error · ValueError
Got type {type(image)} which is not supported, only `PIL.Ima
Error message
Got type {type(image)} which is not supported, only `PIL.Image.Image`, `np.ndarray` and `torch.Tensor` are. What it means
Error "Got type {type(image)} which is not supported, only `PIL.Image.Image`, `np.ndarray` and `torch.Tensor` are." thrown in huggingface/transformers.
Source
Thrown at src/transformers/image_utils.py:635
if do_normalize and (image_mean is None or image_std is None):
raise ValueError("`image_mean` and `image_std` must both be specified if `do_normalize` is `True`.")
if do_center_crop and crop_size is None:
raise ValueError("`crop_size` must be specified if `do_center_crop` is `True`.")
if do_resize and not (size is not None and resample is not None):
raise ValueError("`size` and `resample` must be specified if `do_resize` is `True`.")
class ImageFeatureExtractionMixin:
"""
Mixin that contain utilities for preparing image features.
"""
def _ensure_format_supported(self, image):
if not isinstance(image, (PIL.Image.Image, np.ndarray)) and not is_torch_tensor(image):
raise ValueError(
f"Got type {type(image)} which is not supported, only `PIL.Image.Image`, `np.ndarray` and "
"`torch.Tensor` are."
)
def to_pil_image(self, image, rescale=None):
"""
Converts `image` to a PIL Image. Optionally rescales it and puts the channel dimension back as the last axis if
needed.
Args:
image (`PIL.Image.Image` or `numpy.ndarray` or `torch.Tensor`):
The image to convert to the PIL Image format.
rescale (`bool`, *optional*):
Whether or not to apply the scaling factor (to make pixel values integers between 0 and 255). Will
default to `True` if the image type is a floating type, `False` otherwise.
"""
self._ensure_format_supported(image)
View on GitHub (pinned to a597f97485)
Solutions
- Convert the image to PIL.Image.Image, np.ndarray, or torch.Tensor before processing.
- Use `load_image` for URLs, paths, or base64 strings.
When it happens
Trigger: Raised in image type validation when input is not a PIL image, numpy array, or torch tensor.
Common situations: Passing lists, scalars, or TensorFlow/JAX tensors where only PIL/np/torch images are accepted.
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/e101674744ff7a87.
Report an issue: GitHub.