


'''simple docstring'''
from __future__ import annotations

import os
import tempfile
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import is_tensorflow_text_available, is_tf_available
from transformers.testing_utils import require_tensorflow_text, require_tf, slow

from ..test_modeling_tf_common import floats_tensor
from .test_framework_agnostic import GenerationIntegrationTestsMixin


if is_tf_available():
	import tensorflow as tf

	from transformers import (
	    AutoTokenizer,
	    TFAutoModelForCausalLM,
	    TFAutoModelForSeqaSeqLM,
	    TFAutoModelForSpeechSeqaSeq,
	    TFAutoModelForVisionaSeq,
	    TFBartForConditionalGeneration,
	    TFLogitsProcessorList,
	    TFMinLengthLogitsProcessor,
	    tf_top_k_top_p_filtering,
	)

if is_tensorflow_text_available():
	import tensorflow_text as text
@require_tf
class      lowercase			(							unittest.TestCase      ):

		"""simple docstring"""

		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				tf.convert_to_tensor(
							    [
							        [
							            8.2220991,  # 3rd highest value; idx. 0
							            -0.5620044,
							            5.23229752,
							            4.0386393,
							            -6.8798378,
							            -0.54785802,
							            -3.2012153,
							            2.92777176,
							            1.88171953,
							            7.35341276,  # 5th highest value; idx. 9
							            8.43207833,  # 2nd highest value; idx. 10
							            -9.85711836,
							            -5.96209236,
							            -1.13039161,
							            -7.1115294,
							            -0.8369633,
							            -5.3186408,
							            7.06427407,
							            0.81369344,
							            -0.82023817,
							            -5.9179796,
							            0.58813443,
							            -6.99778438,
							            4.71551189,
							            -0.18771637,
							            7.44020759,  # 4th highest value; idx. 25
							            9.38450987,  # 1st highest value; idx. 26
							            2.12662941,
							            -9.32562038,
							            2.35652522,
							        ],  # cummulative prob of 5 highest values <= 0.6
							        [
							            0.58425518,
							            4.53139238,
							            -5.57510464,
							            -6.28030699,
							            -7.19529503,
							            -4.02122551,
							            1.39337037,
							            -6.06707057,
							            1.59480517,
							            -9.643119,
							            0.03907799,
							            0.67231762,
							            -8.88206726,
							            6.27115922,  # 4th highest value; idx. 13
							            2.28520723,
							            4.82767506,
							            4.30421368,
							            8.8275313,  # 2nd highest value; idx. 17
							            5.44029958,  # 5th highest value; idx. 18
							            -4.4735794,
							            7.38579536,  # 3rd highest value; idx. 20
							            -2.91051663,
							            2.61946077,
							            -2.5674762,
							            -9.48959302,
							            -4.02922645,
							            -1.35416918,
							            9.67702323,  # 1st highest value; idx. 27
							            -5.89478553,
							            1.85370467,
							        ],  # cummulative prob of 5 highest values <= 0.6
							    ]					,     dtype=tf.floataa					,     )

							UpperCamelCase__     :Union[str, Any]							      =				tf.convert_to_tensor(
							    [[0, 0], [0, 9], [0, 10], [0, 25], [0, 26], [1, 13], [1, 17], [1, 18], [1, 20], [1, 27]]					,     dtype=tf.intaa					,     )  # expected non filtered idx as noted above

							UpperCamelCase__     :List[Any]							      =				tf.convert_to_tensor(
							    [8.222099, 7.3534126, 8.432078, 7.4402075, 9.38451, 6.271159, 8.827531, 5.4402995, 7.3857956, 9.677023]					,     dtype=tf.floataa					,     )  # expected non filtered values as noted above

							UpperCamelCase__     :Dict							      =				tf_top_k_top_p_filtering(UpperCamelCase_					,     top_k=10					,     top_p=0.6					,     min_tokens_to_keep=4							)

							UpperCamelCase__     :Tuple							      =				output[output != -float('''inf'''							)]
							UpperCamelCase__     :int							      =				tf.cast(
							    tf.where(tf.not_equal(UpperCamelCase_					,     tf.constant(-float('''inf'''							)					,     dtype=tf.floataa							)							)							)					,     dtype=tf.intaa					,     )

							tf.debugging.assert_near(UpperCamelCase_					,     UpperCamelCase_					,     rtol=1e-12							)
							tf.debugging.assert_equal(UpperCamelCase_					,     UpperCamelCase_							)



