


'''simple docstring'''



import os
import tempfile
import unittest

from transformers import FlaubertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

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 (
	    FlaubertForMultipleChoice,
	    FlaubertForQuestionAnswering,
	    FlaubertForQuestionAnsweringSimple,
	    FlaubertForSequenceClassification,
	    FlaubertForTokenClassification,
	    FlaubertModel,
	    FlaubertWithLMHeadModel,
	)
	from transformers.models.flaubert.modeling_flaubert import FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST






class 			UpperCamelCase__(  __snake_case			):




				def __init__(						self     :					Optional[int] ,       lowerCAmelCase     :					List[str] ,       lowerCAmelCase     :					List[Any]=13 ,       lowerCAmelCase     :					Any=7 ,       lowerCAmelCase     :					Optional[Any]=True ,       lowerCAmelCase     :					Union[str, Any]=True ,       lowerCAmelCase     :					Optional[Any]=True ,       lowerCAmelCase     :					Union[str, Any]=True ,       lowerCAmelCase     :					List[str]=True ,       lowerCAmelCase     :					List[str]=False ,       lowerCAmelCase     :					Optional[Any]=False ,       lowerCAmelCase     :					str=False ,       lowerCAmelCase     :					Tuple=2 ,       lowerCAmelCase     :					Tuple=99 ,       lowerCAmelCase     :					Union[str, Any]=0 ,       lowerCAmelCase     :					int=32 ,       lowerCAmelCase     :					List[str]=5 ,       lowerCAmelCase     :					List[Any]=4 ,       lowerCAmelCase     :					int=0.1 ,       lowerCAmelCase     :					Tuple=0.1 ,       lowerCAmelCase     :					Tuple=512 ,       lowerCAmelCase     :					str=12 ,       lowerCAmelCase     :					int=2 ,       lowerCAmelCase     :					str=0.02 ,       lowerCAmelCase     :					List[str]=3 ,       lowerCAmelCase     :					Dict=4 ,       lowerCAmelCase     :					Dict="last" ,       lowerCAmelCase     :					Dict=None ,       lowerCAmelCase     :					Optional[Any]=None ,       )->	int:

										"""simple docstring"""




										UpperCAmelCase								=      parent
										UpperCAmelCase								=      batch_size
										UpperCAmelCase								=      seq_length
										UpperCAmelCase								=      is_training
										UpperCAmelCase								=      use_input_lengths
										UpperCAmelCase								=      use_token_type_ids
										UpperCAmelCase								=      use_labels
										UpperCAmelCase								=      gelu_activation
										UpperCAmelCase								=      sinusoidal_embeddings
										UpperCAmelCase								=      causal
										UpperCAmelCase								=      asm
										UpperCAmelCase								=      n_langs
										UpperCAmelCase								=      vocab_size
										UpperCAmelCase								=      n_special
										UpperCAmelCase								=      hidden_size
										UpperCAmelCase								=      num_hidden_layers
										UpperCAmelCase								=      num_attention_heads
										UpperCAmelCase								=      hidden_dropout_prob
										UpperCAmelCase								=      attention_probs_dropout_prob
										UpperCAmelCase								=      max_position_embeddings
										UpperCAmelCase								=      type_vocab_size
										UpperCAmelCase								=      type_sequence_label_size
										UpperCAmelCase								=      initializer_range
										UpperCAmelCase								=      num_labels
										UpperCAmelCase								=      num_choices
										UpperCAmelCase								=      summary_type
										UpperCAmelCase								=      use_proj
										UpperCAmelCase								=      scope




				def 	a__(						self     :					int )->	int:

										"""simple docstring"""




										UpperCAmelCase								=      ids_tensor([self.batch_size, self.seq_length] ,       self.vocab_size )
										UpperCAmelCase								=      random_attention_mask([self.batch_size, self.seq_length] )

										UpperCAmelCase								=      None
										if self.use_input_lengths:
																UpperCAmelCase								=      (
																    ids_tensor([self.batch_size] ,       vocab_size=2 ) + self.seq_length - 2
																)  # small variation of seq_length

										UpperCAmelCase								=      None
										if self.use_token_type_ids:
																UpperCAmelCase								=      ids_tensor([self.batch_size, self.seq_length] ,       self.n_langs )

										UpperCAmelCase								=      None
										UpperCAmelCase								=      None
										UpperCAmelCase								=      None
										if self.use_labels:
																UpperCAmelCase								=      ids_tensor([self.batch_size] ,       self.type_sequence_label_size )
																UpperCAmelCase								=      ids_tensor([self.batch_size, self.seq_length] ,       self.num_labels )
																UpperCAmelCase								=      ids_tensor([self.batch_size] ,       2 ).float()
																UpperCAmelCase								=      ids_tensor([self.batch_size] ,       self.num_choices )

										UpperCAmelCase								=      self.get_config()

										return (
										    config,
										    input_ids,
										    token_type_ids,
										    input_lengths,
										    sequence_labels,
										    token_labels,
										    is_impossible_labels,
										    choice_labels,
										    input_mask,
										)




				def 	a__(						self     :					Optional[int] )->	List[Any]:

										"""simple docstring"""




										return FlaubertConfig(
										    vocab_size=self.vocab_size ,       n_special=self.n_special ,       emb_dim=self.hidden_size ,       n_layers=self.num_hidden_layers ,       n_heads=self.num_attention_heads ,       dropout=self.hidden_dropout_prob ,       attention_dropout=self.attention_probs_dropout_prob ,       gelu_activation=self.gelu_activation ,       sinusoidal_embeddings=self.sinusoidal_embeddings ,       asm=self.asm ,       causal=self.causal ,       n_langs=self.n_langs ,       max_position_embeddings=self.max_position_embeddings ,       initializer_range=self.initializer_range ,       summary_type=self.summary_type ,       use_proj=self.use_proj ,       )




				def 	a__(						self     :					Union[str, Any] ,       lowerCAmelCase     :					Tuple ,       lowerCAmelCase     :					Any ,       lowerCAmelCase     :					int ,       lowerCAmelCase     :					Tuple ,       lowerCAmelCase     :					List[Any] ,       lowerCAmelCase     :					Dict ,       lowerCAmelCase     :					str ,       lowerCAmelCase     :					Optional[Any] ,       lowerCAmelCase     :					int ,       )->	Any:

										"""simple docstring"""




										UpperCAmelCase								=      FlaubertModel(config=lowerCAmelCase )
										model.to(lowerCAmelCase )
										model.eval()
										UpperCAmelCase								=      model(lowerCAmelCase ,       lengths=lowerCAmelCase ,       langs=lowerCAmelCase )
										UpperCAmelCase								=      model(lowerCAmelCase ,       langs=lowerCAmelCase )
										UpperCAmelCase								=      model(lowerCAmelCase )
										self.parent.assertEqual(result.last_hidden_state.shape ,       (self.batch_size, self.seq_length, self.hidden_size) )




				def 	a__(						self     :					int ,       lowerCAmelCase     :					Tuple ,       lowerCAmelCase     :					Optional[Any] ,       lowerCAmelCase     :					List[Any] ,       lowerCAmelCase     :					int ,       lowerCAmelCase     :					Optional[int] ,       lowerCAmelCase     :					Optional[Any] ,       lowerCAmelCase     :					List[Any] ,       lowerCAmelCase     :					Any ,       lowerCAmelCase     :					Optional[Any] ,       )->	Tuple:

										"""simple docstring"""




										UpperCAmelCase								=      FlaubertWithLMHeadModel(lowerCAmelCase )
										model.to(lowerCAmelCase )
										model.eval()

										UpperCAmelCase								=      model(lowerCAmelCase ,       token_type_ids=lowerCAmelCase ,       labels=lowerCAmelCase )
										self.parent.assertEqual(result.loss.shape ,       () )
										self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.seq_length, self.vocab_size) )




				def 	a__(						self     :					Any ,       lowerCAmelCase     :					Any ,       lowerCAmelCase     :					Tuple ,       lowerCAmelCase     :					Any ,       lowerCAmelCase     :					Optional[Any] ,       lowerCAmelCase     :					Union[str, Any] ,       lowerCAmelCase     :					int ,       lowerCAmelCase     :					List[str] ,       lowerCAmelCase     :					str ,       lowerCAmelCase     :					Union[str, Any] ,       )->	Any:

										"""simple docstring"""




										UpperCAmelCase								=      FlaubertForQuestionAnsweringSimple(lowerCAmelCase )
										model.to(lowerCAmelCase )
										model.eval()

										UpperCAmelCase								=      model(lowerCAmelCase )

										UpperCAmelCase								=      model(lowerCAmelCase ,       start_positions=lowerCAmelCase ,       end_positions=lowerCAmelCase )
										self.parent.assertEqual(result.start_logits.shape ,       (self.batch_size, self.seq_length) )
										self.parent.assertEqual(result.end_logits.shape ,       (self.batch_size, self.seq_length) )




				def 	a__(						self     :					int ,       lowerCAmelCase     :					Tuple ,       lowerCAmelCase     :					str ,       lowerCAmelCase     :					Dict ,       lowerCAmelCase     :					List[Any] ,       lowerCAmelCase     :					List[str] ,       lowerCAmelCase     :					Optional[Any] ,       lowerCAmelCase     :					Tuple ,       lowerCAmelCase     :					Union[str, Any] ,       lowerCAmelCase     :					List[Any] ,       )->	Tuple:

										"""simple docstring"""




										UpperCAmelCase								=      FlaubertForQuestionAnswering(lowerCAmelCase )
										model.to(lowerCAmelCase )
										model.eval()

										UpperCAmelCase								=      model(lowerCAmelCase )

										UpperCAmelCase								=      model(
										    lowerCAmelCase ,       start_positions=lowerCAmelCase ,       end_positions=lowerCAmelCase ,       cls_index=lowerCAmelCase ,       is_impossible=lowerCAmelCase ,       p_mask=lowerCAmelCase ,       )

										UpperCAmelCase								=      model(
										    lowerCAmelCase ,       start_positions=lowerCAmelCase ,       end_positions=lowerCAmelCase ,       cls_index=lowerCAmelCase ,       is_impossible=lowerCAmelCase ,       )

										(UpperCAmelCase    )								=      result_with_labels.to_tuple()

										UpperCAmelCase								=      model(lowerCAmelCase ,       start_positions=lowerCAmelCase ,       end_positions=lowerCAmelCase )

										(UpperCAmelCase    )								=      result_with_labels.to_tuple()

										self.parent.assertEqual(result_with_labels.loss.shape ,       () )
										self.parent.assertEqual(result.start_top_log_probs.shape ,       (self.batch_size, model.config.start_n_top) )
										self.parent.assertEqual(result.start_top_index.shape ,       (self.batch_size, model.config.start_n_top) )
										self.parent.assertEqual(
										    result.end_top_log_probs.shape ,       (self.batch_size, model.config.start_n_top * model.config.end_n_top) )
										self.parent.assertEqual(
										    result.end_top_index.shape ,       (self.batch_size, model.config.start_n_top * model.config.end_n_top) )
										self.parent.assertEqual(result.cls_logits.shape ,       (self.batch_size,) )




				def 	a__(						self     :					Union[str, Any] ,       lowerCAmelCase     :					Union[str, Any] ,       lowerCAmelCase     :					Optional[int] ,       lowerCAmelCase     :					List[Any] ,       lowerCAmelCase     :					Dict ,       lowerCAmelCase     :					str ,       lowerCAmelCase     :					Dict ,       lowerCAmelCase     :					Optional[Any] ,       lowerCAmelCase     :					List[Any] ,       lowerCAmelCase     :					List[Any] ,       )->	Optional[Any]:

										"""simple docstring"""




										UpperCAmelCase								=      FlaubertForSequenceClassification(lowerCAmelCase )
										model.to(lowerCAmelCase )
										model.eval()

										UpperCAmelCase								=      model(lowerCAmelCase )
										UpperCAmelCase								=      model(lowerCAmelCase ,       labels=lowerCAmelCase )

										self.parent.assertEqual(result.loss.shape ,       () )
										self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.type_sequence_label_size) )




				def 	a__(						self     :					Dict ,       lowerCAmelCase     :					List[str] ,       lowerCAmelCase     :					str ,       lowerCAmelCase     :					List[Any] ,       lowerCAmelCase     :					Optional[int] ,       lowerCAmelCase     :					Optional[int] ,       lowerCAmelCase     :					List[str] ,       lowerCAmelCase     :					Union[str, Any] ,       lowerCAmelCase     :					str ,       lowerCAmelCase     :					Union[str, Any] ,       )->	Optional[int]:

										"""simple docstring"""




										UpperCAmelCase								=      self.num_labels
										UpperCAmelCase								=      FlaubertForTokenClassification(lowerCAmelCase )
										model.to(lowerCAmelCase )
										model.eval()

										UpperCAmelCase								=      model(lowerCAmelCase ,       attention_mask=lowerCAmelCase ,       labels=lowerCAmelCase )
										self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.seq_length, self.num_labels) )




				def 	a__(						self     :					Optional[int] ,       lowerCAmelCase     :					List[Any] ,       lowerCAmelCase     :					List[str] ,       lowerCAmelCase     :					Dict ,       lowerCAmelCase     :					str ,       lowerCAmelCase     :					Tuple ,       lowerCAmelCase     :					str ,       lowerCAmelCase     :					Union[str, Any] ,       lowerCAmelCase     :					Any ,       lowerCAmelCase     :					str ,       )->	str:

										"""simple docstring"""




										UpperCAmelCase								=      self.num_choices
										UpperCAmelCase								=      FlaubertForMultipleChoice(config=lowerCAmelCase )
										model.to(lowerCAmelCase )
										model.eval()
										UpperCAmelCase								=      input_ids.unsqueeze(1 ).expand(-1 ,       self.num_choices ,       -1 ).contiguous()
										UpperCAmelCase								=      token_type_ids.unsqueeze(1 ).expand(-1 ,       self.num_choices ,       -1 ).contiguous()
										UpperCAmelCase								=      input_mask.unsqueeze(1 ).expand(-1 ,       self.num_choices ,       -1 ).contiguous()
										UpperCAmelCase								=      model(
										    lowerCAmelCase ,       attention_mask=lowerCAmelCase ,       token_type_ids=lowerCAmelCase ,       labels=lowerCAmelCase ,       )
										self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.num_choices) )





				def 	a__(						self     :					str )->	List[Any]:

										"""simple docstring"""




										UpperCAmelCase								=      self.prepare_config_and_inputs()
										(
										    UpperCAmelCase    
										)								=      config_and_inputs
										UpperCAmelCase								=      {
										    "input_ids": input_ids,
										    "token_type_ids": token_type_ids,
										    "lengths": input_lengths,
										    "attention_mask": input_mask,
										}
										return config, inputs_dict







