






'''simple docstring'''



import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, 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 (
          MODEL_FOR_PRETRAINING_MAPPING,
          MobileBertForMaskedLM,
          MobileBertForMultipleChoice,
          MobileBertForNextSentencePrediction,
          MobileBertForPreTraining,
          MobileBertForQuestionAnswering,
          MobileBertForSequenceClassification,
          MobileBertForTokenClassification,
          MobileBertModel,
      )
class UpperCAmelCase_       :




      """simple docstring"""




      def __init__(			self      :		List[str]  ,   UpperCAmelCase      :		Any  ,   UpperCAmelCase      :		Dict=13  ,   UpperCAmelCase      :		Optional[int]=7  ,   UpperCAmelCase      :		str=True  ,   UpperCAmelCase      :		List[Any]=True  ,   UpperCAmelCase      :		Optional[int]=True  ,   UpperCAmelCase      :		Dict=True  ,   UpperCAmelCase      :		str=99  ,   UpperCAmelCase      :		Union[str, Any]=64  ,   UpperCAmelCase      :		List[str]=32  ,   UpperCAmelCase      :		List[str]=5  ,   UpperCAmelCase      :		Dict=4  ,   UpperCAmelCase      :		Any=37  ,   UpperCAmelCase      :		Union[str, Any]="gelu"  ,   UpperCAmelCase      :		Dict=0.1  ,   UpperCAmelCase      :		Tuple=0.1  ,   UpperCAmelCase      :		List[Any]=512  ,   UpperCAmelCase      :		List[str]=16  ,   UpperCAmelCase      :		Any=2  ,   UpperCAmelCase      :		Union[str, Any]=0.0_2  ,   UpperCAmelCase      :		str=3  ,   UpperCAmelCase      :		List[Any]=4  ,   UpperCAmelCase      :		int=None  ,   )	->	Dict:


       '''simple docstring'''

       lowercase       : Dict						=parent
       lowercase       : Optional[Any]						=batch_size
       lowercase       : Union[str, Any]						=seq_length
       lowercase       : Optional[int]						=is_training
       lowercase       : Optional[Any]						=use_input_mask
       lowercase       : int						=use_token_type_ids
       lowercase       : List[Any]						=use_labels
       lowercase       : List[Any]						=vocab_size
       lowercase       : Union[str, Any]						=hidden_size
       lowercase       : Dict						=embedding_size
       lowercase       : Optional[int]						=num_hidden_layers
       lowercase       : List[str]						=num_attention_heads
       lowercase       : List[str]						=intermediate_size
       lowercase       : List[Any]						=hidden_act
       lowercase       : List[str]						=hidden_dropout_prob
       lowercase       : Tuple						=attention_probs_dropout_prob
       lowercase       : str						=max_position_embeddings
       lowercase       : str						=type_vocab_size
       lowercase       : Tuple						=type_sequence_label_size
       lowercase       : str						=initializer_range
       lowercase       : Optional[Any]						=num_labels
       lowercase       : List[Any]						=num_choices
       lowercase       : List[str]						=scope






      def 					A__   (			self      :		Dict		)	->	Union[str, Any]:


       '''simple docstring'''

       lowercase       : Optional[Any]						=ids_tensor([self.batch_size, self.seq_length]  ,   self.vocab_size		)

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

       lowercase       : str						=None
       if self.use_token_type_ids:
        lowercase       : List[str]						=ids_tensor([self.batch_size, self.seq_length]  ,   self.type_vocab_size		)

       lowercase       : Tuple						=None
       lowercase       : Optional[int]						=None
       lowercase       : Union[str, Any]						=None
       if self.use_labels:
        lowercase       : str						=ids_tensor([self.batch_size]  ,   self.type_sequence_label_size		)
        lowercase       : Dict						=ids_tensor([self.batch_size, self.seq_length]  ,   self.num_labels		)
        lowercase       : List[Any]						=ids_tensor([self.batch_size]  ,   self.num_choices		)

       lowercase       : Optional[int]						=self.get_config()

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






      def 					A__   (			self      :		List[Any]		)	->	Any:


       '''simple docstring'''

       return MobileBertConfig(
           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  ,   embedding_size=self.embedding_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=UpperCAmelCase  ,   initializer_range=self.initializer_range  ,   )






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


       '''simple docstring'''

       lowercase       : int						=MobileBertModel(config=UpperCAmelCase		)
       model.to(UpperCAmelCase		)
       model.eval()
       lowercase       : List[Any]						=model(UpperCAmelCase  ,   attention_mask=UpperCAmelCase  ,   token_type_ids=UpperCAmelCase		)
       lowercase       : Optional[int]						=model(UpperCAmelCase  ,   token_type_ids=UpperCAmelCase		)
       lowercase       : List[str]						=model(UpperCAmelCase		)

       self.parent.assertEqual(result.last_hidden_state.shape  ,   (self.batch_size, self.seq_length, self.hidden_size)		)
       self.parent.assertEqual(result.pooler_output.shape  ,   (self.batch_size, self.hidden_size)		)






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


       '''simple docstring'''

       lowercase       : Optional[int]						=MobileBertForMaskedLM(config=UpperCAmelCase		)
       model.to(UpperCAmelCase		)
       model.eval()
       lowercase       : Tuple						=model(UpperCAmelCase  ,   attention_mask=UpperCAmelCase  ,   token_type_ids=UpperCAmelCase  ,   labels=UpperCAmelCase		)
       self.parent.assertEqual(result.logits.shape  ,   (self.batch_size, self.seq_length, self.vocab_size)		)






      def 					A__   (			self      :		Dict  ,   UpperCAmelCase      :		Tuple  ,   UpperCAmelCase      :		str  ,   UpperCAmelCase      :		Dict  ,   UpperCAmelCase      :		List[Any]  ,   UpperCAmelCase      :		List[Any]  ,   UpperCAmelCase      :		Optional[int]  ,   UpperCAmelCase      :		Tuple		)	->	int:


       '''simple docstring'''

       lowercase       : Dict						=MobileBertForNextSentencePrediction(config=UpperCAmelCase		)
       model.to(UpperCAmelCase		)
       model.eval()
       lowercase       : List[Any]						=model(
           UpperCAmelCase  ,   attention_mask=UpperCAmelCase  ,   token_type_ids=UpperCAmelCase  ,   labels=UpperCAmelCase  ,   )
       self.parent.assertEqual(result.logits.shape  ,   (self.batch_size, 2)		)






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


       '''simple docstring'''

       lowercase       : Dict						=MobileBertForPreTraining(config=UpperCAmelCase		)
       model.to(UpperCAmelCase		)
       model.eval()
       lowercase       : Dict						=model(
           UpperCAmelCase  ,   attention_mask=UpperCAmelCase  ,   token_type_ids=UpperCAmelCase  ,   labels=UpperCAmelCase  ,   next_sentence_label=UpperCAmelCase  ,   )
       self.parent.assertEqual(result.prediction_logits.shape  ,   (self.batch_size, self.seq_length, self.vocab_size)		)
       self.parent.assertEqual(result.seq_relationship_logits.shape  ,   (self.batch_size, 2)		)






      def 					A__   (			self      :		Union[str, Any]  ,   UpperCAmelCase      :		List[str]  ,   UpperCAmelCase      :		Dict  ,   UpperCAmelCase      :		Dict  ,   UpperCAmelCase      :		Dict  ,   UpperCAmelCase      :		Any  ,   UpperCAmelCase      :		List[Any]  ,   UpperCAmelCase      :		Union[str, Any]		)	->	List[Any]:


       '''simple docstring'''

       lowercase       : str						=MobileBertForQuestionAnswering(config=UpperCAmelCase		)
       model.to(UpperCAmelCase		)
       model.eval()
       lowercase       : Optional[int]						=model(
           UpperCAmelCase  ,   attention_mask=UpperCAmelCase  ,   token_type_ids=UpperCAmelCase  ,   start_positions=UpperCAmelCase  ,   end_positions=UpperCAmelCase  ,   )
       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      :		List[str]  ,   UpperCAmelCase      :		Optional[int]  ,   UpperCAmelCase      :		Optional[Any]  ,   UpperCAmelCase      :		Any  ,   UpperCAmelCase      :		Any  ,   UpperCAmelCase      :		Any  ,   UpperCAmelCase      :		str  ,   UpperCAmelCase      :		str		)	->	Tuple:


       '''simple docstring'''

       lowercase       : Optional[int]						=self.num_labels
       lowercase       : Tuple						=MobileBertForSequenceClassification(UpperCAmelCase		)
       model.to(UpperCAmelCase		)
       model.eval()
       lowercase       : Dict						=model(UpperCAmelCase  ,   attention_mask=UpperCAmelCase  ,   token_type_ids=UpperCAmelCase  ,   labels=UpperCAmelCase		)
       self.parent.assertEqual(result.logits.shape  ,   (self.batch_size, self.num_labels)		)






      def 					A__   (			self      :		Dict  ,   UpperCAmelCase      :		List[str]  ,   UpperCAmelCase      :		int  ,   UpperCAmelCase      :		Any  ,   UpperCAmelCase      :		List[Any]  ,   UpperCAmelCase      :		int  ,   UpperCAmelCase      :		Any  ,   UpperCAmelCase      :		Union[str, Any]		)	->	Union[str, Any]:


       '''simple docstring'''

       lowercase       : Tuple						=self.num_labels
       lowercase       : Dict						=MobileBertForTokenClassification(config=UpperCAmelCase		)
       model.to(UpperCAmelCase		)
       model.eval()
       lowercase       : List[Any]						=model(UpperCAmelCase  ,   attention_mask=UpperCAmelCase  ,   token_type_ids=UpperCAmelCase  ,   labels=UpperCAmelCase		)
       self.parent.assertEqual(result.logits.shape  ,   (self.batch_size, self.seq_length, self.num_labels)		)






      def 					A__   (			self      :		Union[str, Any]  ,   UpperCAmelCase      :		Optional[int]  ,   UpperCAmelCase      :		Optional[int]  ,   UpperCAmelCase      :		Tuple  ,   UpperCAmelCase      :		Optional[int]  ,   UpperCAmelCase      :		int  ,   UpperCAmelCase      :		Optional[Any]  ,   UpperCAmelCase      :		Any		)	->	Union[str, Any]:


       '''simple docstring'''

       lowercase       : List[str]						=self.num_choices
       lowercase       : Dict						=MobileBertForMultipleChoice(config=UpperCAmelCase		)
       model.to(UpperCAmelCase		)
       model.eval()
       lowercase       : Any						=input_ids.unsqueeze(1		).expand(-1  ,   self.num_choices  ,   -1		).contiguous()
       lowercase       : str						=token_type_ids.unsqueeze(1		).expand(-1  ,   self.num_choices  ,   -1		).contiguous()
       lowercase       : Tuple						=input_mask.unsqueeze(1		).expand(-1  ,   self.num_choices  ,   -1		).contiguous()
       lowercase       : Dict						=model(
           UpperCAmelCase  ,   attention_mask=UpperCAmelCase  ,   token_type_ids=UpperCAmelCase  ,   labels=UpperCAmelCase  ,   )
       self.parent.assertEqual(result.logits.shape  ,   (self.batch_size, self.num_choices)		)






      def 					A__   (			self      :		str		)	->	Any:


       '''simple docstring'''

       lowercase       : List[Any]						=self.prepare_config_and_inputs()
       (
           (
           lowercase
       )	,		(
           lowercase
       )	,		(
           lowercase
       )	,		(
           lowercase
       )	,		(
           lowercase
       )	,		(
           lowercase
       )	,		(
           lowercase
       )	,		
       )       : Optional[int]						=config_and_inputs
       lowercase       : Optional[Any]						={'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict





@require_torch
class UpperCAmelCase_       (     __A					,							__A					,							unittest.TestCase					):




      """simple docstring"""




      UpperCamelCase_             =      (
          (
              MobileBertModel,
              MobileBertForMaskedLM,
              MobileBertForMultipleChoice,
              MobileBertForNextSentencePrediction,
              MobileBertForPreTraining,
              MobileBertForQuestionAnswering,
              MobileBertForSequenceClassification,
              MobileBertForTokenClassification,
          )
          if is_torch_available()
          else ()
      )
      UpperCamelCase_             =      (
          {
              '''feature-extraction''': MobileBertModel,
              '''fill-mask''': MobileBertForMaskedLM,
              '''question-answering''': MobileBertForQuestionAnswering,
              '''text-classification''': MobileBertForSequenceClassification,
              '''token-classification''': MobileBertForTokenClassification,
              '''zero-shot''': MobileBertForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      UpperCamelCase_             =      True






      def 					A__   (			self      :		Tuple  ,   UpperCAmelCase      :		List[Any]  ,   UpperCAmelCase      :		str  ,   UpperCAmelCase      :		str=False		)	->	List[Any]:


       '''simple docstring'''

       lowercase       : Dict						=super()._prepare_for_class(UpperCAmelCase  ,   UpperCAmelCase  ,   return_labels=UpperCAmelCase		)

       if return_labels:
        if model_class in get_values(UpperCAmelCase		):
         lowercase       : Any						=torch.zeros(
             (self.model_tester.batch_size, self.model_tester.seq_length)  ,   dtype=torch.long  ,   device=UpperCAmelCase		)
         lowercase       : Optional[int]						=torch.zeros(
             self.model_tester.batch_size  ,   dtype=torch.long  ,   device=UpperCAmelCase		)
       return inputs_dict






      def 					A__   (			self      :		int		)	->	Dict:


       '''simple docstring'''

       lowercase       : List[Any]						=MobileBertModelTester(self		)
       lowercase       : Union[str, Any]						=ConfigTester(self  ,   config_class=UpperCAmelCase  ,   hidden_size=37		)






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


       '''simple docstring'''

       self.config_tester.run_common_tests()






      def 					A__   (			self      :		Tuple		)	->	List[str]:


       '''simple docstring'''

       lowercase       : Optional[Any]						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_model(*UpperCAmelCase		)






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


       '''simple docstring'''

       lowercase       : Tuple						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_masked_lm(*UpperCAmelCase		)






      def 					A__   (			self      :		Union[str, Any]		)	->	Tuple:


       '''simple docstring'''

       lowercase       : Optional[int]						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_multiple_choice(*UpperCAmelCase		)






      def 					A__   (			self      :		int		)	->	int:


       '''simple docstring'''

       lowercase       : List[Any]						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*UpperCAmelCase		)






      def 					A__   (			self      :		Any		)	->	Dict:


       '''simple docstring'''

       lowercase       : Optional[Any]						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_pretraining(*UpperCAmelCase		)






      def 					A__   (			self      :		Any		)	->	Any:


       '''simple docstring'''

       lowercase       : List[Any]						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_question_answering(*UpperCAmelCase		)






      def 					A__   (			self      :		Dict		)	->	Optional[Any]:


       '''simple docstring'''

       lowercase       : str						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_sequence_classification(*UpperCAmelCase		)






      def 					A__   (			self      :		Tuple		)	->	Union[str, Any]:


       '''simple docstring'''

       lowercase       : Any						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_token_classification(*UpperCAmelCase		)





def 				lowercase_					(     __A			:							Any      )							->   List[str]:



 """simple docstring"""




 return torch.tensor(
     __A       ,   dtype=torch.long       ,   device=__A       ,   )


SCREAMING_SNAKE_CASE							=						1E-3





@require_torch
@require_sentencepiece
@require_tokenizers
class UpperCAmelCase_       (     unittest.TestCase					):




      """simple docstring"""




      @slow
      def 					A__   (			self      :		Dict		)	->	Union[str, Any]:


       '''simple docstring'''

       lowercase       : Union[str, Any]						=MobileBertModel.from_pretrained('''google/mobilebert-uncased'''		).to(UpperCAmelCase		)
       lowercase       : Tuple						=_long_tensor([[101, 7110, 1005, 1056, 2023, 1_1333, 1_7413, 1029, 102]]		)
       with torch.no_grad():
        lowercase       : Union[str, Any]						=model(UpperCAmelCase		)[0]
       lowercase       : Optional[int]						=torch.Size((1, 9, 512)		)
       self.assertEqual(output.shape  ,   UpperCAmelCase		)
       lowercase       : Any						=torch.tensor(
           [
               [
                   [-2.4_736_526e07, 8.2_691_656e04, 1.6_521_838e05],
                   [-5.7_541_704e-01, 3.9_056_022e00, 4.4_011_507e00],
                   [2.6_047_359e00, 1.5_677_652e00, -1.7_324_188e-01],
               ]
           ]  ,   device=UpperCAmelCase  ,   )

       # MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
       # ~1 difference, it's therefore not a good idea to measure using addition.
       # Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
       # result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
       lowercase       : int						=torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE		)
       lowercase       : Union[str, Any]						=torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE		)

       self.assertTrue(lower_bound and upper_bound		)











