


"""simple docstring"""






import json
import pathlib
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision, slow
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import DetaImageProcessor





class      lowerCamelCase__   (     unittest.TestCase				):







					"""simple docstring"""


					def __init__(       self    : List[Any] ,       UpperCamelCase    : List[Any] ,       UpperCamelCase    : int=7 ,       UpperCamelCase    : int=3 ,       UpperCamelCase    : Union[str, Any]=30 ,       UpperCamelCase    : int=400 ,       UpperCamelCase    : Optional[int]=True ,       UpperCamelCase    : Tuple=None ,       UpperCamelCase    : List[Any]=True ,       UpperCamelCase    : Union[str, Any]=[0.5, 0.5, 0.5] ,       UpperCamelCase    : str=[0.5, 0.5, 0.5] ,       UpperCamelCase    : int=True ,       UpperCamelCase    : List[str]=1 / 255 ,       UpperCamelCase    : Any=True ,       ):
												'''simple docstring'''






												__UpperCAmelCase   :						Optional[Any]      							=					size if size is not None else {"""shortest_edge""": 18, """longest_edge""": 1_333}
												__UpperCAmelCase   :						Optional[Any]      							=					parent
												__UpperCAmelCase   :						int      							=					batch_size
												__UpperCAmelCase   :						Tuple      							=					num_channels
												__UpperCAmelCase   :						List[str]      							=					min_resolution
												__UpperCAmelCase   :						Any      							=					max_resolution
												__UpperCAmelCase   :						Union[str, Any]      							=					do_resize
												__UpperCAmelCase   :						str      							=					size
												__UpperCAmelCase   :						Optional[int]      							=					do_normalize
												__UpperCAmelCase   :						Optional[int]      							=					image_mean
												__UpperCAmelCase   :						Union[str, Any]      							=					image_std
												__UpperCAmelCase   :						List[str]      							=					do_rescale
												__UpperCAmelCase   :						int      							=					rescale_factor
												__UpperCAmelCase   :						Union[str, Any]      							=					do_pad






					def lowerCamelCase__							(       self    : Dict  ):
												'''simple docstring'''






												return {
												    "do_resize": self.do_resize,
												    "size": self.size,
												    "do_normalize": self.do_normalize,
												    "image_mean": self.image_mean,
												    "image_std": self.image_std,
												    "do_rescale": self.do_rescale,
												    "rescale_factor": self.rescale_factor,
												    "do_pad": self.do_pad,
												}






					def lowerCamelCase__							(       self    : int ,       UpperCamelCase    : Union[str, Any] ,       UpperCamelCase    : List[str]=False  ):
												'''simple docstring'''






												if not batched:
																			__UpperCAmelCase   :						Optional[int]      							=					image_inputs[0]
																			if isinstance(UpperCamelCase ,       Image.Image  ):
																										__UpperCAmelCase							,__UpperCAmelCase   :						List[str]      							=					image.size
																			else:
																										__UpperCAmelCase							,__UpperCAmelCase   :						List[str]      							=					image.shape[1], image.shape[2]
																			if w < h:
																										__UpperCAmelCase   :						Any      							=					int(self.size["""shortest_edge"""] * h / w  )
																										__UpperCAmelCase   :						str      							=					self.size["""shortest_edge"""]
																			elif w > h:
																										__UpperCAmelCase   :						int      							=					self.size["""shortest_edge"""]
																										__UpperCAmelCase   :						Tuple      							=					int(self.size["""shortest_edge"""] * w / h  )
																			else:
																										__UpperCAmelCase   :						Union[str, Any]      							=					self.size["""shortest_edge"""]
																										__UpperCAmelCase   :						str      							=					self.size["""shortest_edge"""]

												else:
																			__UpperCAmelCase   :						int      							=					[]
																			for image in image_inputs:
																										__UpperCAmelCase							,__UpperCAmelCase   :						str      							=					self.get_expected_values([image]  )
																										expected_values.append((expected_height, expected_width)  )
																			__UpperCAmelCase   :						List[Any]      							=					max(UpperCamelCase ,       key=lambda UpperCamelCase  : item[0]  )[0]
																			__UpperCAmelCase   :						Optional[int]      							=					max(UpperCamelCase ,       key=lambda UpperCamelCase  : item[1]  )[1]

												return expected_height, expected_width