@require_torch
class 			UpperCamelCase__(  __snake_case		,							__snake_case		,							unittest.TestCase			):
				__magic_name__							: Tuple    						=			(
				    (
				        FlaubertModel,
				        FlaubertWithLMHeadModel,
				        FlaubertForQuestionAnswering,
				        FlaubertForQuestionAnsweringSimple,
				        FlaubertForSequenceClassification,
				        FlaubertForTokenClassification,
				        FlaubertForMultipleChoice,
				    )
				    if is_torch_available()
				    else ()
				)
				__magic_name__							: Any    						=			(
				    {
				        "feature-extraction": FlaubertModel,
				        "fill-mask": FlaubertWithLMHeadModel,
				        "question-answering": FlaubertForQuestionAnsweringSimple,
				        "text-classification": FlaubertForSequenceClassification,
				        "token-classification": FlaubertForTokenClassification,
				        "zero-shot": FlaubertForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)




				def 	a__(						self     :					Optional[int] ,       lowerCAmelCase     :					List[str] ,       lowerCAmelCase     :					str ,       lowerCAmelCase     :					Optional[int] ,       lowerCAmelCase     :					List[str] ,       lowerCAmelCase     :					Optional[Any] )->	Any:

										"""simple docstring"""




										if (
										    pipeline_test_casse_name == "QAPipelineTests"
										    and tokenizer_name is not None
										    and not tokenizer_name.endswith('''Fast''' )
										):
																# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
																# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
																# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
																return True

										return False




				def 	a__(						self     :					List[Any] ,       lowerCAmelCase     :					Any ,       lowerCAmelCase     :					List[Any] ,       lowerCAmelCase     :					Any=False )->	str:

										"""simple docstring"""




										UpperCAmelCase								=      super()._prepare_for_class(lowerCAmelCase ,       lowerCAmelCase ,       return_labels=lowerCAmelCase )

										if return_labels:
																if model_class.__name__ == "FlaubertForQuestionAnswering":
																						UpperCAmelCase								=      torch.zeros(
																						    self.model_tester.batch_size ,       dtype=torch.long ,       device=lowerCAmelCase )
																						UpperCAmelCase								=      torch.zeros(
																						    self.model_tester.batch_size ,       dtype=torch.long ,       device=lowerCAmelCase )

										return inputs_dict




				def 	a__(						self     :					Dict )->	Dict:

										"""simple docstring"""




										UpperCAmelCase								=      FlaubertModelTester(self )
										UpperCAmelCase								=      ConfigTester(self ,       config_class=lowerCAmelCase ,       emb_dim=37 )




				def 	a__(						self     :					Optional[Any] )->	Tuple:

										"""simple docstring"""




										self.config_tester.run_common_tests()




				def 	a__(						self     :					int )->	Tuple:

										"""simple docstring"""




										UpperCAmelCase								=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_flaubert_model(*lowerCAmelCase )




				def 	a__(						self     :					List[str] )->	str:

										"""simple docstring"""




										UpperCAmelCase								=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_flaubert_lm_head(*lowerCAmelCase )




				def 	a__(						self     :					Tuple )->	int:

										"""simple docstring"""




										UpperCAmelCase								=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_flaubert_simple_qa(*lowerCAmelCase )




				def 	a__(						self     :					int )->	Optional[int]:

										"""simple docstring"""




										UpperCAmelCase								=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_flaubert_qa(*lowerCAmelCase )




				def 	a__(						self     :					List[Any] )->	Optional[Any]:

										"""simple docstring"""




										UpperCAmelCase								=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_flaubert_sequence_classif(*lowerCAmelCase )




				def 	a__(						self     :					List[str] )->	Dict:

										"""simple docstring"""




										UpperCAmelCase								=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_flaubert_token_classif(*lowerCAmelCase )




				def 	a__(						self     :					int )->	List[str]:

										"""simple docstring"""




										UpperCAmelCase								=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_flaubert_multiple_choice(*lowerCAmelCase )




				@slow
				def 	a__(						self     :					List[str] )->	List[Any]:

										"""simple docstring"""




										for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																UpperCAmelCase								=      FlaubertModel.from_pretrained(lowerCAmelCase )
																self.assertIsNotNone(lowerCAmelCase )





				@slow
				@require_torch_gpu
				def 	a__(						self     :					Union[str, Any] )->	str:

										"""simple docstring"""




										UpperCAmelCase								=      self.model_tester.prepare_config_and_inputs_for_common()
										for model_class in self.all_model_classes:
																# FlauBertForMultipleChoice behaves incorrectly in JIT environments.
																if model_class == FlaubertForMultipleChoice:
																						return

																UpperCAmelCase								=      True
																UpperCAmelCase								=      model_class(config=lowerCAmelCase )

																UpperCAmelCase								=      self._prepare_for_class(lowerCAmelCase ,       lowerCAmelCase )
																UpperCAmelCase								=      torch.jit.trace(
																    lowerCAmelCase ,       (inputs_dict['''input_ids'''].to('''cpu''' ), inputs_dict['''attention_mask'''].to('''cpu''' )) )

																with tempfile.TemporaryDirectory() as tmp:
																						torch.jit.save(lowerCAmelCase ,       os.path.join(lowerCAmelCase ,       '''traced_model.pt''' ) )
																						UpperCAmelCase								=      torch.jit.load(os.path.join(lowerCAmelCase ,       '''traced_model.pt''' ) ,       map_location=lowerCAmelCase )
																						loaded(inputs_dict['''input_ids'''].to(lowerCAmelCase ) ,       inputs_dict['''attention_mask'''].to(lowerCAmelCase ) )







@require_torch
class 			UpperCamelCase__(  unittest.TestCase			):




				@slow
				def 	a__(						self     :					Union[str, Any] )->	Tuple:

										"""simple docstring"""




										UpperCAmelCase								=      FlaubertModel.from_pretrained('''flaubert/flaubert_base_cased''' )
										UpperCAmelCase								=      torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]] )
										with torch.no_grad():
																UpperCAmelCase								=      model(lowerCAmelCase )[0]
										UpperCAmelCase								=      torch.Size((1, 11, 768) )
										self.assertEqual(output.shape ,       lowerCAmelCase )
										UpperCAmelCase								=      torch.tensor(
										    [[[-2.6251, -1.4298, -0.0227], [-2.8510, -1.6387, 0.2258], [-2.8114, -1.1832, -0.3066]]] )

										self.assertTrue(torch.allclose(output[:, :3, :3] ,       lowerCAmelCase ,       atol=1E-4 ) )