'''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,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
      import PIL


SCREAMING_SNAKE_CASE							=						logging.get_logger(__name__)


def 				lowercase_					(     __A			:							Tuple      )							->   List[List[ImageInput]]:



 """simple docstring"""




 if isinstance(__A       ,   (list, tuple)      ) and isinstance(videos[0]       ,   (list, tuple)      ) and is_valid_image(videos[0][0]      ):
  return videos

 elif isinstance(__A       ,   (list, tuple)      ) and is_valid_image(videos[0]      ):
  return [videos]

 elif is_valid_image(__A      ):
  return [[videos]]

 raise ValueError(F'Could not make batched video from {videos}'      )





class UpperCAmelCase_       (     __A					):




      """simple docstring"""




      UpperCamelCase_             =      ['''pixel_values''']






      def __init__(			self      :		List[Any]  ,   UpperCAmelCase      :		bool = True  ,   UpperCAmelCase      :		Dict[str, int] = None  ,   UpperCAmelCase      :		PILImageResampling = PILImageResampling.BILINEAR  ,   UpperCAmelCase      :		bool = True  ,   UpperCAmelCase      :		Dict[str, int] = None  ,   UpperCAmelCase      :		bool = True  ,   UpperCAmelCase      :		Union[int, float] = 1 / 255  ,   UpperCAmelCase      :		bool = True  ,   UpperCAmelCase      :		Optional[Union[float, List[float]]] = None  ,   UpperCAmelCase      :		Optional[Union[float, List[float]]] = None  ,   **UpperCAmelCase      :		Tuple  ,   )	->	None:


       '''simple docstring'''

       super().__init__(**UpperCAmelCase		)
       lowercase       : Tuple						=size if size is not None else {'''shortest_edge''': 224}
       lowercase       : str						=get_size_dict(UpperCAmelCase  ,   default_to_square=UpperCAmelCase		)
       lowercase       : List[str]						=crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
       lowercase       : List[Any]						=get_size_dict(UpperCAmelCase  ,   param_name='''crop_size'''		)

       lowercase       : Tuple						=do_resize
       lowercase       : Any						=size
       lowercase       : Optional[Any]						=do_center_crop
       lowercase       : str						=crop_size
       lowercase       : Any						=resample
       lowercase       : List[Any]						=do_rescale
       lowercase       : Dict						=rescale_factor
       lowercase       : List[str]						=do_normalize
       lowercase       : Optional[int]						=image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
       lowercase       : List[Any]						=image_std if image_std is not None else IMAGENET_STANDARD_STD






      def 					A__   (			self      :		Dict  ,   UpperCAmelCase      :		np.ndarray  ,   UpperCAmelCase      :		Dict[str, int]  ,   UpperCAmelCase      :		PILImageResampling = PILImageResampling.BILINEAR  ,   UpperCAmelCase      :		Optional[Union[str, ChannelDimension]] = None  ,   **UpperCAmelCase      :		List[str]  ,   )	->	np.ndarray:


       '''simple docstring'''

       lowercase       : str						=get_size_dict(UpperCAmelCase  ,   default_to_square=UpperCAmelCase		)
       if "shortest_edge" in size:
        lowercase       : int						=get_resize_output_image_size(UpperCAmelCase  ,   size['''shortest_edge''']  ,   default_to_square=UpperCAmelCase		)
       elif "height" in size and "width" in size:
        lowercase       : str						=(size['''height'''], size['''width'''])
       else:
        raise ValueError(f'Size must have \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}'		)
       return resize(UpperCAmelCase  ,   size=UpperCAmelCase  ,   resample=UpperCAmelCase  ,   data_format=UpperCAmelCase  ,   **UpperCAmelCase		)






      def 					A__   (			self      :		Any  ,   UpperCAmelCase      :		np.ndarray  ,   UpperCAmelCase      :		Dict[str, int]  ,   UpperCAmelCase      :		Optional[Union[str, ChannelDimension]] = None  ,   **UpperCAmelCase      :		Optional[Any]  ,   )	->	np.ndarray:


       '''simple docstring'''

       lowercase       : List[str]						=get_size_dict(UpperCAmelCase		)
       if "height" not in size or "width" not in size:
        raise ValueError(f'Size must have \'height\' and \'width\' as keys. Got {size.keys()}'		)
       return center_crop(UpperCAmelCase  ,   size=(size['''height'''], size['''width'''])  ,   data_format=UpperCAmelCase  ,   **UpperCAmelCase		)






      def 					A__   (			self      :		int  ,   UpperCAmelCase      :		np.ndarray  ,   UpperCAmelCase      :		Union[int, float]  ,   UpperCAmelCase      :		Optional[Union[str, ChannelDimension]] = None  ,   **UpperCAmelCase      :		Tuple  ,   )	->	List[Any]:


       '''simple docstring'''

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






      def 					A__   (			self      :		Any  ,   UpperCAmelCase      :		np.ndarray  ,   UpperCAmelCase      :		Union[float, List[float]]  ,   UpperCAmelCase      :		Union[float, List[float]]  ,   UpperCAmelCase      :		Optional[Union[str, ChannelDimension]] = None  ,   **UpperCAmelCase      :		int  ,   )	->	np.ndarray:


       '''simple docstring'''

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






      def 					A__   (			self      :		int  ,   UpperCAmelCase      :		ImageInput  ,   UpperCAmelCase      :		bool = None  ,   UpperCAmelCase      :		Dict[str, int] = None  ,   UpperCAmelCase      :		PILImageResampling = None  ,   UpperCAmelCase      :		bool = None  ,   UpperCAmelCase      :		Dict[str, int] = None  ,   UpperCAmelCase      :		bool = None  ,   UpperCAmelCase      :		float = None  ,   UpperCAmelCase      :		bool = None  ,   UpperCAmelCase      :		Optional[Union[float, List[float]]] = None  ,   UpperCAmelCase      :		Optional[Union[float, List[float]]] = None  ,   UpperCAmelCase      :		Optional[ChannelDimension] = ChannelDimension.FIRST  ,   )	->	np.ndarray:


       '''simple docstring'''

       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_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(UpperCAmelCase		)

       if do_resize:
        lowercase       : Union[str, Any]						=self.resize(image=UpperCAmelCase  ,   size=UpperCAmelCase  ,   resample=UpperCAmelCase		)

       if do_center_crop:
        lowercase       : Optional[Any]						=self.center_crop(UpperCAmelCase  ,   size=UpperCAmelCase		)

       if do_rescale:
        lowercase       : Dict						=self.rescale(image=UpperCAmelCase  ,   scale=UpperCAmelCase		)

       if do_normalize:
        lowercase       : int						=self.normalize(image=UpperCAmelCase  ,   mean=UpperCAmelCase  ,   std=UpperCAmelCase		)

       lowercase       : Optional[Any]						=to_channel_dimension_format(UpperCAmelCase  ,   UpperCAmelCase		)
       return image






      def 					A__   (			self      :		List[str]  ,   UpperCAmelCase      :		ImageInput  ,   UpperCAmelCase      :		bool = None  ,   UpperCAmelCase      :		Dict[str, int] = None  ,   UpperCAmelCase      :		PILImageResampling = None  ,   UpperCAmelCase      :		bool = None  ,   UpperCAmelCase      :		Dict[str, int] = None  ,   UpperCAmelCase      :		bool = None  ,   UpperCAmelCase      :		float = None  ,   UpperCAmelCase      :		bool = None  ,   UpperCAmelCase      :		Optional[Union[float, List[float]]] = None  ,   UpperCAmelCase      :		Optional[Union[float, List[float]]] = None  ,   UpperCAmelCase      :		Optional[Union[str, TensorType]] = None  ,   UpperCAmelCase      :		ChannelDimension = ChannelDimension.FIRST  ,   **UpperCAmelCase      :		Optional[int]  ,   )	->	PIL.Image.Image:


       '''simple docstring'''

       lowercase       : Any						=do_resize if do_resize is not None else self.do_resize
       lowercase       : Union[str, Any]						=resample if resample is not None else self.resample
       lowercase       : Tuple						=do_center_crop if do_center_crop is not None else self.do_center_crop
       lowercase       : List[Any]						=do_rescale if do_rescale is not None else self.do_rescale
       lowercase       : str						=rescale_factor if rescale_factor is not None else self.rescale_factor
       lowercase       : List[str]						=do_normalize if do_normalize is not None else self.do_normalize
       lowercase       : List[str]						=image_mean if image_mean is not None else self.image_mean
       lowercase       : Optional[int]						=image_std if image_std is not None else self.image_std

       lowercase       : Optional[Any]						=size if size is not None else self.size
       lowercase       : Any						=get_size_dict(UpperCAmelCase  ,   default_to_square=UpperCAmelCase		)
       lowercase       : Union[str, Any]						=crop_size if crop_size is not None else self.crop_size
       lowercase       : Optional[int]						=get_size_dict(UpperCAmelCase  ,   param_name='''crop_size'''		)

       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.'''		)

       lowercase       : List[str]						=make_batched(UpperCAmelCase		)

       lowercase       : Union[str, Any]						=[
           [
               self._preprocess_image(
                   image=UpperCAmelCase  ,   do_resize=UpperCAmelCase  ,   size=UpperCAmelCase  ,   resample=UpperCAmelCase  ,   do_center_crop=UpperCAmelCase  ,   crop_size=UpperCAmelCase  ,   do_rescale=UpperCAmelCase  ,   rescale_factor=UpperCAmelCase  ,   do_normalize=UpperCAmelCase  ,   image_mean=UpperCAmelCase  ,   image_std=UpperCAmelCase  ,   data_format=UpperCAmelCase  ,   )
               for img in video
           ]
           for video in videos
       ]

       lowercase       : Dict						={'''pixel_values''': videos}
       return BatchFeature(data=UpperCAmelCase  ,   tensor_type=UpperCAmelCase		)