@require_torch
@require_vision
class      lowerCamelCase__   (     A     ,    unittest.TestCase				):







					"""simple docstring"""


					__a	       =							DetaImageProcessor if is_vision_available() else None






					def lowerCamelCase__							(       self    : Any  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Any      							=					DetaImageProcessingTester(self  )






					@property
					def lowerCamelCase__							(       self    : int  ):
												'''simple docstring'''






												return self.image_processor_tester.prepare_image_processor_dict()






					def lowerCamelCase__							(       self    : int  ):
												'''simple docstring'''






												__UpperCAmelCase   :						List[Any]      							=					self.image_processing_class(**self.image_processor_dict  )
												self.assertTrue(hasattr(UpperCamelCase ,       """image_mean"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """image_std"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """do_normalize"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """do_resize"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """do_rescale"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """do_pad"""  )  )
												self.assertTrue(hasattr(UpperCamelCase ,       """size"""  )  )






					def lowerCamelCase__							(       self    : int  ):
												'''simple docstring'''






												__UpperCAmelCase   :						List[str]      							=					self.image_processing_class.from_dict(self.image_processor_dict  )
												self.assertEqual(image_processor.size ,       {"""shortest_edge""": 18, """longest_edge""": 1_333}  )
												self.assertEqual(image_processor.do_pad ,       UpperCamelCase  )






					def lowerCamelCase__							(       self    : str  ):
												'''simple docstring'''






												pass






					def lowerCamelCase__							(       self    : Union[str, Any]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						List[Any]      							=					self.image_processing_class(**self.image_processor_dict  )
												# create random PIL images
												__UpperCAmelCase   :						Optional[Any]      							=					prepare_image_inputs(self.image_processor_tester ,       equal_resolution=UpperCamelCase  )
												for image in image_inputs:
																			self.assertIsInstance(UpperCamelCase ,       Image.Image  )

												# Test not batched input
												__UpperCAmelCase   :						int      							=					image_processing(image_inputs[0] ,       return_tensors="""pt"""  ).pixel_values

												__UpperCAmelCase							,__UpperCAmelCase   :						List[Any]      							=					self.image_processor_tester.get_expected_values(UpperCamelCase  )

												self.assertEqual(
												    encoded_images.shape ,       (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,       )

												# Test batched
												__UpperCAmelCase							,__UpperCAmelCase   :						Any      							=					self.image_processor_tester.get_expected_values(UpperCamelCase ,       batched=UpperCamelCase  )

												__UpperCAmelCase   :						Tuple      							=					image_processing(UpperCamelCase ,       return_tensors="""pt"""  ).pixel_values
												self.assertEqual(
												    encoded_images.shape ,       (
												        self.image_processor_tester.batch_size,
												        self.image_processor_tester.num_channels,
												        expected_height,
												        expected_width,
												    ) ,       )






					def lowerCamelCase__							(       self    : str  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Optional[int]      							=					self.image_processing_class(**self.image_processor_dict  )
												# create random numpy tensors
												__UpperCAmelCase   :						Dict      							=					prepare_image_inputs(self.image_processor_tester ,       equal_resolution=UpperCamelCase ,       numpify=UpperCamelCase  )
												for image in image_inputs:
																			self.assertIsInstance(UpperCamelCase ,       np.ndarray  )

												# Test not batched input
												__UpperCAmelCase   :						str      							=					image_processing(image_inputs[0] ,       return_tensors="""pt"""  ).pixel_values

												__UpperCAmelCase							,__UpperCAmelCase   :						List[str]      							=					self.image_processor_tester.get_expected_values(UpperCamelCase  )

												self.assertEqual(
												    encoded_images.shape ,       (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,       )

												# Test batched
												__UpperCAmelCase   :						Union[str, Any]      							=					image_processing(UpperCamelCase ,       return_tensors="""pt"""  ).pixel_values

												__UpperCAmelCase							,__UpperCAmelCase   :						Tuple      							=					self.image_processor_tester.get_expected_values(UpperCamelCase ,       batched=UpperCamelCase  )

												self.assertEqual(
												    encoded_images.shape ,       (
												        self.image_processor_tester.batch_size,
												        self.image_processor_tester.num_channels,
												        expected_height,
												        expected_width,
												    ) ,       )






					def lowerCamelCase__							(       self    : Optional[int]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						int      							=					self.image_processing_class(**self.image_processor_dict  )
												# create random PyTorch tensors
												__UpperCAmelCase   :						Tuple      							=					prepare_image_inputs(self.image_processor_tester ,       equal_resolution=UpperCamelCase ,       torchify=UpperCamelCase  )
												for image in image_inputs:
																			self.assertIsInstance(UpperCamelCase ,       torch.Tensor  )

												# Test not batched input
												__UpperCAmelCase   :						List[Any]      							=					image_processing(image_inputs[0] ,       return_tensors="""pt"""  ).pixel_values

												__UpperCAmelCase							,__UpperCAmelCase   :						Any      							=					self.image_processor_tester.get_expected_values(UpperCamelCase  )

												self.assertEqual(
												    encoded_images.shape ,       (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,       )

												# Test batched
												__UpperCAmelCase   :						str      							=					image_processing(UpperCamelCase ,       return_tensors="""pt"""  ).pixel_values

												__UpperCAmelCase							,__UpperCAmelCase   :						Tuple      							=					self.image_processor_tester.get_expected_values(UpperCamelCase ,       batched=UpperCamelCase  )

												self.assertEqual(
												    encoded_images.shape ,       (
												        self.image_processor_tester.batch_size,
												        self.image_processor_tester.num_channels,
												        expected_height,
												        expected_width,
												    ) ,       )






					@slow
					def lowerCamelCase__							(       self    : Optional[int]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Any      							=					Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""  )
												with open("""./tests/fixtures/tests_samples/COCO/coco_annotations.txt""" ,       """r"""  ) as f:
																			__UpperCAmelCase   :						Optional[int]      							=					json.loads(f.read()  )

												__UpperCAmelCase   :						Optional[int]      							=					{"""image_id""": 39_769, """annotations""": target}

												# encode them
												__UpperCAmelCase   :						Union[str, Any]      							=					DetaImageProcessor()
												__UpperCAmelCase   :						Dict      							=					image_processing(images=UpperCamelCase ,       annotations=UpperCamelCase ,       return_tensors="""pt"""  )

												# verify pixel values
												__UpperCAmelCase   :						int      							=					torch.Size([1, 3, 800, 1_066]  )
												self.assertEqual(encoding["""pixel_values"""].shape ,       UpperCamelCase  )

												__UpperCAmelCase   :						Optional[int]      							=					torch.tensor([0.2796, 0.3138, 0.3481]  )
												self.assertTrue(torch.allclose(encoding["""pixel_values"""][0, 0, 0, :3] ,       UpperCamelCase ,       atol=1e-4  )  )

												# verify area
												__UpperCAmelCase   :						Optional[int]      							=					torch.tensor([5887.9600, 11250.2061, 489353.8438, 837122.7500, 147967.5156, 165732.3438]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""area"""] ,       UpperCamelCase  )  )
												# verify boxes
												__UpperCAmelCase   :						List[str]      							=					torch.Size([6, 4]  )
												self.assertEqual(encoding["""labels"""][0]["""boxes"""].shape ,       UpperCamelCase  )
												__UpperCAmelCase   :						Tuple      							=					torch.tensor([0.5503, 0.2765, 0.0604, 0.2215]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""boxes"""][0] ,       UpperCamelCase ,       atol=1e-3  )  )
												# verify image_id
												__UpperCAmelCase   :						Optional[int]      							=					torch.tensor([39_769]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""image_id"""] ,       UpperCamelCase  )  )
												# verify is_crowd
												__UpperCAmelCase   :						List[str]      							=					torch.tensor([0, 0, 0, 0, 0, 0]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""iscrowd"""] ,       UpperCamelCase  )  )
												# verify class_labels
												__UpperCAmelCase   :						Tuple      							=					torch.tensor([75, 75, 63, 65, 17, 17]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""class_labels"""] ,       UpperCamelCase  )  )
												# verify orig_size
												__UpperCAmelCase   :						Union[str, Any]      							=					torch.tensor([480, 640]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""orig_size"""] ,       UpperCamelCase  )  )
												# verify size
												__UpperCAmelCase   :						List[str]      							=					torch.tensor([800, 1_066]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""size"""] ,       UpperCamelCase  )  )






					@slow
					def lowerCamelCase__							(       self    : str  ):
												'''simple docstring'''






												__UpperCAmelCase   :						List[str]      							=					Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""  )
												with open("""./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt""" ,       """r"""  ) as f:
																			__UpperCAmelCase   :						Any      							=					json.loads(f.read()  )

												__UpperCAmelCase   :						Dict      							=					{"""file_name""": """000000039769.png""", """image_id""": 39_769, """segments_info""": target}

												__UpperCAmelCase   :						List[Any]      							=					pathlib.Path("""./tests/fixtures/tests_samples/COCO/coco_panoptic"""  )

												# encode them
												__UpperCAmelCase   :						Optional[int]      							=					DetaImageProcessor(format="""coco_panoptic"""  )
												__UpperCAmelCase   :						List[Any]      							=					image_processing(images=UpperCamelCase ,       annotations=UpperCamelCase ,       masks_path=UpperCamelCase ,       return_tensors="""pt"""  )

												# verify pixel values
												__UpperCAmelCase   :						List[str]      							=					torch.Size([1, 3, 800, 1_066]  )
												self.assertEqual(encoding["""pixel_values"""].shape ,       UpperCamelCase  )

												__UpperCAmelCase   :						str      							=					torch.tensor([0.2796, 0.3138, 0.3481]  )
												self.assertTrue(torch.allclose(encoding["""pixel_values"""][0, 0, 0, :3] ,       UpperCamelCase ,       atol=1e-4  )  )

												# verify area
												__UpperCAmelCase   :						int      							=					torch.tensor([147979.6875, 165527.0469, 484638.5938, 11292.9375, 5879.6562, 7634.1147]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""area"""] ,       UpperCamelCase  )  )
												# verify boxes
												__UpperCAmelCase   :						List[str]      							=					torch.Size([6, 4]  )
												self.assertEqual(encoding["""labels"""][0]["""boxes"""].shape ,       UpperCamelCase  )
												__UpperCAmelCase   :						int      							=					torch.tensor([0.2625, 0.5437, 0.4688, 0.8625]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""boxes"""][0] ,       UpperCamelCase ,       atol=1e-3  )  )
												# verify image_id
												__UpperCAmelCase   :						str      							=					torch.tensor([39_769]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""image_id"""] ,       UpperCamelCase  )  )
												# verify is_crowd
												__UpperCAmelCase   :						Dict      							=					torch.tensor([0, 0, 0, 0, 0, 0]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""iscrowd"""] ,       UpperCamelCase  )  )
												# verify class_labels
												__UpperCAmelCase   :						Union[str, Any]      							=					torch.tensor([17, 17, 63, 75, 75, 93]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""class_labels"""] ,       UpperCamelCase  )  )
												# verify masks
												__UpperCAmelCase   :						Union[str, Any]      							=					822_873
												self.assertEqual(encoding["""labels"""][0]["""masks"""].sum().item() ,       UpperCamelCase  )
												# verify orig_size
												__UpperCAmelCase   :						Any      							=					torch.tensor([480, 640]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""orig_size"""] ,       UpperCamelCase  )  )
												# verify size
												__UpperCAmelCase   :						str      							=					torch.tensor([800, 1_066]  )
												self.assertTrue(torch.allclose(encoding["""labels"""][0]["""size"""] ,       UpperCamelCase  )  )