from typing import Dict, Iterable, 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_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


UpperCamelCase_						:     Any	       =							logging.get_logger(__name__)




class   __lowercase						(						__snake_case       ):
	_A       =   ["pixel_values"]






	def __init__(self				: Dict      ,	snake_case				: bool = True      ,	snake_case				: Dict[str, int] = None      ,	snake_case				: PILImageResampling = PILImageResampling.BICUBIC      ,	snake_case				: bool = True      ,	snake_case				: Dict[str, int] = None      ,	snake_case				: bool = True      ,	snake_case				: Union[int, float] = 1 / 255      ,	snake_case				: bool = True      ,	snake_case				: Optional[Union[float, Iterable[float]]] = IMAGENET_DEFAULT_MEAN      ,	snake_case				: Optional[Union[float, Iterable[float]]] = IMAGENET_DEFAULT_STD      ,	**snake_case				: Optional[int]      ,	) ->			None:
							super().__init__(**snake_case    )
							_lowercase       :	str           =   size if size is not None else {"shortest_edge": 224}
							_lowercase       :	List[str]           =   get_size_dict(snake_case      ,	default_to_square=snake_case    )
							_lowercase       :	Optional[int]           =   crop_size if crop_size is not None else {"height": 224, "width": 224}
							_lowercase       :	List[Any]           =   get_size_dict(snake_case      ,	param_name="crop_size"    )

							_lowercase       :	Optional[int]           =   do_resize
							_lowercase       :	List[str]           =   size
							_lowercase       :	Tuple           =   resample
							_lowercase       :	Union[str, Any]           =   do_center_crop
							_lowercase       :	List[str]           =   crop_size
							_lowercase       :	Tuple           =   do_rescale
							_lowercase       :	Union[str, Any]           =   rescale_factor
							_lowercase       :	str           =   do_normalize
							_lowercase       :	List[Any]           =   image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
							_lowercase       :	List[Any]           =   image_std if image_std is not None else IMAGENET_DEFAULT_STD






	def       _a(self				: str      ,	snake_case				: np.ndarray      ,	snake_case				: Dict[str, int]      ,	snake_case				: PILImageResampling = PILImageResampling.BICUBIC      ,	snake_case				: Optional[Union[str, ChannelDimension]] = None      ,	**snake_case				: str      ,	) ->			np.ndarray:
							_lowercase       :	Tuple           =   get_size_dict(snake_case      ,	default_to_square=snake_case    )
							# size_dict is a dict with either keys "height" and "width" or "shortest_edge"
							if "shortest_edge" in size:
													_lowercase       :	List[str]           =   int((256 / 224) * size["shortest_edge"]    )
													_lowercase       :	Dict           =   get_resize_output_image_size(snake_case      ,	size=snake_case      ,	default_to_square=snake_case    )
													_lowercase       :	int           =   {"height": output_size[0], "width": output_size[1]}
							if "height" not in size_dict or "width" not in size_dict:
													raise ValueError(
													    F"""Size dict must have keys 'height' and 'width' or 'shortest_edge'. Got {size_dict.keys()}"""    )
							return resize(
							    snake_case      ,	size=(size_dict["height"], size_dict["width"])      ,	resample=snake_case      ,	data_format=snake_case      ,	**snake_case    )






	def       _a(self				: Any      ,	snake_case				: np.ndarray      ,	snake_case				: Dict[str, int]      ,	snake_case				: Optional[Union[str, ChannelDimension]] = None      ,	**snake_case				: Any      ,	) ->			np.ndarray:
							_lowercase       :	Tuple           =   get_size_dict(snake_case    )
							if "height" not in size or "width" not in size:
													raise ValueError(F"""Size dict must have keys 'height' and 'width'. Got {size.keys()}"""    )
							return center_crop(snake_case      ,	size=(size["height"], size["width"])      ,	data_format=snake_case      ,	**snake_case    )






	def       _a(self				: Dict      ,	snake_case				: np.ndarray      ,	snake_case				: Union[int, float]      ,	snake_case				: Optional[Union[str, ChannelDimension]] = None      ,	**snake_case				: List[str]      ,	) ->			np.ndarray:
							return rescale(snake_case      ,	scale=snake_case      ,	data_format=snake_case      ,	**snake_case    )






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






	def       _a(self				: Any      ,	snake_case				: ImageInput      ,	snake_case				: Optional[bool] = None      ,	snake_case				: Optional[Dict[str, int]] = None      ,	snake_case				: PILImageResampling = None      ,	snake_case				: Optional[bool] = None      ,	snake_case				: Optional[Dict[str, int]] = None      ,	snake_case				: Optional[bool] = None      ,	snake_case				: Optional[float] = None      ,	snake_case				: Optional[bool] = None      ,	snake_case				: Optional[Union[float, Iterable[float]]] = None      ,	snake_case				: Optional[Union[float, Iterable[float]]] = None      ,	snake_case				: Optional[TensorType] = None      ,	snake_case				: ChannelDimension = ChannelDimension.FIRST      ,	**snake_case				: Tuple      ,	) ->			BatchFeature:
							_lowercase       :	Optional[Any]           =   do_resize if do_resize is not None else self.do_resize
							_lowercase       :	Any           =   resample if resample is not None else self.resample
							_lowercase       :	Optional[Any]           =   do_center_crop if do_center_crop is not None else self.do_center_crop
							_lowercase       :	Union[str, Any]           =   do_rescale if do_rescale is not None else self.do_rescale
							_lowercase       :	Optional[Any]           =   rescale_factor if rescale_factor is not None else self.rescale_factor
							_lowercase       :	str           =   do_normalize if do_normalize is not None else self.do_normalize
							_lowercase       :	Dict           =   image_mean if image_mean is not None else self.image_mean
							_lowercase       :	Dict           =   image_std if image_std is not None else self.image_std

							_lowercase       :	Optional[int]           =   size if size is not None else self.size
							_lowercase       :	Dict           =   get_size_dict(snake_case      ,	default_to_square=snake_case    )
							_lowercase       :	Dict           =   crop_size if crop_size is not None else self.crop_size
							_lowercase       :	Optional[int]           =   get_size_dict(snake_case      ,	param_name="crop_size"    )

							_lowercase       :	Dict           =   make_list_of_images(snake_case    )

							if not valid_images(snake_case    ):
													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.
							_lowercase       :	Dict           =   [to_numpy_array(snake_case    ) for image in images]

							if do_resize:
													_lowercase       :	List[Any]           =   [self.resize(snake_case      ,	snake_case      ,	snake_case    ) for image in images]

							if do_center_crop:
													_lowercase       :	Union[str, Any]           =   [self.center_crop(snake_case      ,	snake_case    ) for image in images]

							if do_rescale:
													_lowercase       :	List[str]           =   [self.rescale(snake_case      ,	snake_case    ) for image in images]

							if do_normalize:
													_lowercase       :	str           =   [self.normalize(snake_case      ,	snake_case      ,	snake_case    ) for image in images]

							_lowercase       :	Any           =   [to_channel_dimension_format(snake_case      ,	snake_case    ) for image in images]

							_lowercase       :	str           =   {"pixel_values": images}
							return BatchFeature(data=snake_case      ,	tensor_type=snake_case    )