@require_tf
class      lowercase			(							unittest.TestCase			,	A__      ):

		"""simple docstring"""

		if is_tf_available():
				_a									=       {
				    'AutoModelForCausalLM': TFAutoModelForCausalLM,
				    'AutoModelForSpeechSeq2Seq': TFAutoModelForSpeechSeqaSeq,
				    'AutoModelForSeq2SeqLM': TFAutoModelForSeqaSeqLM,
				    'AutoModelForVision2Seq': TFAutoModelForVisionaSeq,
				    'LogitsProcessorList': TFLogitsProcessorList,
				    'MinLengthLogitsProcessor': TFMinLengthLogitsProcessor,
				    'create_tensor_fn': tf.convert_to_tensor,
				    'floats_tensor': floats_tensor,
				    'return_tensors': 'tf',
				}




		@slow
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Dict							      =				TFAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''							)
							UpperCamelCase__     :Tuple							      =				2
							UpperCamelCase__     :int							      =				2
							class      lowercase			(							tf.Module      ):

									"""simple docstring"""

									def __init__(	self					,     UpperCamelCase_							):

														'''simple docstring'''


														super(UpperCamelCase_					,     self							).__init__()
														UpperCamelCase__     :Optional[int]							      =				model




									@tf.function(
									    input_signature=(
									        tf.TensorSpec((None, input_length)					,     tf.intaa					,     name='''input_ids'''							),
									        tf.TensorSpec((None, input_length)					,     tf.intaa					,     name='''attention_mask'''							),
									    )					,     jit_compile=UpperCamelCase_					,     )
									def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_							):

														'''simple docstring'''


														UpperCamelCase__     :Optional[int]							      =				self.model.generate(
														    input_ids=UpperCamelCase_					,     attention_mask=UpperCamelCase_					,     max_new_tokens=UpperCamelCase_					,     return_dict_in_generate=UpperCamelCase_					,     )
														return {"sequences": outputs["sequences"]}



							UpperCamelCase__     :Tuple							      =				[[2, 0], [102, 103]]
							UpperCamelCase__     :List[str]							      =				[[1, 0], [1, 1]]
							UpperCamelCase__     :Any							      =				DummyModel(model=UpperCamelCase_							)
							with tempfile.TemporaryDirectory() as tmp_dir:
												tf.saved_model.save(UpperCamelCase_					,     UpperCamelCase_					,     signatures={'''serving_default''': dummy_model.serving}							)
												UpperCamelCase__     :List[str]							      =				tf.saved_model.load(UpperCamelCase_							).signatures['''serving_default''']
												for batch_size in range(1					,     len(UpperCamelCase_							) + 1							):
																	UpperCamelCase__     :List[str]							      =				{
																	    '''input_ids''': tf.constant(dummy_input_ids[:batch_size]							),
																	    '''attention_mask''': tf.constant(dummy_attention_masks[:batch_size]							),
																	}
																	UpperCamelCase__     :Dict							      =				serving_func(**UpperCamelCase_							)['''sequences''']
																	UpperCamelCase__     :Any							      =				test_model.generate(**UpperCamelCase_					,     max_new_tokens=UpperCamelCase_							)
																	tf.debugging.assert_equal(UpperCamelCase_					,     UpperCamelCase_							)




		@slow
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[Any]							      =				TFAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''							)
							UpperCamelCase__     :Optional[int]							      =				1
							UpperCamelCase__     :int							      =				2
							class      lowercase			(							tf.Module      ):

									"""simple docstring"""

									def __init__(	self					,     UpperCamelCase_							):

														'''simple docstring'''


														super(UpperCamelCase_					,     self							).__init__()
														UpperCamelCase__     :Any							      =				model




									@tf.function(
									    input_signature=(
									        tf.TensorSpec((batch_size, None)					,     tf.intaa					,     name='''input_ids'''							),
									        tf.TensorSpec((batch_size, None)					,     tf.intaa					,     name='''attention_mask'''							),
									    )					,     jit_compile=UpperCamelCase_					,     )
									def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_							):

														'''simple docstring'''


														UpperCamelCase__     :Dict							      =				self.model.generate(
														    input_ids=UpperCamelCase_					,     attention_mask=UpperCamelCase_					,     max_new_tokens=UpperCamelCase_					,     return_dict_in_generate=UpperCamelCase_					,     )
														return {"sequences": outputs["sequences"]}



							UpperCamelCase__     :Optional[Any]							      =				[[2], [102, 103]]
							UpperCamelCase__     :str							      =				[[1], [1, 1]]
							UpperCamelCase__     :Union[str, Any]							      =				DummyModel(model=UpperCamelCase_							)
							with tempfile.TemporaryDirectory() as tmp_dir:
												tf.saved_model.save(UpperCamelCase_					,     UpperCamelCase_					,     signatures={'''serving_default''': dummy_model.serving}							)
												UpperCamelCase__     :List[str]							      =				tf.saved_model.load(UpperCamelCase_							).signatures['''serving_default''']
												for input_row in range(len(UpperCamelCase_							)							):
																	UpperCamelCase__     :Optional[Any]							      =				{
																	    '''input_ids''': tf.constant([dummy_input_ids[input_row]]							),
																	    '''attention_mask''': tf.constant([dummy_attention_masks[input_row]]							),
																	}
																	UpperCamelCase__     :Union[str, Any]							      =				serving_func(**UpperCamelCase_							)['''sequences''']
																	UpperCamelCase__     :Optional[int]							      =				test_model.generate(**UpperCamelCase_					,     max_new_tokens=UpperCamelCase_							)
																	tf.debugging.assert_equal(UpperCamelCase_					,     UpperCamelCase_							)




		@slow
		@require_tensorflow_text
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							with tempfile.TemporaryDirectory() as tmp_dir:
												# file needed to load the TF tokenizer
												hf_hub_download(repo_id='''google/flan-t5-small'''					,     filename='''spiece.model'''					,     local_dir=UpperCamelCase_							)
												class      lowercase			(							tf.keras.layers.Layer      ):

														"""simple docstring"""

														def __init__(	self							):

																			'''simple docstring'''


																			super().__init__()
																			UpperCamelCase__     :Dict							      =				text.SentencepieceTokenizer(
																			    model=tf.io.gfile.GFile(os.path.join(UpperCamelCase_					,     '''spiece.model'''							)					,     '''rb'''							).read()							)
																			UpperCamelCase__     :Dict							      =				TFAutoModelForSeqaSeqLM.from_pretrained('''hf-internal-testing/tiny-random-t5'''							)




														def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     *UpperCamelCase_					,     **UpperCamelCase_							):

																			'''simple docstring'''


																			UpperCamelCase__     :Tuple							      =				self.tokenizer.tokenize(UpperCamelCase_							)
																			UpperCamelCase__     :Tuple							      =				text.pad_model_inputs(
																			    UpperCamelCase_					,     max_seq_length=64					,     pad_value=self.model.config.pad_token_id							)
																			UpperCamelCase__     :Optional[int]							      =				self.model.generate(input_ids=UpperCamelCase_					,     attention_mask=UpperCamelCase_							)
																			return self.tokenizer.detokenize(UpperCamelCase_							)



												UpperCamelCase__     :Tuple							      =				CompleteSentenceTransformer()
												UpperCamelCase__     :Optional[Any]							      =				tf.keras.layers.Input(shape=(1,)					,     dtype=tf.string					,     name='''inputs'''							)
												UpperCamelCase__     :List[str]							      =				complete_model(UpperCamelCase_							)
												UpperCamelCase__     :Any							      =				tf.keras.Model(UpperCamelCase_					,     UpperCamelCase_							)
												keras_model.save(UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :int							      =				{
							    '''do_sample''': True,
							    '''num_beams''': 1,
							    '''top_p''': 0.7,
							    '''top_k''': 10,
							    '''temperature''': 0.7,
							}
							UpperCamelCase__     :Any							      =				14

							UpperCamelCase__     :str							      =				AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''							)
							UpperCamelCase__     :List[Any]							      =				'''Hello, my dog is cute and'''
							UpperCamelCase__     :Tuple							      =				tokenizer(UpperCamelCase_					,     return_tensors='''tf'''							)
							UpperCamelCase__     :Optional[int]							      =				TFAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''							)

							UpperCamelCase__     :str							      =				638
							# forces the generation to happen on CPU, to avoid GPU-related quirks
							with tf.device(''':/CPU:0'''							):
												tf.random.set_seed(0							)
												UpperCamelCase__     :Optional[int]							      =				model.generate(**UpperCamelCase_					,     eos_token_id=UpperCamelCase_					,     **UpperCamelCase_							)
							self.assertTrue(expectation == len(generated_tokens[0]							)							)

							UpperCamelCase__     :str							      =				[638, 198]
							with tf.device(''':/CPU:0'''							):
												tf.random.set_seed(0							)
												UpperCamelCase__     :Optional[Any]							      =				model.generate(**UpperCamelCase_					,     eos_token_id=UpperCamelCase_					,     **UpperCamelCase_							)
							self.assertTrue(expectation == len(generated_tokens[0]							)							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Tuple							      =				AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-random-bart'''							)
							UpperCamelCase__     :Any							      =				'''Hugging Face is a technology company based in New York and Paris.'''
							UpperCamelCase__     :str							      =				bart_tokenizer(UpperCamelCase_					,     return_tensors='''tf'''							).input_ids
							UpperCamelCase__     :Optional[Any]							      =				TFBartForConditionalGeneration.from_pretrained('''hf-internal-testing/tiny-random-bart'''							)
							UpperCamelCase__     :Optional[Any]							      =				bart_model.generate(UpperCamelCase_							).numpy()
							class      lowercase			(							A__      ):

									"""simple docstring"""

									def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_=None					,     **UpperCamelCase_							):

														'''simple docstring'''


														return super().call(UpperCamelCase_					,     **UpperCamelCase_							)



							UpperCamelCase__     :Union[str, Any]							      =				FakeBart.from_pretrained('''hf-internal-testing/tiny-random-bart'''							)
							UpperCamelCase__     :Union[str, Any]							      =				bart_model.generate(UpperCamelCase_					,     foo='''bar'''							).numpy()
							self.assertTrue(np.array_equal(UpperCamelCase_					,     UpperCamelCase_							)							)
							class      lowercase			(							bart_model.model.encoder.__class__      ):

									"""simple docstring"""

									def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     **UpperCamelCase_							):

														'''simple docstring'''


														return super().call(UpperCamelCase_					,     **UpperCamelCase_							)



							UpperCamelCase__     :Union[str, Any]							      =				FakeEncoder(bart_model.config					,     bart_model.model.shared							)
							UpperCamelCase__     :List[Any]							      =				fake_encoder

							# Normal generation still works (the output will be different because the encoder weights are different)
							UpperCamelCase__     :str							      =				bart_model.generate(UpperCamelCase_							).numpy()
							with self.assertRaises(UpperCamelCase_							):
												# FakeEncoder.call() accepts **kwargs -> no filtering -> value error due to unexpected input "foo"
												bart_model.generate(UpperCamelCase_					,     foo='''bar'''							)



'''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 (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


__snake_case							   =  logging.get_logger(__name__)


if is_vision_available():
		import PIL
class      lowercase			(							A__      ):

		"""simple docstring"""

		_a									=       ['pixel_values']




		def __init__(	self					,     UpperCamelCase_ = True					,     UpperCamelCase_ = None					,     UpperCamelCase_ = PILImageResampling.BICUBIC					,     UpperCamelCase_ = True					,     UpperCamelCase_ = None					,     UpperCamelCase_ = True					,     UpperCamelCase_ = 1 / 255					,     UpperCamelCase_ = True					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = True					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							super().__init__(**UpperCamelCase_							)
							UpperCamelCase__     :Tuple							      =				size if size is not None else {'''shortest_edge''': 224}
							UpperCamelCase__     :Optional[int]							      =				get_size_dict(UpperCamelCase_					,     default_to_square=UpperCamelCase_							)
							UpperCamelCase__     :str							      =				crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
							UpperCamelCase__     :Union[str, Any]							      =				get_size_dict(UpperCamelCase_					,     default_to_square=UpperCamelCase_					,     param_name='''crop_size'''							)

							UpperCamelCase__     :Any							      =				do_resize
							UpperCamelCase__     :Union[str, Any]							      =				size
							UpperCamelCase__     :Any							      =				resample
							UpperCamelCase__     :Optional[Any]							      =				do_center_crop
							UpperCamelCase__     :List[str]							      =				crop_size
							UpperCamelCase__     :Optional[int]							      =				do_rescale
							UpperCamelCase__     :Optional[Any]							      =				rescale_factor
							UpperCamelCase__     :Any							      =				do_normalize
							UpperCamelCase__     :int							      =				image_mean if image_mean is not None else OPENAI_CLIP_MEAN
							UpperCamelCase__     :List[str]							      =				image_std if image_std is not None else OPENAI_CLIP_STD
							UpperCamelCase__     :Union[str, Any]							      =				do_convert_rgb




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = PILImageResampling.BICUBIC					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							UpperCamelCase__     :Union[str, Any]							      =				get_size_dict(UpperCamelCase_					,     default_to_square=UpperCamelCase_							)
							if "shortest_edge" not in size:
												raise ValueError(F'''The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'''							)
							UpperCamelCase__     :str							      =				get_resize_output_image_size(UpperCamelCase_					,     size=size['''shortest_edge''']					,     default_to_square=UpperCamelCase_							)
							return resize(UpperCamelCase_					,     size=UpperCamelCase_					,     resample=UpperCamelCase_					,     data_format=UpperCamelCase_					,     **UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							UpperCamelCase__     :int							      =				get_size_dict(UpperCamelCase_							)
							if "height" not in size or "width" not in size:
												raise ValueError(F'''The `size` parameter must contain the keys (height, width). Got {size.keys()}'''							)
							return center_crop(UpperCamelCase_					,     size=(size['''height'''], size['''width'''])					,     data_format=UpperCamelCase_					,     **UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							return rescale(UpperCamelCase_					,     scale=UpperCamelCase_					,     data_format=UpperCamelCase_					,     **UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							return normalize(UpperCamelCase_					,     mean=UpperCamelCase_					,     std=UpperCamelCase_					,     data_format=UpperCamelCase_					,     **UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = ChannelDimension.FIRST					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							UpperCamelCase__     :Optional[int]							      =				do_resize if do_resize is not None else self.do_resize
							UpperCamelCase__     :Optional[Any]							      =				size if size is not None else self.size
							UpperCamelCase__     :Optional[int]							      =				get_size_dict(UpperCamelCase_					,     param_name='''size'''					,     default_to_square=UpperCamelCase_							)
							UpperCamelCase__     :Dict							      =				resample if resample is not None else self.resample
							UpperCamelCase__     :int							      =				do_center_crop if do_center_crop is not None else self.do_center_crop
							UpperCamelCase__     :Any							      =				crop_size if crop_size is not None else self.crop_size
							UpperCamelCase__     :Any							      =				get_size_dict(UpperCamelCase_					,     param_name='''crop_size'''					,     default_to_square=UpperCamelCase_							)
							UpperCamelCase__     :List[str]							      =				do_rescale if do_rescale is not None else self.do_rescale
							UpperCamelCase__     :List[Any]							      =				rescale_factor if rescale_factor is not None else self.rescale_factor
							UpperCamelCase__     :Optional[int]							      =				do_normalize if do_normalize is not None else self.do_normalize
							UpperCamelCase__     :Tuple							      =				image_mean if image_mean is not None else self.image_mean
							UpperCamelCase__     :str							      =				image_std if image_std is not None else self.image_std
							UpperCamelCase__     :Optional[Any]							      =				do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

							UpperCamelCase__     :str							      =				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:
												raise ValueError('''Size must be specified if do_resize 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_rescale and rescale_factor is None:
												raise ValueError('''Rescale factor must be specified if do_rescale is True.'''							)

							if do_normalize and (image_mean is None or image_std is None):
												raise ValueError('''Image mean and std must be specified if do_normalize is True.'''							)

							# PIL RGBA images are converted to RGB
							if do_convert_rgb:
												UpperCamelCase__     :Any							      =				[convert_to_rgb(UpperCamelCase_							) for image in images]

							# All transformations expect numpy arrays.
							UpperCamelCase__     :str							      =				[to_numpy_array(UpperCamelCase_							) for image in images]

							if do_resize:
												UpperCamelCase__     :Optional[Any]							      =				[self.resize(image=UpperCamelCase_					,     size=UpperCamelCase_					,     resample=UpperCamelCase_							) for image in images]

							if do_center_crop:
												UpperCamelCase__     :Dict							      =				[self.center_crop(image=UpperCamelCase_					,     size=UpperCamelCase_							) for image in images]

							if do_rescale:
												UpperCamelCase__     :Optional[Any]							      =				[self.rescale(image=UpperCamelCase_					,     scale=UpperCamelCase_							) for image in images]

							if do_normalize:
												UpperCamelCase__     :Tuple							      =				[self.normalize(image=UpperCamelCase_					,     mean=UpperCamelCase_					,     std=UpperCamelCase_							) for image in images]

							UpperCamelCase__     :List[str]							      =				[to_channel_dimension_format(UpperCamelCase_					,     UpperCamelCase_							) for image in images]

							UpperCamelCase__     :Optional[Any]							      =				{'''pixel_values''': images}
							return BatchFeature(data=UpperCamelCase_					,     tensor_type=UpperCamelCase_							)