


'''simple docstring'''

import unittest

from transformers import AutoTokenizer, FalconConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    FalconForCausalLM,
							    FalconForQuestionAnswering,
							    FalconForSequenceClassification,
							    FalconForTokenClassification,
							    FalconModel,
							)
class _lowerCamelCase	:



		'''simple docstring'''







		def __init__( self		:						Any  ,					_A		:						List[Any]  ,					_A		:						Tuple=3  ,					_A		:						Union[str, Any]=7  ,					_A		:						Union[str, Any]=True  ,					_A		:						Optional[int]=True  ,					_A		:						Dict=False  ,					_A		:						Optional[int]=True  ,					_A		:						Any=99  ,					_A		:						Optional[int]=32  ,					_A		:						Optional[Any]=5  ,					_A		:						str=4  ,					_A		:						Union[str, Any]=37  ,					_A		:						Dict="gelu"  ,					_A		:						Optional[Any]=0.1  ,					_A		:						Optional[Any]=0.1  ,					_A		:						Any=512  ,					_A		:						Union[str, Any]=16  ,					_A		:						str=2  ,					_A		:						Optional[Any]=0.02  ,					_A		:						str=3  ,					_A		:						List[Any]=4  ,					_A		:						List[Any]=None  ,					)  ->			List[Any]:
			__magic_name__	:   Dict					     =					parent
			__magic_name__	:   Optional[int]					     =					batch_size
			__magic_name__	:   int					     =					seq_length
			__magic_name__	:   Union[str, Any]					     =					is_training
			__magic_name__	:   Dict					     =					use_input_mask
			__magic_name__	:   Optional[Any]					     =					use_token_type_ids
			__magic_name__	:   Tuple					     =					use_labels
			__magic_name__	:   Any					     =					vocab_size
			__magic_name__	:   str					     =					hidden_size
			__magic_name__	:   Optional[Any]					     =					num_hidden_layers
			__magic_name__	:   Optional[Any]					     =					num_attention_heads
			__magic_name__	:   Optional[int]					     =					intermediate_size
			__magic_name__	:   str					     =					hidden_act
			__magic_name__	:   str					     =					hidden_dropout_prob
			__magic_name__	:   Optional[int]					     =					attention_probs_dropout_prob
			__magic_name__	:   Tuple					     =					max_position_embeddings
			__magic_name__	:   str					     =					type_vocab_size
			__magic_name__	:   Optional[int]					     =					type_sequence_label_size
			__magic_name__	:   List[str]					     =					initializer_range
			__magic_name__	:   Union[str, Any]					     =					num_labels
			__magic_name__	:   str					     =					num_choices
			__magic_name__	:   Optional[Any]					     =					scope







		def        __lowerCAmelCase		( self		:						Dict      )  ->			Optional[Any]:
			__magic_name__	:   Tuple					     =					ids_tensor([self.batch_size, self.seq_length]  ,					self.vocab_size      )

			__magic_name__	:   List[Any]					     =					None
			if self.use_input_mask:
				__magic_name__	:   Optional[int]					     =					random_attention_mask([self.batch_size, self.seq_length]      )

			__magic_name__	:   Union[str, Any]					     =					None

			__magic_name__	:   Optional[Any]					     =					None
			__magic_name__	:   str					     =					None
			__magic_name__	:   str					     =					None
			if self.use_labels:
				__magic_name__	:   List[Any]					     =					ids_tensor([self.batch_size]  ,					self.type_sequence_label_size      )
				__magic_name__	:   Optional[Any]					     =					ids_tensor([self.batch_size, self.seq_length]  ,					self.num_labels      )
				__magic_name__	:   Optional[Any]					     =					ids_tensor([self.batch_size]  ,					self.num_choices      )

			__magic_name__	:   List[str]					     =					self.get_config()

			return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels







		def        __lowerCAmelCase		( self		:						str      )  ->			Tuple:
			return FalconConfig(
			    vocab_size=self.vocab_size  ,					hidden_size=self.hidden_size  ,					num_hidden_layers=self.num_hidden_layers  ,					num_attention_heads=self.num_attention_heads  ,					intermediate_size=self.intermediate_size  ,					hidden_act=self.hidden_act  ,					hidden_dropout_prob=self.hidden_dropout_prob  ,					attention_probs_dropout_prob=self.attention_probs_dropout_prob  ,					max_position_embeddings=self.max_position_embeddings  ,					type_vocab_size=self.type_vocab_size  ,					is_decoder=_A  ,					initializer_range=self.initializer_range  ,					pad_token_id=1  ,					new_decoder_architecture=_A  ,					)







		def        __lowerCAmelCase		( self		:						str  ,					_A		:						Optional[Any]  ,					_A		:						int  ,					_A		:						Tuple  ,					_A		:						List[str]  ,					_A		:						Union[str, Any]  ,					_A		:						Optional[int]  ,					_A		:						Optional[Any]      )  ->			Dict:
			__magic_name__	:   Union[str, Any]					     =					FalconModel(config=_A      )
			model.to(_A      )
			model.eval()
			__magic_name__	:   Tuple					     =					model(_A  ,					attention_mask=_A      )
			__magic_name__	:   Union[str, Any]					     =					model(_A      )
			self.parent.assertEqual(result.last_hidden_state.shape  ,					(self.batch_size, self.seq_length, self.hidden_size)      )







		def        __lowerCAmelCase		( self		:						Tuple  ,					_A		:						Any  ,					_A		:						int  ,					_A		:						Optional[int]  ,					_A		:						List[str]  ,					_A		:						Union[str, Any]  ,					_A		:						Union[str, Any]  ,					_A		:						str  ,					_A		:						List[Any]  ,					_A		:						List[Any]  ,					)  ->			Optional[Any]:
			__magic_name__	:   Optional[Any]					     =					True
			__magic_name__	:   int					     =					FalconModel(_A      )
			model.to(_A      )
			model.eval()
			__magic_name__	:   List[Any]					     =					model(
			    _A  ,					attention_mask=_A  ,					encoder_hidden_states=_A  ,					encoder_attention_mask=_A  ,					)
			__magic_name__	:   int					     =					model(
			    _A  ,					attention_mask=_A  ,					encoder_hidden_states=_A  ,					)
			__magic_name__	:   int					     =					model(_A  ,					attention_mask=_A      )
			self.parent.assertEqual(result.last_hidden_state.shape  ,					(self.batch_size, self.seq_length, self.hidden_size)      )







		def        __lowerCAmelCase		( self		:						Dict  ,					_A		:						List[str]  ,					_A		:						str  ,					_A		:						Tuple  ,					_A		:						Optional[int]  ,					_A		:						Tuple  ,					_A		:						List[Any]  ,					_A		:						Union[str, Any]  ,					_A		:						List[Any]  ,					_A		:						List[str]  ,					)  ->			Tuple:
			__magic_name__	:   int					     =					FalconForCausalLM(config=_A      )
			model.to(_A      )
			model.eval()
			__magic_name__	:   Any					     =					model(_A  ,					attention_mask=_A  ,					labels=_A      )
			self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.seq_length, self.vocab_size)      )







		def        __lowerCAmelCase		( self		:						Optional[int]  ,					_A		:						Dict  ,					_A		:						Optional[int]  ,					_A		:						Union[str, Any]  ,					_A		:						List[str]  ,					_A		:						Any  ,					_A		:						Optional[Any]  ,					_A		:						Union[str, Any]  ,					_A		:						Optional[Any]  ,					_A		:						Optional[Any]  ,					)  ->			Union[str, Any]:
			__magic_name__	:   Optional[int]					     =					True
			__magic_name__	:   List[str]					     =					True
			__magic_name__	:   str					     =					FalconForCausalLM(config=_A      )
			model.to(_A      )
			model.eval()

			# first forward pass
			__magic_name__	:   int					     =					model(
			    _A  ,					attention_mask=_A  ,					encoder_hidden_states=_A  ,					encoder_attention_mask=_A  ,					use_cache=_A  ,					)
			__magic_name__	:   Union[str, Any]					     =					outputs.past_key_values

			# create hypothetical multiple next token and extent to next_input_ids
			__magic_name__	:   Optional[int]					     =					ids_tensor((self.batch_size, 3)  ,					config.vocab_size      )
			__magic_name__	:   List[str]					     =					ids_tensor((self.batch_size, 3)  ,					vocab_size=2      )

			# append to next input_ids and
			__magic_name__	:   Any					     =					torch.cat([input_ids, next_tokens]  ,					dim=-1      )
			__magic_name__	:   Any					     =					torch.cat([input_mask, next_mask]  ,					dim=-1      )

			__magic_name__	:   Tuple					     =					model(
			    _A  ,					attention_mask=_A  ,					encoder_hidden_states=_A  ,					encoder_attention_mask=_A  ,					output_hidden_states=_A  ,					)['hidden_states'][0]
			__magic_name__	:   Tuple					     =					model(
			    _A  ,					attention_mask=_A  ,					encoder_hidden_states=_A  ,					encoder_attention_mask=_A  ,					past_key_values=_A  ,					output_hidden_states=_A  ,					)['hidden_states'][0]

			# select random slice
			__magic_name__	:   List[str]					     =					ids_tensor((1,)  ,					output_from_past.shape[-1]      ).item()
			__magic_name__	:   List[str]					     =					output_from_no_past[:, -3:, random_slice_idx].detach()
			__magic_name__	:   Tuple					     =					output_from_past[:, :, random_slice_idx].detach()

			self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]      )

			# test that outputs are equal for slice
			self.parent.assertTrue(torch.allclose(_A  ,					_A  ,					atol=1E-3      )      )







		def        __lowerCAmelCase		( self		:						List[str]      )  ->			Union[str, Any]:
			__magic_name__	:   List[str]					     =					self.prepare_config_and_inputs()
			(
			    (
			    __magic_name__
			)     ,    (
			    __magic_name__
			)     ,    (
			    __magic_name__
			)     ,    (
			    __magic_name__
			)     ,    (
			    __magic_name__
			)     ,    (
			    __magic_name__
			)     ,    (
			    __magic_name__
			)     ,    
			)	:   Dict					     =					config_and_inputs
			__magic_name__	:   str					     =					{'input_ids': input_ids, 'attention_mask': input_mask}
			return config, inputs_dict







