mirror of
https://github.com/saymrwulf/transformers.git
synced 2026-05-14 20:58:08 +00:00
Processors: allow tuples of images when checking (#36084)
allow tuples of images
This commit is contained in:
parent
3a3b06ace4
commit
5bd7694781
4 changed files with 14 additions and 16 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue