huggingface/transformers · error · TypeError

only a single or a list of entries is supported but got type

Error message

only a single or a list of entries is supported but got type={type(image_url_or_urls)}

What it means

Error "only a single or a list of entries is supported but got type={type(image_url_or_urls)}" thrown in huggingface/transformers.

Source

Thrown at src/transformers/image_processing_backends.py:114

        `str`: The backend used by this image processor.
        """
        return "torchvision"

    def fetch_images(self, image_url_or_urls: str | list[str] | list[list[str]]):
        """
        Convert a single or a list of URLs / paths into `torch.Tensor` objects.

        Already-valid image objects (tensors, numpy arrays, PIL Images) are passed through
        unchanged so that callers who pre-load images are unaffected.
        """
        if isinstance(image_url_or_urls, (list, tuple)):
            return [self.fetch_images(x) for x in image_url_or_urls]
        elif isinstance(image_url_or_urls, str):
            return load_image_as_tensor(image_url_or_urls)
        elif is_valid_image(image_url_or_urls):
            return image_url_or_urls
        else:
            raise TypeError(f"only a single or a list of entries is supported but got type={type(image_url_or_urls)}")

    def process_image(
        self,
        image: ImageInput,
        do_convert_rgb: bool | None = None,
        input_data_format: str | ChannelDimension | None = None,
        device: Optional["torch.device"] = None,
        **kwargs: Unpack[ImagesKwargs],
    ) -> "torch.Tensor":
        """Process a single image for torchvision backend."""
        image_type = get_image_type(image)
        if image_type not in [ImageType.PIL, ImageType.TORCH, ImageType.NUMPY]:
            raise ValueError(f"Unsupported input image type {image_type}")

        if do_convert_rgb:
            image = self.convert_to_rgb(image)

        if image_type == ImageType.PIL:

View on GitHub (pinned to a597f97485)

Solutions

  1. Pass a single image URL/path or a list of them.
  2. Wrap iterables that are not lists into a list first.

When it happens

Trigger: Raised in image processing fetch path when image_url_or_urls is neither a single string/URL nor a list.

Common situations: Passing a tuple, dict, or nested structure of image URLs to an image processor backend.


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/72410ce7ca7ac293. Report an issue: GitHub.