@require_torch
class _lowerCamelCase	(						lowercase__		,					lowercase__		,					lowercase__		,					unittest.TestCase							):



		'''simple docstring'''







		A_     :      List[Any]				   =    (
		    (
		        FalconModel,
		        FalconForCausalLM,
		        FalconForSequenceClassification,
		        FalconForTokenClassification,
		        FalconForQuestionAnswering,
		    )
		    if is_torch_available()
		    else ()
		)
		A_     :      List[str]				   =    (FalconForCausalLM,) if is_torch_available() else ()
		A_     :      Tuple				   =    (
		    {
		        """feature-extraction""": FalconModel,
		        """text-classification""": FalconForSequenceClassification,
		        """text-generation""": FalconForCausalLM,
		        """question-answering""": FalconForQuestionAnswering,
		        """token-classification""": FalconForTokenClassification,
		        """zero-shot""": FalconForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		A_     :      Optional[int]				   =    False
		A_     :      int				   =    False







		def        __lowerCAmelCase		( self		:						Any      )  ->			int:
			__magic_name__	:   int					     =					FalconModelTester(self      )
			__magic_name__	:   Optional[int]					     =					ConfigTester(self  ,					config_class=_A  ,					hidden_size=37      )







		def        __lowerCAmelCase		( self		:						int      )  ->			str:
			self.config_tester.run_common_tests()







		def        __lowerCAmelCase		( self		:						Optional[Any]      )  ->			List[str]:
			__magic_name__	:   List[Any]					     =					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*_A      )







		def        __lowerCAmelCase		( self		:						List[Any]      )  ->			Tuple:
			__magic_name__     ,    *__magic_name__	:   List[str]					     =					self.model_tester.prepare_config_and_inputs()
			for alibi in [True, False]:
				__magic_name__	:   Tuple					     =					alibi
				self.model_tester.create_and_check_model(_A  ,					*_A      )







		def        __lowerCAmelCase		( self		:						List[str]      )  ->			Union[str, Any]:
			__magic_name__     ,    __magic_name__	:   Optional[Any]					     =					self.model_tester.prepare_config_and_inputs_for_common()
			__magic_name__	:   List[str]					     =					3
			__magic_name__	:   Optional[Any]					     =					input_dict['input_ids']
			__magic_name__	:   Any					     =					input_ids.ne(1      ).to(_A      )
			__magic_name__	:   Tuple					     =					ids_tensor([self.model_tester.batch_size]  ,					self.model_tester.type_sequence_label_size      )
			__magic_name__	:   List[str]					     =					FalconForSequenceClassification(_A      )
			model.to(_A      )
			model.eval()
			__magic_name__	:   Tuple					     =					model(_A  ,					attention_mask=_A  ,					labels=_A      )
			self.assertEqual(result.logits.shape  ,					(self.model_tester.batch_size, self.model_tester.num_labels)      )







		def        __lowerCAmelCase		( self		:						Any      )  ->			List[str]:
			__magic_name__     ,    __magic_name__	:   Any					     =					self.model_tester.prepare_config_and_inputs_for_common()
			__magic_name__	:   List[Any]					     =					3
			__magic_name__	:   List[Any]					     =					'single_label_classification'
			__magic_name__	:   Union[str, Any]					     =					input_dict['input_ids']
			__magic_name__	:   Any					     =					input_ids.ne(1      ).to(_A      )
			__magic_name__	:   Optional[int]					     =					ids_tensor([self.model_tester.batch_size]  ,					self.model_tester.type_sequence_label_size      )
			__magic_name__	:   Any					     =					FalconForSequenceClassification(_A      )
			model.to(_A      )
			model.eval()
			__magic_name__	:   Dict					     =					model(_A  ,					attention_mask=_A  ,					labels=_A      )
			self.assertEqual(result.logits.shape  ,					(self.model_tester.batch_size, self.model_tester.num_labels)      )







		def        __lowerCAmelCase		( self		:						Tuple      )  ->			Tuple:
			__magic_name__     ,    __magic_name__	:   List[Any]					     =					self.model_tester.prepare_config_and_inputs_for_common()
			__magic_name__	:   Dict					     =					input_dict['input_ids']
			__magic_name__	:   int					     =					FalconForCausalLM(_A      )
			model.to(_A      )
			model.eval()
			__magic_name__	:   Tuple					     =					model(_A  ,					use_cache=_A      )
			__magic_name__	:   Optional[int]					     =					input_ids.shape[0]
			__magic_name__	:   Dict					     =					model._convert_to_rw_cache(result.past_key_values      )
			__magic_name__	:   Optional[int]					     =					model._convert_cache_to_standard_format(_A  ,					_A      )
			for layer in range(len(_A      )      ):
				for tensor_idx in range(2      ):
					self.assertTrue(rw_cache[layer][tensor_idx].ndim == 3      )
					self.assertTrue(result.past_key_values[layer][tensor_idx].ndim == 4      )
					self.assertTrue(
					    torch.all(result.past_key_values[layer][tensor_idx] == standard_cache[layer][tensor_idx]      )      )







		def        __lowerCAmelCase		( self		:						int      )  ->			Dict:
			__magic_name__     ,    __magic_name__	:   Dict					     =					self.model_tester.prepare_config_and_inputs_for_common()
			__magic_name__	:   str					     =					3
			__magic_name__	:   str					     =					'multi_label_classification'
			__magic_name__	:   Optional[int]					     =					input_dict['input_ids']
			__magic_name__	:   List[str]					     =					input_ids.ne(1      ).to(_A      )
			__magic_name__	:   Tuple					     =					ids_tensor(
			    [self.model_tester.batch_size, config.num_labels]  ,					self.model_tester.type_sequence_label_size      ).to(torch.float      )
			__magic_name__	:   int					     =					FalconForSequenceClassification(_A      )
			model.to(_A      )
			model.eval()
			__magic_name__	:   Tuple					     =					model(_A  ,					attention_mask=_A  ,					labels=_A      )
			self.assertEqual(result.logits.shape  ,					(self.model_tester.batch_size, self.model_tester.num_labels)      )







		def        __lowerCAmelCase		( self		:						List[str]      )  ->			Any:
			# Falcon can have different numbers of KV-heads than the number of query heads, so we need
			# to override this test to use the right head counts.
			for model_class in self.all_generative_model_classes:
				__magic_name__     ,    __magic_name__	:   Any					     =					self.model_tester.prepare_config_and_inputs_for_common()

				# If it doesn't support cache, pass the test
				if not hasattr(_A  ,					'use_cache'      ):
					return

				__magic_name__	:   Optional[Any]					     =					model_class(_A      ).to(_A      )
				if "use_cache" not in inputs:
					__magic_name__	:   Union[str, Any]					     =					True
				__magic_name__	:   Optional[Any]					     =					model(**_A      )

				# If "past_key_values" is not returned, pass the test (e.g. RWKV uses a different cache name and format)
				if "past_key_values" not in outputs:
					return

				__magic_name__	:   Tuple					     =					(
				    getattr(_A  ,					'decoder_layers'  ,					_A      )
				    or getattr(_A  ,					'num_decoder_layers'  ,					_A      )
				    or config.num_hidden_layers
				)
				__magic_name__	:   Any					     =					getattr(_A  ,					'num_kv_heads'  ,					config.num_attention_heads      )
				__magic_name__	:   Any					     =					getattr(_A  ,					'd_model'  ,					config.hidden_size      )
				__magic_name__	:   List[str]					     =					embed_dim // num_attention_heads

				__magic_name__	:   Dict					     =					outputs['past_key_values']
				self.assertEqual(len(_A      )  ,					_A      )

				__magic_name__     ,    __magic_name__	:   List[Any]					     =					inputs['input_ids'].shape
				for i in range(_A      ):
					if config.new_decoder_architecture:
						__magic_name__	:   Tuple					     =					config.num_attention_heads
					elif config.multi_query:
						__magic_name__	:   Tuple					     =					1
					self.assertEqual(len(past_kv[0]      )  ,					2      )  # K V for the decoder = 2
					self.assertEqual(
					    past_kv[i][0].shape  ,					(batch_size, num_attention_heads, seq_length, per_head_embed_dim)      )
					self.assertEqual(
					    past_kv[i][1].shape  ,					(batch_size, num_attention_heads, seq_length, per_head_embed_dim)      )







@require_torch
class _lowerCamelCase	(						unittest.TestCase							):



		'''simple docstring'''







		@slow
		def        __lowerCAmelCase		( self		:						str      )  ->			Dict:
			__magic_name__	:   List[Any]					     =					AutoTokenizer.from_pretrained('Rocketknight1/falcon-rw-1b'      )
			__magic_name__	:   Dict					     =					FalconForCausalLM.from_pretrained('Rocketknight1/falcon-rw-1b'      )
			model.eval()
			model.to(_A      )
			__magic_name__	:   int					     =					tokenizer('My favorite food is'  ,					return_tensors='pt'      ).to(_A      )

			__magic_name__	:   Union[str, Any]					     =					(
			    'My favorite food is pizza. I love it so much that I have a pizza party every year for my birthday.'
			)

			__magic_name__	:   Dict					     =					model.generate(**_A  ,					do_sample=_A  ,					max_new_tokens=19      )
			__magic_name__	:   str					     =					tokenizer.batch_decode(_A      )[0]

			self.assertEqual(_A  ,					_A      )







		@slow
		def        __lowerCAmelCase		( self		:						str      )  ->			Optional[int]:
			# The big models are way too big for the CI, so we use tiny random models that resemble their
			# architectures but with much smaller and fewer layers
			for repo in ["Rocketknight1/tiny-random-falcon-7b", "Rocketknight1/tiny-random-falcon-40b"]:
				__magic_name__	:   List[str]					     =					AutoTokenizer.from_pretrained(_A      )
				__magic_name__	:   Union[str, Any]					     =					FalconForCausalLM.from_pretrained(_A      )
				model.eval()
				model.to(_A      )
				__magic_name__	:   List[str]					     =					tokenizer('My favorite food is'  ,					return_tensors='pt'      ).to(_A      )

				# We just test that these run without errors - the models are randomly initialized
				# and so the actual text outputs will be garbage
				model.generate(**_A  ,					do_sample=_A  ,					max_new_tokens=4      )
				model.generate(**_A  ,					do_sample=_A  ,					max_new_tokens=4      )
				model.generate(**_A  ,					num_beams=2  ,					max_new_tokens=4      )







		@slow
		def        __lowerCAmelCase		( self		:						Optional[Any]      )  ->			Any:
			# The big models are way too big for the CI, so we use tiny random models that resemble their
			# architectures but with much smaller and fewer layers
			with torch.no_grad():
				for repo in [
				    "Rocketknight1/falcon-rw-1b",
				    "Rocketknight1/tiny-random-falcon-7b",
				    "Rocketknight1/tiny-random-falcon-40b",
				]:
					__magic_name__	:   List[Any]					     =					AutoTokenizer.from_pretrained(_A      )
					__magic_name__	:   Tuple					     =					FalconForCausalLM.from_pretrained(_A      )
					model.eval()
					model.to(device=_A      )
					__magic_name__	:   Dict					     =					tokenizer('My favorite food is'  ,					return_tensors='pt'      ).to(_A      )

					# Test results are the same with and without cache
					__magic_name__	:   Dict					     =					model.generate(**_A  ,					do_sample=_A  ,					max_new_tokens=20  ,					use_cache=_A      )
					__magic_name__	:   Tuple					     =					model.generate(**_A  ,					do_sample=_A  ,					max_new_tokens=20  ,					use_cache=_A      )
					self.assertTrue((outputs_cache - outputs_no_cache).sum().item() == 0      )



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


lowerCAmelCase				:Tuple        =      logging.get_logger(__name__)
class _lowerCamelCase	(						lowercase__							):



		'''simple docstring'''







		A_     :      int				   =    ["""pixel_values"""]







		def __init__( self		:						Any  ,					_A		:						bool = True  ,					_A		:						Optional[Dict[str, int]] = None  ,					_A		:						PILImageResampling = PILImageResampling.BILINEAR  ,					_A		:						bool = True  ,					_A		:						Dict[str, int] = None  ,					_A		:						bool = True  ,					_A		:						Union[int, float] = 1 / 255  ,					_A		:						bool = True  ,					_A		:						Optional[Union[float, List[float]]] = None  ,					_A		:						Optional[Union[float, List[float]]] = None  ,					**_A		:						Optional[Any]  ,					)  ->			None:
			super().__init__(**_A      )
			__magic_name__	:   List[str]					     =					size if size is not None else {'shortest_edge': 256}
			__magic_name__	:   str					     =					get_size_dict(_A  ,					default_to_square=_A      )
			__magic_name__	:   List[str]					     =					crop_size if crop_size is not None else {'height': 224, 'width': 224}
			__magic_name__	:   Optional[int]					     =					get_size_dict(_A      )
			__magic_name__	:   Union[str, Any]					     =					do_resize
			__magic_name__	:   List[Any]					     =					size
			__magic_name__	:   List[str]					     =					resample
			__magic_name__	:   Dict					     =					do_center_crop
			__magic_name__	:   List[str]					     =					crop_size
			__magic_name__	:   int					     =					do_rescale
			__magic_name__	:   Tuple					     =					rescale_factor
			__magic_name__	:   List[str]					     =					do_normalize
			__magic_name__	:   Union[str, Any]					     =					image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
			__magic_name__	:   Dict					     =					image_std if image_std is not None else IMAGENET_STANDARD_STD







		def        __lowerCAmelCase		( self		:						Optional[Any]  ,					_A		:						np.ndarray  ,					_A		:						Dict[str, int]  ,					_A		:						PILImageResampling = PILImageResampling.BICUBIC  ,					_A		:						Optional[Union[str, ChannelDimension]] = None  ,					**_A		:						List[str]  ,					)  ->			np.ndarray:
			__magic_name__	:   Optional[Any]					     =					get_size_dict(_A  ,					default_to_square=_A      )
			if "shortest_edge" not in size:
				raise ValueError(F'The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'      )
			__magic_name__	:   Dict					     =					get_resize_output_image_size(_A  ,					size=size['shortest_edge']  ,					default_to_square=_A      )
			return resize(_A  ,					size=_A  ,					resample=_A  ,					data_format=_A  ,					**_A      )







		def        __lowerCAmelCase		( self		:						Dict  ,					_A		:						np.ndarray  ,					_A		:						Dict[str, int]  ,					_A		:						Optional[Union[str, ChannelDimension]] = None  ,					**_A		:						Optional[int]  ,					)  ->			np.ndarray:
			__magic_name__	:   int					     =					get_size_dict(_A      )
			return center_crop(_A  ,					size=(size['height'], size['width'])  ,					data_format=_A  ,					**_A      )







		def        __lowerCAmelCase		( self		:						List[str]  ,					_A		:						np.ndarray  ,					_A		:						float  ,					_A		:						Optional[Union[str, ChannelDimension]] = None  ,					**_A		:						Tuple      )  ->			np.ndarray:
			return rescale(_A  ,					scale=_A  ,					data_format=_A  ,					**_A      )







		def        __lowerCAmelCase		( self		:						str  ,					_A		:						np.ndarray  ,					_A		:						Union[float, List[float]]  ,					_A		:						Union[float, List[float]]  ,					_A		:						Optional[Union[str, ChannelDimension]] = None  ,					**_A		:						int  ,					)  ->			np.ndarray:
			return normalize(_A  ,					mean=_A  ,					std=_A  ,					data_format=_A  ,					**_A      )







		def        __lowerCAmelCase		( self		:						List[str]  ,					_A		:						ImageInput  ,					_A		:						Optional[bool] = None  ,					_A		:						Dict[str, int] = None  ,					_A		:						PILImageResampling = None  ,					_A		:						bool = None  ,					_A		:						Dict[str, int] = None  ,					_A		:						Optional[bool] = None  ,					_A		:						Optional[float] = None  ,					_A		:						Optional[bool] = None  ,					_A		:						Optional[Union[float, List[float]]] = None  ,					_A		:						Optional[Union[float, List[float]]] = None  ,					_A		:						Optional[Union[str, TensorType]] = None  ,					_A		:						Union[str, ChannelDimension] = ChannelDimension.FIRST  ,					**_A		:						List[Any]  ,					)  ->			List[str]:
			__magic_name__	:   int					     =					do_resize if do_resize is not None else self.do_resize
			__magic_name__	:   Tuple					     =					size if size is not None else self.size
			__magic_name__	:   Optional[Any]					     =					get_size_dict(_A  ,					default_to_square=_A      )
			__magic_name__	:   Dict					     =					resample if resample is not None else self.resample
			__magic_name__	:   Optional[Any]					     =					do_center_crop if do_center_crop is not None else self.do_center_crop
			__magic_name__	:   Dict					     =					crop_size if crop_size is not None else self.crop_size
			__magic_name__	:   List[str]					     =					get_size_dict(_A      )
			__magic_name__	:   Union[str, Any]					     =					do_rescale if do_rescale is not None else self.do_rescale
			__magic_name__	:   str					     =					rescale_factor if rescale_factor is not None else self.rescale_factor
			__magic_name__	:   Any					     =					do_normalize if do_normalize is not None else self.do_normalize
			__magic_name__	:   Tuple					     =					image_mean if image_mean is not None else self.image_mean
			__magic_name__	:   Union[str, Any]					     =					image_std if image_std is not None else self.image_std

			__magic_name__	:   int					     =					make_list_of_images(_A      )

			if not valid_images(_A      ):
				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.'      )

			# All transformations expect numpy arrays.
			__magic_name__	:   List[Any]					     =					[to_numpy_array(_A      ) for image in images]

			if do_resize:
				__magic_name__	:   Union[str, Any]					     =					[self.resize(image=_A  ,					size=_A  ,					resample=_A      ) for image in images]

			if do_center_crop:
				__magic_name__	:   Union[str, Any]					     =					[self.center_crop(image=_A  ,					size=_A      ) for image in images]

			if do_rescale:
				__magic_name__	:   List[Any]					     =					[self.rescale(image=_A  ,					scale=_A      ) for image in images]

			if do_normalize:
				__magic_name__	:   Optional[Any]					     =					[self.normalize(image=_A  ,					mean=_A  ,					std=_A      ) for image in images]

			__magic_name__	:   Union[str, Any]					     =					[to_channel_dimension_format(_A  ,					_A      ) for image in images]

			__magic_name__	:   List[str]					     =					{'pixel_values': images}
			return BatchFeature(data=_A  ,					tensor_type=_A      )