Processors: allow tuples of images when checking (#36084)

allow tuples of images
This commit is contained in:
Raushan Turganbay 2025-02-10 09:35:13 +01:00 committed by GitHub
parent 3a3b06ace4
commit 5bd7694781
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 16 deletions

View file

@ -221,7 +221,7 @@ class Idefics2Processor(ProcessorMixin):
if images is not None:
if is_image_or_image_url(images):
images = [[images]]
elif isinstance(images, list) and is_image_or_image_url(images[0]):
elif isinstance(images, (list, tuple)) and is_image_or_image_url(images[0]):
if text is not None:
if sum(n_images_in_text) != len(images):
raise ValueError(
@ -238,8 +238,8 @@ class Idefics2Processor(ProcessorMixin):
images = [images]
elif (
not isinstance(images, list)
and not isinstance(images[0], list)
not isinstance(images, (list, tuple))
and not isinstance(images[0], (list, tuple))
and not is_image_or_image_url(images[0][0])
):
raise ValueError(

View file

@ -252,7 +252,7 @@ class Idefics3Processor(ProcessorMixin):
if images is not None:
if is_image_or_image_url(images):
images = [[images]]
elif isinstance(images, list) and is_image_or_image_url(images[0]):
elif isinstance(images, (list, tuple)) and is_image_or_image_url(images[0]):
if text is not None:
if sum(n_images_in_text) != len(images):
raise ValueError(
@ -268,8 +268,8 @@ class Idefics3Processor(ProcessorMixin):
else:
images = [images]
elif (
not isinstance(images, list)
and not isinstance(images[0], list)
not isinstance(images, (list, tuple))
and not isinstance(images[0], (list, tuple))
and not is_image_or_image_url(images[0][0])
):
raise ValueError(

View file

@ -19,7 +19,7 @@ Processor class for PaliGemma.
from typing import List, Optional, Union
from ...feature_extraction_utils import BatchFeature
from ...image_utils import ImageInput, is_valid_image, make_flat_list_of_images
from ...image_utils import ImageInput, is_valid_image, make_flat_list_of_images, make_nested_list_of_images
from ...processing_utils import (
ImagesKwargs,
ProcessingKwargs,
@ -256,13 +256,7 @@ class PaliGemmaProcessor(ProcessorMixin):
)
# make a nested list of lists to be able to iterate over the images and text below
if is_valid_image(images):
images = [[images]]
elif isinstance(images, list) and is_valid_image(images[0]):
images = [[image] for image in images]
elif not (isinstance(images, list) and isinstance(images[0], list) and is_valid_image(images[0][0])):
raise ValueError("images must be an image, list of images or list of list of images")
images = make_nested_list_of_images(images)
input_strings = [
build_string_from_input(
prompt=prompt,

View file

@ -154,9 +154,13 @@ class PixtralProcessor(ProcessorMixin):
if images is not None:
if is_image_or_image_url(images):
images = [images]
elif isinstance(images, list) and is_image_or_image_url(images[0]):
elif isinstance(images, (list, tuple)) and is_image_or_image_url(images[0]):
pass
elif isinstance(images, list) and isinstance(images[0], list) and is_image_or_image_url(images[0][0]):
elif (
isinstance(images, (list, tuple))
and isinstance(images[0], (list, tuple))
and is_image_or_image_url(images[0][0])
):
images = [image for sublist in images for image in sublist]
else:
raise ValueError(