"""simple docstring"""






from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
							import PIL


UpperCAmelCase    :     Optional[Any]   						=		logging.get_logger(__name__)
def      lowerCamelCase       (     _UpperCamelCase		:      Any       ,			_UpperCamelCase		:      Optional[Any]							)		->       int:

							'''simple docstring'''



							__UpperCAmelCase   :						int      							=					b.T
							__UpperCAmelCase   :						Union[str, Any]      							=					np.sum(np.square(_UpperCamelCase							)       ,			axis=1							)
							__UpperCAmelCase   :						List[Any]      							=					np.sum(np.square(_UpperCamelCase							)       ,			axis=0							)
							__UpperCAmelCase   :						int      							=					np.matmul(_UpperCamelCase       ,			_UpperCamelCase							)
							__UpperCAmelCase   :						Tuple      							=					aa[:, None] - 2 * ab + ba[None, :]
							return d
def      lowerCamelCase       (     _UpperCamelCase		:      Tuple       ,			_UpperCamelCase		:      Optional[Any]							)		->       Optional[int]:

							'''simple docstring'''



							__UpperCAmelCase   :						Tuple      							=					x.reshape(-1       ,			3							)
							__UpperCAmelCase   :						Optional[Any]      							=					squared_euclidean_distance(_UpperCamelCase       ,			_UpperCamelCase							)
							return np.argmin(_UpperCamelCase       ,			axis=1							)





