
"""simple docstring"""




import inspect
import math
import tempfile
import unittest

import numpy as np

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

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch
    from torch import nn

    from transformers import ViTMAEForPreTraining, ViTMAEModel
    from transformers.models.vit.modeling_vit import VIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
    from PIL import Image

    from transformers import ViTImageProcessor







class   _lowercase						:


     '''simple docstring'''





     def __init__(      self ,			__UpperCamelCase ,			__UpperCamelCase=13 ,			__UpperCamelCase=30 ,			__UpperCamelCase=2 ,			__UpperCamelCase=3 ,			__UpperCamelCase=True ,			__UpperCamelCase=True ,			__UpperCamelCase=32 ,			__UpperCamelCase=5 ,			__UpperCamelCase=4 ,			__UpperCamelCase=37 ,			__UpperCamelCase="gelu" ,			__UpperCamelCase=0.1 ,			__UpperCamelCase=0.1 ,			__UpperCamelCase=10 ,			__UpperCamelCase=0.02 ,			__UpperCamelCase=3 ,			__UpperCamelCase=0.6 ,			__UpperCamelCase=None ,			)->					List[Any]:
          UpperCAmelCase__							: str 							=						parent
          UpperCAmelCase__							: Optional[Any] 							=						batch_size
          UpperCAmelCase__							: Any 							=						image_size
          UpperCAmelCase__							: Dict 							=						patch_size
          UpperCAmelCase__							: Optional[Any] 							=						num_channels
          UpperCAmelCase__							: Union[str, Any] 							=						is_training
          UpperCAmelCase__							: Any 							=						use_labels
          UpperCAmelCase__							: List[Any] 							=						hidden_size
          UpperCAmelCase__							: Dict 							=						num_hidden_layers
          UpperCAmelCase__							: List[str] 							=						num_attention_heads
          UpperCAmelCase__							: List[Any] 							=						intermediate_size
          UpperCAmelCase__							: Dict 							=						hidden_act
          UpperCAmelCase__							: List[Any] 							=						hidden_dropout_prob
          UpperCAmelCase__							: Optional[int] 							=						attention_probs_dropout_prob
          UpperCAmelCase__							: Optional[Any] 							=						type_sequence_label_size
          UpperCAmelCase__							: Union[str, Any] 							=						initializer_range
          UpperCAmelCase__							: int 							=						mask_ratio
          UpperCAmelCase__							: Tuple 							=						scope

          # in ViTMAE, the expected sequence length = (num_patches + 1) * (1 - config.mask_ratio), rounded above
          # (we add 1 for the [CLS] token)
          UpperCAmelCase__							: int 							=						(image_size // patch_size) ** 2
          UpperCAmelCase__							: str 							=						int(math.ceil((1 - mask_ratio) * (num_patches + 1)  )  )



     def  lowerCAmelCase__       (      self  )->					List[Any]:
          UpperCAmelCase__							: List[Any] 							=						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]  )

          UpperCAmelCase__							: Optional[Any] 							=						None
          if self.use_labels:
               UpperCAmelCase__							: Dict 							=						ids_tensor([self.batch_size] ,			self.type_sequence_label_size  )

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

          return config, pixel_values, labels



     def  lowerCAmelCase__       (      self  )->					int:
          return ViTMAEConfig(
              image_size=self.image_size ,			patch_size=self.patch_size ,			num_channels=self.num_channels ,			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 ,			is_decoder=__UpperCamelCase ,			initializer_range=self.initializer_range ,			mask_ratio=self.mask_ratio ,			)



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase ,			__UpperCamelCase  )->					Union[str, Any]:
          UpperCAmelCase__							: Optional[Any] 							=						ViTMAEModel(config=__UpperCamelCase  )
          model.to(__UpperCamelCase  )
          model.eval()
          UpperCAmelCase__							: List[str] 							=						model(__UpperCamelCase  )
          self.parent.assertEqual(result.last_hidden_state.shape ,			(self.batch_size, self.seq_length, self.hidden_size)  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase ,			__UpperCamelCase  )->					Optional[int]:
          UpperCAmelCase__							: List[Any] 							=						ViTMAEForPreTraining(__UpperCamelCase  )
          model.to(__UpperCamelCase  )
          model.eval()
          UpperCAmelCase__							: Optional[int] 							=						model(__UpperCamelCase  )
          UpperCAmelCase__							: List[str] 							=						(self.image_size // self.patch_size) ** 2
          UpperCAmelCase__							: List[str] 							=						self.patch_size**2 * self.num_channels
          self.parent.assertEqual(result.logits.shape ,			(self.batch_size, num_patches, expected_num_channels)  )

          # test greyscale images
          UpperCAmelCase__							: Dict 							=						1
          UpperCAmelCase__							: str 							=						ViTMAEForPreTraining(__UpperCamelCase  )
          model.to(__UpperCamelCase  )
          model.eval()
          UpperCAmelCase__							: int 							=						floats_tensor([self.batch_size, 1, self.image_size, self.image_size]  )
          UpperCAmelCase__							: List[str] 							=						model(__UpperCamelCase  )
          UpperCAmelCase__							: List[str] 							=						self.patch_size**2
          self.parent.assertEqual(result.logits.shape ,			(self.batch_size, num_patches, expected_num_channels)  )



     def  lowerCAmelCase__       (      self  )->					Dict:
          UpperCAmelCase__							: Tuple 							=						self.prepare_config_and_inputs()
          UpperCAmelCase__							,	UpperCAmelCase__							,	UpperCAmelCase__							: str 							=						config_and_inputs
          UpperCAmelCase__							: int 							=						{"pixel_values": pixel_values}
          return config, inputs_dict







@require_torch
class   _lowercase						(       lowerCAmelCase_	,   lowerCAmelCase_	,   unittest.TestCase				):


     '''simple docstring'''





     _A								=							(ViTMAEModel, ViTMAEForPreTraining) if is_torch_available() else ()
     _A								=							{'feature-extraction': ViTMAEModel} if is_torch_available() else {}

     _A								=							False
     _A								=							False
     _A								=							False
     _A								=							False



     def  lowerCAmelCase__       (      self  )->					List[Any]:
          UpperCAmelCase__							: Any 							=						ViTMAEModelTester(self  )
          UpperCAmelCase__							: List[str] 							=						ConfigTester(self ,			config_class=__UpperCamelCase ,			has_text_modality=__UpperCamelCase ,			hidden_size=37  )



     def  lowerCAmelCase__       (      self  )->					int:
          self.config_tester.run_common_tests()



     @unittest.skip(reason="ViTMAE does not use inputs_embeds"  )
     def  lowerCAmelCase__       (      self  )->					Dict:
          pass



     def  lowerCAmelCase__       (      self  )->					List[str]:
          UpperCAmelCase__							,	UpperCAmelCase__							: Tuple 							=						self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               UpperCAmelCase__							: int 							=						model_class(__UpperCamelCase  )
               self.assertIsInstance(model.get_input_embeddings() ,			(nn.Module)  )
               UpperCAmelCase__							: Tuple 							=						model.get_output_embeddings()
               self.assertTrue(x is None or isinstance(__UpperCamelCase ,			nn.Linear  )  )



     def  lowerCAmelCase__       (      self  )->					Optional[Any]:
          UpperCAmelCase__							,	UpperCAmelCase__							: int 							=						self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               UpperCAmelCase__							: List[str] 							=						model_class(__UpperCamelCase  )
               UpperCAmelCase__							: Dict 							=						inspect.signature(model.forward  )
               # signature.parameters is an OrderedDict => so arg_names order is deterministic
               UpperCAmelCase__							: Dict 							=						[*signature.parameters.keys()]

               UpperCAmelCase__							: Tuple 							=						["pixel_values"]
               self.assertListEqual(arg_names[:1] ,			__UpperCamelCase  )



     def  lowerCAmelCase__       (      self  )->					Any:
          UpperCAmelCase__							: int 							=						self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*__UpperCamelCase  )



     def  lowerCAmelCase__       (      self  )->					Dict:
          UpperCAmelCase__							: int 							=						self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_pretraining(*__UpperCamelCase  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase ,			__UpperCamelCase  )->					Dict:
          # make masks reproducible
          np.random.seed(2  )

          UpperCAmelCase__							: Tuple 							=						int((pt_model.config.image_size // pt_model.config.patch_size) ** 2  )
          UpperCAmelCase__							: Union[str, Any] 							=						np.random.uniform(size=(self.model_tester.batch_size, num_patches)  )
          UpperCAmelCase__							: str 							=						torch.from_numpy(__UpperCamelCase  )

          # Add `noise` argument.
          # PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
          UpperCAmelCase__							: Optional[Any] 							=						pt_noise

          super().check_pt_tf_models(__UpperCamelCase ,			__UpperCamelCase ,			__UpperCamelCase  )



     def  lowerCAmelCase__       (      self  )->					List[Any]:
          UpperCAmelCase__							,	UpperCAmelCase__							: Optional[int] 							=						self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               UpperCAmelCase__							: List[Any] 							=						model_class(__UpperCamelCase  )
               model.to(__UpperCamelCase  )
               model.eval()
               # make random mask reproducible
               torch.manual_seed(2  )
               with torch.no_grad():
                    UpperCAmelCase__							: Optional[int] 							=						model(**self._prepare_for_class(__UpperCamelCase ,			__UpperCamelCase  )  )

               UpperCAmelCase__							: Optional[Any] 							=						outputs[0].cpu().numpy()
               UpperCAmelCase__							: Union[str, Any] 							=						0

               with tempfile.TemporaryDirectory() as tmpdirname:
                    model.save_pretrained(__UpperCamelCase  )
                    UpperCAmelCase__							: Union[str, Any] 							=						model_class.from_pretrained(__UpperCamelCase  )
                    model.to(__UpperCamelCase  )
                    # make random mask reproducible
                    torch.manual_seed(2  )
                    with torch.no_grad():
                         UpperCAmelCase__							: List[Any] 							=						model(**self._prepare_for_class(__UpperCamelCase ,			__UpperCamelCase  )  )

                    # Make sure we don't have nans
                    UpperCAmelCase__							: Tuple 							=						after_outputs[0].cpu().numpy()
                    UpperCAmelCase__							: int 							=						0
                    UpperCAmelCase__							: str 							=						np.amax(np.abs(out_a - out_a  )  )
                    self.assertLessEqual(__UpperCamelCase ,			1E-5  )



     @unittest.skip(
         reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results."  )
     def  lowerCAmelCase__       (      self  )->					List[str]:
          pass



     @unittest.skip(
         reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results."  )
     def  lowerCAmelCase__       (      self  )->					Any:
          pass



     @unittest.skip(
         reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results."  )
     def  lowerCAmelCase__       (      self  )->					Optional[Any]:
          pass



     @unittest.skip(reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load"  )
     def  lowerCAmelCase__       (      self  )->					List[Any]:
          pass



     @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."  )
     def  lowerCAmelCase__       (      self  )->					Union[str, Any]:
          pass



     @slow
     def  lowerCAmelCase__       (      self  )->					Union[str, Any]:
          for model_name in VIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               UpperCAmelCase__							: Tuple 							=						ViTMAEModel.from_pretrained(__UpperCamelCase  )
               self.assertIsNotNone(__UpperCamelCase  )





def 							a__ (				):






     '''simple docstring'''
     UpperCAmelCase__							: Union[str, Any] 							=						Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
     return image







@require_torch
@require_vision
class   _lowercase						(       unittest.TestCase				):


     '''simple docstring'''





     @cached_property
     def  lowerCAmelCase__       (      self  )->					List[Any]:
          return ViTImageProcessor.from_pretrained("facebook/vit-mae-base"  ) if is_vision_available() else None



     @slow
     def  lowerCAmelCase__       (      self  )->					Optional[int]:
          # make random mask reproducible across the PT and TF model
          np.random.seed(2  )

          UpperCAmelCase__							: Any 							=						ViTMAEForPreTraining.from_pretrained("facebook/vit-mae-base"  ).to(__UpperCamelCase  )

          UpperCAmelCase__							: Tuple 							=						self.default_image_processor
          UpperCAmelCase__							: List[Any] 							=						prepare_img()
          UpperCAmelCase__							: Optional[Any] 							=						image_processor(images=__UpperCamelCase ,			return_tensors="pt"  ).to(__UpperCamelCase  )

          # prepare a noise vector that will be also used for testing the TF model
          # (this way we can ensure that the PT and TF models operate on the same inputs)
          UpperCAmelCase__							: List[Any] 							=						ViTMAEConfig()
          UpperCAmelCase__							: str 							=						int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2  )
          UpperCAmelCase__							: Optional[int] 							=						np.random.uniform(size=(1, num_patches)  )

          # forward pass
          with torch.no_grad():
               UpperCAmelCase__							: List[str] 							=						model(**__UpperCamelCase ,			noise=torch.from_numpy(__UpperCamelCase  ).to(device=__UpperCamelCase  )  )

          # verify the logits
          UpperCAmelCase__							: str 							=						torch.Size((1, 1_96, 7_68)  )
          self.assertEqual(outputs.logits.shape ,			__UpperCamelCase  )

          UpperCAmelCase__							: List[Any] 							=						torch.tensor(
              [[-0.0548, -1.7023, -0.9325], [0.3721, -0.5670, -0.2233], [0.8235, -1.3878, -0.3524]]  )

          self.assertTrue(torch.allclose(outputs.logits[0, :3, :3] ,			expected_slice.to(__UpperCamelCase  ) ,			atol=1E-4  )  )





"""simple docstring"""




from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

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 logging


if is_vision_available():
    import PIL

A__      :	Dict          =    logging.get_logger(__name__)



def 							a__ (				lowerCAmelCase	:       Optional[Any]		):






     '''simple docstring'''
     if isinstance(lowerCAmelCase       ,    (list, tuple)		) and isinstance(videos[0]       ,    (list, tuple)		) and is_valid_image(videos[0][0]		):
          return videos

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

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

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







class   _lowercase						(       lowerCAmelCase_				):


     '''simple docstring'''





     _A								=							['pixel_values']



     def __init__(      self ,			__UpperCamelCase = True ,			__UpperCamelCase = None ,			__UpperCamelCase = PILImageResampling.BILINEAR ,			__UpperCamelCase = True ,			__UpperCamelCase = None ,			__UpperCamelCase = True ,			__UpperCamelCase = 1 / 2_55 ,			__UpperCamelCase = True ,			__UpperCamelCase = True ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			**__UpperCamelCase ,			)->					None:
          super().__init__(**__UpperCamelCase  )
          UpperCAmelCase__							: Optional[Any] 							=						size if size is not None else {"shortest_edge": 2_56}
          UpperCAmelCase__							: List[Any] 							=						get_size_dict(__UpperCamelCase ,			default_to_square=__UpperCamelCase  )
          UpperCAmelCase__							: List[str] 							=						crop_size if crop_size is not None else {"height": 2_24, "width": 2_24}
          UpperCAmelCase__							: int 							=						get_size_dict(__UpperCamelCase ,			param_name="crop_size"  )

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



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase ,			__UpperCamelCase = PILImageResampling.BILINEAR ,			__UpperCamelCase = None ,			**__UpperCamelCase ,			)->					np.ndarray:
          UpperCAmelCase__							: Optional[int] 							=						get_size_dict(__UpperCamelCase ,			default_to_square=__UpperCamelCase  )
          if "shortest_edge" in size:
               UpperCAmelCase__							: Union[str, Any] 							=						get_resize_output_image_size(__UpperCamelCase ,			size["shortest_edge"] ,			default_to_square=__UpperCamelCase  )
          elif "height" in size and "width" in size:
               UpperCAmelCase__							: Any 							=						(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  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase ,			__UpperCamelCase = None ,			**__UpperCamelCase ,			)->					np.ndarray:
          UpperCAmelCase__							: Optional[Any] 							=						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  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase ,			__UpperCamelCase = True ,			__UpperCamelCase = None ,			**__UpperCamelCase ,			)->					Tuple:
          UpperCAmelCase__							: str 							=						image.astype(np.floataa  )
          if offset:
               UpperCAmelCase__							: Tuple 							=						image - (scale / 2)
          return rescale(__UpperCamelCase ,			scale=__UpperCamelCase ,			data_format=__UpperCamelCase ,			**__UpperCamelCase  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase ,			__UpperCamelCase ,			__UpperCamelCase = None ,			**__UpperCamelCase ,			)->					np.ndarray:
          return normalize(__UpperCamelCase ,			mean=__UpperCamelCase ,			std=__UpperCamelCase ,			data_format=__UpperCamelCase ,			**__UpperCamelCase  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = ChannelDimension.FIRST ,			)->					np.ndarray:
          if do_resize and size is None or resample is None:
               raise ValueError("Size and resample must be specified if do_resize is True."  )

          if do_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."  )

          if offset and not do_rescale:
               raise ValueError("For offset, do_rescale must also be set to True."  )

          # All transformations expect numpy arrays.
          UpperCAmelCase__							: Optional[Any] 							=						to_numpy_array(__UpperCamelCase  )

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

          if do_center_crop:
               UpperCAmelCase__							: int 							=						self.center_crop(__UpperCamelCase ,			size=__UpperCamelCase  )

          if do_rescale:
               UpperCAmelCase__							: List[str] 							=						self.rescale(image=__UpperCamelCase ,			scale=__UpperCamelCase ,			offset=__UpperCamelCase  )

          if do_normalize:
               UpperCAmelCase__							: List[Any] 							=						self.normalize(image=__UpperCamelCase ,			mean=__UpperCamelCase ,			std=__UpperCamelCase  )

          UpperCAmelCase__							: Dict 							=						to_channel_dimension_format(__UpperCamelCase ,			__UpperCamelCase  )
          return image



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			__UpperCamelCase = ChannelDimension.FIRST ,			**__UpperCamelCase ,			)->					PIL.Image.Image:
          UpperCAmelCase__							: Optional[int] 							=						do_resize if do_resize is not None else self.do_resize
          UpperCAmelCase__							: int 							=						resample if resample is not None else self.resample
          UpperCAmelCase__							: Tuple 							=						do_center_crop if do_center_crop is not None else self.do_center_crop
          UpperCAmelCase__							: int 							=						do_rescale if do_rescale is not None else self.do_rescale
          UpperCAmelCase__							: Any 							=						rescale_factor if rescale_factor is not None else self.rescale_factor
          UpperCAmelCase__							: Optional[int] 							=						offset if offset is not None else self.offset
          UpperCAmelCase__							: Dict 							=						do_normalize if do_normalize is not None else self.do_normalize
          UpperCAmelCase__							: Dict 							=						image_mean if image_mean is not None else self.image_mean
          UpperCAmelCase__							: Optional[int] 							=						image_std if image_std is not None else self.image_std

          UpperCAmelCase__							: List[str] 							=						size if size is not None else self.size
          UpperCAmelCase__							: Optional[int] 							=						get_size_dict(__UpperCamelCase ,			default_to_square=__UpperCamelCase  )
          UpperCAmelCase__							: Dict 							=						crop_size if crop_size is not None else self.crop_size
          UpperCAmelCase__							: Tuple 							=						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."  )

          UpperCAmelCase__							: List[str] 							=						make_batched(__UpperCamelCase  )

          UpperCAmelCase__							: Optional[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 ,			offset=__UpperCamelCase ,			do_normalize=__UpperCamelCase ,			image_mean=__UpperCamelCase ,			image_std=__UpperCamelCase ,			data_format=__UpperCamelCase ,			)
                  for img in video
              ]
              for video in videos
          ]

          UpperCAmelCase__							: Dict 							=						{"pixel_values": videos}
          return BatchFeature(data=__UpperCamelCase ,			tensor_type=__UpperCamelCase  )