class      lowerCamelCase__   (     A				):







					"""simple docstring"""


					__a	       =							["""pixel_values"""]






					def __init__(       self    : List[str] ,       UpperCamelCase    : Optional[Union[List[List[int]], np.ndarray]] = None ,       UpperCamelCase    : bool = True ,       UpperCamelCase    : Dict[str, int] = None ,       UpperCamelCase    : PILImageResampling = PILImageResampling.BILINEAR ,       UpperCamelCase    : bool = True ,       UpperCamelCase    : bool = True ,       **UpperCamelCase    : int ,       ):
												'''simple docstring'''






												super().__init__(**UpperCamelCase  )
												__UpperCAmelCase   :						Optional[Any]      							=					size if size is not None else {"""height""": 256, """width""": 256}
												__UpperCAmelCase   :						Tuple      							=					get_size_dict(UpperCamelCase  )
												__UpperCAmelCase   :						Union[str, Any]      							=					np.array(UpperCamelCase  ) if clusters is not None else None
												__UpperCAmelCase   :						int      							=					do_resize
												__UpperCAmelCase   :						List[str]      							=					size
												__UpperCAmelCase   :						Dict      							=					resample
												__UpperCAmelCase   :						int      							=					do_normalize
												__UpperCAmelCase   :						List[Any]      							=					do_color_quantize






					def lowerCamelCase__							(       self    : List[str] ,       UpperCamelCase    : np.ndarray ,       UpperCamelCase    : Dict[str, int] ,       UpperCamelCase    : PILImageResampling = PILImageResampling.BILINEAR ,       UpperCamelCase    : Optional[Union[str, ChannelDimension]] = None ,       **UpperCamelCase    : str ,       ):
												'''simple docstring'''






												__UpperCAmelCase   :						Any      							=					get_size_dict(UpperCamelCase  )
												if "height" not in size or "width" not in size:
																			raise ValueError(f'''Size dictionary must contain both height and width keys. Got {size.keys()}'''  )
												return resize(
												    UpperCamelCase ,       size=(size["""height"""], size["""width"""]) ,       resample=UpperCamelCase ,       data_format=UpperCamelCase ,       **UpperCamelCase  )






					def lowerCamelCase__							(       self    : Dict ,       UpperCamelCase    : np.ndarray ,       UpperCamelCase    : Optional[Union[str, ChannelDimension]] = None ,       ):
												'''simple docstring'''






												__UpperCAmelCase   :						Optional[Any]      							=					rescale(image=UpperCamelCase ,       scale=1 / 127.5 ,       data_format=UpperCamelCase  )
												__UpperCAmelCase   :						Optional[Any]      							=					image - 1
												return image






					def lowerCamelCase__							(       self    : Dict ,       UpperCamelCase    : ImageInput ,       UpperCamelCase    : bool = None ,       UpperCamelCase    : Dict[str, int] = None ,       UpperCamelCase    : PILImageResampling = None ,       UpperCamelCase    : bool = None ,       UpperCamelCase    : Optional[bool] = None ,       UpperCamelCase    : Optional[Union[List[List[int]], np.ndarray]] = None ,       UpperCamelCase    : Optional[Union[str, TensorType]] = None ,       UpperCamelCase    : Optional[Union[str, ChannelDimension]] = ChannelDimension.FIRST ,       **UpperCamelCase    : Optional[int] ,       ):
												'''simple docstring'''






												__UpperCAmelCase   :						List[str]      							=					do_resize if do_resize is not None else self.do_resize
												__UpperCAmelCase   :						Any      							=					size if size is not None else self.size
												__UpperCAmelCase   :						Any      							=					get_size_dict(UpperCamelCase  )
												__UpperCAmelCase   :						Optional[Any]      							=					resample if resample is not None else self.resample
												__UpperCAmelCase   :						Any      							=					do_normalize if do_normalize is not None else self.do_normalize
												__UpperCAmelCase   :						Any      							=					do_color_quantize if do_color_quantize is not None else self.do_color_quantize
												__UpperCAmelCase   :						Tuple      							=					clusters if clusters is not None else self.clusters
												__UpperCAmelCase   :						Tuple      							=					np.array(UpperCamelCase  )

												__UpperCAmelCase   :						int      							=					make_list_of_images(UpperCamelCase  )

												if not valid_images(UpperCamelCase  ):
																			raise ValueError(
																			    """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
																			    """torch.Tensor, tf.Tensor or jax.ndarray."""  )

												if do_resize and size is None or resample is None:
																			raise ValueError("""Size and resample must be specified if do_resize is True."""  )

												if do_color_quantize and clusters is None:
																			raise ValueError("""Clusters must be specified if do_color_quantize is True."""  )

												# All transformations expect numpy arrays.
												__UpperCAmelCase   :						Tuple      							=					[to_numpy_array(UpperCamelCase  ) for image in images]

												if do_resize:
																			__UpperCAmelCase   :						Dict      							=					[self.resize(image=UpperCamelCase ,       size=UpperCamelCase ,       resample=UpperCamelCase  ) for image in images]

												if do_normalize:
																			__UpperCAmelCase   :						Any      							=					[self.normalize(image=UpperCamelCase  ) for image in images]

												if do_color_quantize:
																			__UpperCAmelCase   :						str      							=					[to_channel_dimension_format(UpperCamelCase ,       ChannelDimension.LAST  ) for image in images]
																			# color quantize from (batch_size, height, width, 3) to (batch_size, height, width)
																			__UpperCAmelCase   :						Optional[int]      							=					np.array(UpperCamelCase  )
																			__UpperCAmelCase   :						Any      							=					color_quantize(UpperCamelCase ,       UpperCamelCase  ).reshape(images.shape[:-1]  )

																			# flatten to (batch_size, height*width)
																			__UpperCAmelCase   :						Dict      							=					images.shape[0]
																			__UpperCAmelCase   :						Optional[Any]      							=					images.reshape(UpperCamelCase ,       -1  )

																			# We need to convert back to a list of images to keep consistent behaviour across processors.
																			__UpperCAmelCase   :						int      							=					list(UpperCamelCase  )
												else:
																			__UpperCAmelCase   :						List[Any]      							=					[to_channel_dimension_format(UpperCamelCase ,       UpperCamelCase  ) for image in images]

												__UpperCAmelCase   :						List[str]      							=					{"""input_ids""": images}
												return BatchFeature(data=UpperCamelCase ,       tensor_type=UpperCamelCase  )
