





from __future__ import annotations

import copy
import inspect
import json
import math
import os
import tempfile
import unittest
from importlib import import_module

import numpy as np

from transformers import ViTMAEConfig
from transformers.file_utils import cached_property, is_tf_available, is_vision_available
from transformers.testing_utils import require_tf, require_vision, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
			import tensorflow as tf

			from transformers import TFViTMAEForPreTraining, TFViTMAEModel


if is_vision_available():
			from PIL import Image

			from transformers import ViTImageProcessor
class   a_ :

			def __init__(   self   :  List[str]     , UpperCAmelCase__   :  Optional[Any]     , UpperCAmelCase__   :  Dict=13     , UpperCAmelCase__   :  Dict=30     , UpperCAmelCase__   :  Any=2     , UpperCAmelCase__   :  Union[str, Any]=3     , UpperCAmelCase__   :  Union[str, Any]=True     , UpperCAmelCase__   :  Optional[int]=True     , UpperCAmelCase__   :  Optional[int]=32     , UpperCAmelCase__   :  Optional[Any]=2     , UpperCAmelCase__   :  List[Any]=4     , UpperCAmelCase__   :  Dict=37     , UpperCAmelCase__   :  Dict="gelu"     , UpperCAmelCase__   :  Optional[Any]=0.1     , UpperCAmelCase__   :  Any=0.1     , UpperCAmelCase__   :  List[Any]=10     , UpperCAmelCase__   :  Tuple=0.02     , UpperCAmelCase__   :  int=3     , UpperCAmelCase__   :  int=0.6     , UpperCAmelCase__   :  List[Any]=None     , ):






							"""simple docstring"""
							snake_case   :					Any    						=				parent
							snake_case   :					Optional[Any]    						=				batch_size
							snake_case   :					Dict    						=				image_size
							snake_case   :					Tuple    						=				patch_size
							snake_case   :					Any    						=				num_channels
							snake_case   :					Tuple    						=				is_training
							snake_case   :					Optional[int]    						=				use_labels
							snake_case   :					Dict    						=				hidden_size
							snake_case   :					Dict    						=				num_hidden_layers
							snake_case   :					List[Any]    						=				num_attention_heads
							snake_case   :					Optional[Any]    						=				intermediate_size
							snake_case   :					Any    						=				hidden_act
							snake_case   :					Optional[int]    						=				hidden_dropout_prob
							snake_case   :					int    						=				attention_probs_dropout_prob
							snake_case   :					Optional[Any]    						=				type_sequence_label_size
							snake_case   :					str    						=				initializer_range
							snake_case   :					List[Any]    						=				mask_ratio
							snake_case   :					Any    						=				scope

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

			def      lowerCAmelCase(   self   :  Optional[int]						):






							"""simple docstring"""
							snake_case   :					int    						=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

							snake_case   :					Union[str, Any]    						=				None
							if self.use_labels:
											snake_case   :					Any    						=				ids_tensor([self.batch_size]     , self.type_sequence_label_size						)

							snake_case   :					int    						=				self.get_config()

							return config, pixel_values, labels

			def      lowerCAmelCase(   self   :  Dict						):






							"""simple docstring"""
							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     , decoder_hidden_size=self.hidden_size     , decoder_num_hidden_layers=self.num_hidden_layers     , decoder_num_attention_heads=self.num_attention_heads     , decoder_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   :  Union[str, Any]     , UpperCAmelCase__   :  Any     , UpperCAmelCase__   :  Tuple     , UpperCAmelCase__   :  Optional[int]						):






							"""simple docstring"""
							snake_case   :					Union[str, Any]    						=				TFViTMAEModel(config=_UpperCamelCase						)
							snake_case   :					Dict    						=				model(_UpperCamelCase     , training=_UpperCamelCase						)
							self.parent.assertEqual(result.last_hidden_state.shape     , (self.batch_size, self.seq_length, self.hidden_size)						)

			def      lowerCAmelCase(   self   :  Tuple     , UpperCAmelCase__   :  Optional[int]     , UpperCAmelCase__   :  Any     , UpperCAmelCase__   :  Tuple						):






							"""simple docstring"""
							snake_case   :					Optional[Any]    						=				TFViTMAEForPreTraining(_UpperCamelCase						)
							snake_case   :					Optional[int]    						=				model(_UpperCamelCase     , training=_UpperCamelCase						)
							# expected sequence length = num_patches
							snake_case   :					int    						=				(self.image_size // self.patch_size) ** 2
							snake_case   :					Dict    						=				self.patch_size**2 * self.num_channels
							self.parent.assertEqual(result.logits.shape     , (self.batch_size, num_patches, expected_num_channels)						)

							# test greyscale images
							snake_case   :					Any    						=				1
							snake_case   :					str    						=				TFViTMAEForPreTraining(_UpperCamelCase						)

							snake_case   :					Optional[Any]    						=				floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
							snake_case   :					List[Any]    						=				model(_UpperCamelCase     , training=_UpperCamelCase						)
							snake_case   :					List[str]    						=				self.patch_size**2
							self.parent.assertEqual(result.logits.shape     , (self.batch_size, num_patches, expected_num_channels)						)



			def      lowerCAmelCase(   self   :  int						):






							"""simple docstring"""
							snake_case   :					str    						=				self.prepare_config_and_inputs()
							((snake_case)						,						(snake_case)						,						(snake_case))   :					Tuple    						=				config_and_inputs
							snake_case   :					int    						=				{'''pixel_values''': pixel_values}
							return config, inputs_dict
@require_tf
class   a_ (			snake_case__		,							snake_case__		,							unittest.TestCase      ):
			A__      :			Dict       	=  (TFViTMAEModel, TFViTMAEForPreTraining) if is_tf_available() else ()
			A__      :			Union[str, Any]       	=  {'feature-extraction': TFViTMAEModel} if is_tf_available() else {}

			A__      :			List[str]       	=  False
			A__      :			Tuple       	=  False
			A__      :			Optional[int]       	=  False
			A__      :			Optional[int]       	=  False

			def      lowerCAmelCase(   self   :  Any						):






							"""simple docstring"""
							snake_case   :					Tuple    						=				TFViTMAEModelTester(self						)
							snake_case   :					int    						=				ConfigTester(self     , config_class=_UpperCamelCase     , has_text_modality=_UpperCamelCase     , hidden_size=37						)

			def      lowerCAmelCase(   self   :  Union[str, Any]						):






							"""simple docstring"""
							self.config_tester.run_common_tests()

			@unittest.skip(reason='''ViTMAE does not use inputs_embeds'''						)
			def      lowerCAmelCase(   self   :  Tuple						):






							"""simple docstring"""
							pass

			def      lowerCAmelCase(   self   :  List[str]						):






							"""simple docstring"""
							snake_case						,						snake_case   :					int    						=				self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
											snake_case   :					str    						=				model_class(_UpperCamelCase						)
											self.assertIsInstance(model.get_input_embeddings()     , (tf.keras.layers.Layer)						)
											snake_case   :					Dict    						=				model.get_output_embeddings()
											self.assertTrue(x is None or isinstance(_UpperCamelCase     , tf.keras.layers.Layer						)						)

			def      lowerCAmelCase(   self   :  Optional[int]						):






							"""simple docstring"""
							snake_case						,						snake_case   :					List[Any]    						=				self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
											snake_case   :					Optional[int]    						=				model_class(_UpperCamelCase						)
											snake_case   :					List[str]    						=				inspect.signature(model.call						)
											# signature.parameters is an OrderedDict => so arg_names order is deterministic
											snake_case   :					Optional[int]    						=				[*signature.parameters.keys()]

											snake_case   :					Optional[Any]    						=				['''pixel_values''']
											self.assertListEqual(arg_names[:1]     , _UpperCamelCase						)

			def      lowerCAmelCase(   self   :  Union[str, Any]						):






							"""simple docstring"""
							snake_case   :					Union[str, Any]    						=				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_UpperCamelCase						)

			def      lowerCAmelCase(   self   :  Union[str, Any]						):






							"""simple docstring"""
							snake_case   :					List[str]    						=				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*_UpperCamelCase						)

			def      lowerCAmelCase(   self   :  int						):






							"""simple docstring"""
							np.random.seed(2						)

							snake_case						,						snake_case   :					str    						=				self.model_tester.prepare_config_and_inputs_for_common()

							snake_case   :					str    						=				int((config.image_size // config.patch_size) ** 2						)
							snake_case   :					List[Any]    						=				np.random.uniform(size=(self.model_tester.batch_size, num_patches)						)

							for model_class in self.all_model_classes:
											snake_case   :					List[Any]    						=				model_class(_UpperCamelCase						)
											snake_case   :					Tuple    						=				self._prepare_for_class(_UpperCamelCase     , _UpperCamelCase						)

											snake_case   :					List[Any]    						=				model(_UpperCamelCase     , noise=_UpperCamelCase						)

											snake_case   :					str    						=				copy.deepcopy(self._prepare_for_class(_UpperCamelCase     , _UpperCamelCase						)						)
											snake_case   :					Any    						=				model(**_UpperCamelCase     , noise=_UpperCamelCase						)
											snake_case   :					Any    						=				outputs_dict[0].numpy()
											snake_case   :					int    						=				outputs_keywords[0].numpy()

											self.assertLess(np.sum(np.abs(output_dict - output_keywords						)						)     , 1e-6						)

			def      lowerCAmelCase(   self   :  Any						):






							"""simple docstring"""
							np.random.seed(2						)

							snake_case						,						snake_case   :					Any    						=				self.model_tester.prepare_config_and_inputs_for_common()

							snake_case   :					str    						=				int((config.image_size // config.patch_size) ** 2						)
							snake_case   :					str    						=				np.random.uniform(size=(self.model_tester.batch_size, num_patches)						)

							def prepare_numpy_arrays(UpperCAmelCase__   :  Union[str, Any]						):
											snake_case   :					List[Any]    						=				{}
											for k, v in inputs_dict.items():
															if tf.is_tensor(_UpperCamelCase						):
																			snake_case   :					Optional[int]    						=				v.numpy()
															else:
																			snake_case   :					List[str]    						=				np.array(_UpperCamelCase						)

											return inputs_np_dict

							for model_class in self.all_model_classes:
											snake_case   :					List[Any]    						=				model_class(_UpperCamelCase						)

											snake_case   :					Optional[Any]    						=				self._prepare_for_class(_UpperCamelCase     , _UpperCamelCase						)
											snake_case   :					List[Any]    						=				prepare_numpy_arrays(_UpperCamelCase						)

											snake_case   :					str    						=				model(_UpperCamelCase     , noise=_UpperCamelCase						)
											snake_case   :					str    						=				model(**_UpperCamelCase     , noise=_UpperCamelCase						)
											self.assert_outputs_same(_UpperCamelCase     , _UpperCamelCase						)

			def      lowerCAmelCase(   self   :  str     , UpperCAmelCase__   :  Union[str, Any]     , UpperCAmelCase__   :  Any     , UpperCAmelCase__   :  str						):






							"""simple docstring"""
							np.random.seed(2						)

							snake_case   :					int    						=				int((tf_model.config.image_size // tf_model.config.patch_size) ** 2						)
							snake_case   :					Tuple    						=				np.random.uniform(size=(self.model_tester.batch_size, num_patches)						)
							snake_case   :					Any    						=				tf.constant(_UpperCamelCase						)

							# Add `noise` argument.
							# PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
							snake_case   :					Union[str, Any]    						=				tf_noise

							super().check_pt_tf_models(_UpperCamelCase     , _UpperCamelCase     , _UpperCamelCase						)

			def      lowerCAmelCase(   self   :  Union[str, Any]						):






							"""simple docstring"""
							np.random.seed(2						)

							snake_case						,						snake_case   :					Dict    						=				self.model_tester.prepare_config_and_inputs_for_common()

							snake_case   :					int    						=				{
							    module_member
							    for model_class in self.all_model_classes
							    for module in (import_module(model_class.__module__						),)
							    for module_member_name in dir(_UpperCamelCase						)
							    if module_member_name.endswith('''MainLayer'''						)
							    # This condition is required, since `modeling_tf_clip.py` has 3 classes whose names end with `MainLayer`.
							    and module_member_name[: -len('''MainLayer'''						)] == model_class.__name__[: -len('''Model'''						)]
							    for module_member in (getattr(_UpperCamelCase     , _UpperCamelCase						),)
							    if isinstance(_UpperCamelCase     , _UpperCamelCase						)
							    and tf.keras.layers.Layer in module_member.__bases__
							    and getattr(_UpperCamelCase     , '''_keras_serializable'''     , _UpperCamelCase						)
							}

							snake_case   :					Optional[int]    						=				int((config.image_size // config.patch_size) ** 2						)
							snake_case   :					Optional[Any]    						=				np.random.uniform(size=(self.model_tester.batch_size, num_patches)						)
							snake_case   :					List[Any]    						=				tf.convert_to_tensor(_UpperCamelCase						)
							inputs_dict.update({'''noise''': noise}						)

							for main_layer_class in tf_main_layer_classes:
											snake_case   :					Optional[Any]    						=				main_layer_class(_UpperCamelCase						)

											snake_case   :					str    						=				{
											    name: tf.keras.Input(tensor.shape[1:]     , dtype=tensor.dtype						) for name, tensor in inputs_dict.items()
											}

											snake_case   :					Union[str, Any]    						=				tf.keras.Model(_UpperCamelCase     , outputs=main_layer(_UpperCamelCase						)						)
											snake_case   :					Any    						=				model(_UpperCamelCase						)

											with tempfile.TemporaryDirectory() as tmpdirname:
															snake_case   :					str    						=				os.path.join(_UpperCamelCase     , '''keras_model.h5'''						)
															model.save(_UpperCamelCase						)
															snake_case   :					Union[str, Any]    						=				tf.keras.models.load_model(
															    _UpperCamelCase     , custom_objects={main_layer_class.__name__: main_layer_class}						)
															assert isinstance(_UpperCamelCase     , tf.keras.Model						)
															snake_case   :					str    						=				model(_UpperCamelCase						)
															self.assert_outputs_same(_UpperCamelCase     , _UpperCamelCase						)

			@slow
			def      lowerCAmelCase(   self   :  Optional[Any]						):






							"""simple docstring"""
							np.random.seed(2						)

							snake_case						,						snake_case   :					str    						=				self.model_tester.prepare_config_and_inputs_for_common()

							snake_case   :					Dict    						=				int((config.image_size // config.patch_size) ** 2						)
							snake_case   :					Optional[Any]    						=				np.random.uniform(size=(self.model_tester.batch_size, num_patches)						)

							for model_class in self.all_model_classes:
											snake_case   :					Union[str, Any]    						=				model_class(_UpperCamelCase						)
											snake_case   :					List[str]    						=				self._prepare_for_class(_UpperCamelCase     , _UpperCamelCase						)
											snake_case   :					Any    						=				model(_UpperCamelCase     , noise=_UpperCamelCase						)

											if model_class.__name__ == "TFViTMAEModel":
															snake_case   :					List[str]    						=				outputs.last_hidden_state.numpy()
															snake_case   :					List[str]    						=				0
											else:
															snake_case   :					Optional[Any]    						=				outputs.logits.numpy()
															snake_case   :					Union[str, Any]    						=				0

											with tempfile.TemporaryDirectory() as tmpdirname:
															model.save_pretrained(_UpperCamelCase     , saved_model=_UpperCamelCase						)
															snake_case   :					int    						=				model_class.from_pretrained(_UpperCamelCase						)
															snake_case   :					Union[str, Any]    						=				model(_UpperCamelCase     , noise=_UpperCamelCase						)

															if model_class.__name__ == "TFViTMAEModel":
																			snake_case   :					str    						=				after_outputs['''last_hidden_state'''].numpy()
																			snake_case   :					List[Any]    						=				0
															else:
																			snake_case   :					List[Any]    						=				after_outputs['''logits'''].numpy()
																			snake_case   :					List[Any]    						=				0

															snake_case   :					int    						=				np.amax(np.abs(out_a - out_a						)						)
															self.assertLessEqual(_UpperCamelCase     , 1e-5						)

			def      lowerCAmelCase(   self   :  List[str]						):






							"""simple docstring"""
							np.random.seed(2						)

							snake_case						,						snake_case   :					List[Any]    						=				self.model_tester.prepare_config_and_inputs_for_common()

							snake_case   :					List[Any]    						=				int((config.image_size // config.patch_size) ** 2						)
							snake_case   :					List[str]    						=				np.random.uniform(size=(self.model_tester.batch_size, num_patches)						)

							for model_class in self.all_model_classes:
											snake_case   :					List[str]    						=				model_class(_UpperCamelCase						)
											snake_case   :					Dict    						=				self._prepare_for_class(_UpperCamelCase     , _UpperCamelCase						)

											snake_case   :					Tuple    						=				model(_UpperCamelCase     , noise=_UpperCamelCase						)
											snake_case   :					Tuple    						=				model.get_config()
											# make sure that returned config is jsonifiable, which is required by keras
											json.dumps(_UpperCamelCase						)
											snake_case   :					Tuple    						=				model_class.from_config(model.get_config()						)
											# make sure it also accepts a normal config
											snake_case   :					List[str]    						=				model_class.from_config(model.config						)
											snake_case   :					Optional[int]    						=				new_model(_UpperCamelCase						)  # Build model
											new_model.set_weights(model.get_weights()						)
											snake_case   :					Dict    						=				new_model(_UpperCamelCase     , noise=_UpperCamelCase						)

											self.assert_outputs_same(_UpperCamelCase     , _UpperCamelCase						)

			@unittest.skip(
			    reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load
    to get deterministic results.'''						)
			def      lowerCAmelCase(   self   :  Dict						):






							"""simple docstring"""
							pass

			@unittest.skip(reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load'''						)
			def      lowerCAmelCase(   self   :  Tuple						):






							"""simple docstring"""
							pass



			@slow
			def      lowerCAmelCase(   self   :  Optional[Any]						):






							"""simple docstring"""
							snake_case   :					Optional[int]    						=				TFViTMAEModel.from_pretrained('''google/vit-base-patch16-224'''						)
							self.assertIsNotNone(_UpperCamelCase						)
def 							a_	(    )				->			Dict:




				"""simple docstring"""






				snake_case   :					Optional[int]    						=				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''   )
				return image
@require_tf
@require_vision
class   a_ (			unittest.TestCase      ):

			@cached_property
			def      lowerCAmelCase(   self   :  Optional[int]						):






							"""simple docstring"""
							return ViTImageProcessor.from_pretrained('''facebook/vit-mae-base'''						) if is_vision_available() else None



			@slow
			def      lowerCAmelCase(   self   :  Any						):






							"""simple docstring"""
							np.random.seed(2						)

							snake_case   :					Dict    						=				TFViTMAEForPreTraining.from_pretrained('''facebook/vit-mae-base'''						)

							snake_case   :					List[Any]    						=				self.default_image_processor
							snake_case   :					Any    						=				prepare_img()
							snake_case   :					str    						=				image_processor(images=_UpperCamelCase     , return_tensors='''tf'''						)

							# 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)
							snake_case   :					str    						=				ViTMAEConfig()
							snake_case   :					str    						=				int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2						)
							snake_case   :					Dict    						=				np.random.uniform(size=(1, num_patches)						)

							# forward pass
							snake_case   :					Any    						=				model(**_UpperCamelCase     , noise=_UpperCamelCase						)

							# verify the logits
							snake_case   :					Dict    						=				tf.convert_to_tensor([1, 196, 768]						)
							self.assertEqual(outputs.logits.shape     , _UpperCamelCase						)

							snake_case   :					Optional[Any]    						=				tf.convert_to_tensor(
							    [[-0.0548, -1.7023, -0.9325], [0.3721, -0.5670, -0.2233], [0.8235, -1.3878, -0.3524]]						)

							tf.debugging.assert_near(outputs.logits[0, :3, :3]     , _UpperCamelCase     , atol=1e-4						)



import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_video_inputs


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import VivitImageProcessor

class     __snake_case    (				unittest.TestCase  ):
       """simple docstring"""







       def __init__(		self      , _UpperCamelCase      , _UpperCamelCase=7      , _UpperCamelCase=3      , _UpperCamelCase=10      , _UpperCamelCase=18      , _UpperCamelCase=30      , _UpperCamelCase=4_00      , _UpperCamelCase=True      , _UpperCamelCase=None      , _UpperCamelCase=True      , _UpperCamelCase=[0.5, 0.5, 0.5]      , _UpperCamelCase=[0.5, 0.5, 0.5]      , _UpperCamelCase=None      , )      ->							str:






              """simple docstring"""


              __snake_case       	=							size if size is not None else {"""shortest_edge""": 18}
              __snake_case       	=							crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

              __snake_case       	=							parent
              __snake_case       	=							batch_size
              __snake_case       	=							num_channels
              __snake_case       	=							num_frames
              __snake_case       	=							image_size
              __snake_case       	=							min_resolution
              __snake_case       	=							max_resolution
              __snake_case       	=							do_resize
              __snake_case       	=							size
              __snake_case       	=							do_normalize
              __snake_case       	=							image_mean
              __snake_case       	=							image_std
              __snake_case       	=							crop_size






       def 			a		(		self   )      ->							Optional[Any]:






              """simple docstring"""


              return {
                  "image_mean": self.image_mean,
                  "image_std": self.image_std,
                  "do_normalize": self.do_normalize,
                  "do_resize": self.do_resize,
                  "size": self.size,
                  "crop_size": self.crop_size,
              }






@require_torch
@require_vision
class     __snake_case    (				snake_case__			,	unittest.TestCase  ):
       """simple docstring"""







       __SCREAMING_SNAKE_CASE				    =							VivitImageProcessor if is_vision_available() else None


       def 			a		(		self   )      ->							int:






              """simple docstring"""


              __snake_case       	=							VivitImageProcessingTester(self   )


       @property
       def 			a		(		self   )      ->							str:






              """simple docstring"""


              return self.image_processor_tester.prepare_image_processor_dict()


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






              """simple docstring"""


              __snake_case       	=							self.image_processing_class(**self.image_processor_dict   )
              self.assertTrue(hasattr(_UpperCamelCase      , """image_mean"""   )   )
              self.assertTrue(hasattr(_UpperCamelCase      , """image_std"""   )   )
              self.assertTrue(hasattr(_UpperCamelCase      , """do_normalize"""   )   )
              self.assertTrue(hasattr(_UpperCamelCase      , """do_resize"""   )   )
              self.assertTrue(hasattr(_UpperCamelCase      , """do_center_crop"""   )   )
              self.assertTrue(hasattr(_UpperCamelCase      , """size"""   )   )


       def 			a		(		self   )      ->							str:






              """simple docstring"""


              __snake_case       	=							self.image_processing_class.from_dict(self.image_processor_dict   )
              self.assertEqual(image_processor.size      , {"""shortest_edge""": 18}   )
              self.assertEqual(image_processor.crop_size      , {"""height""": 18, """width""": 18}   )

              __snake_case       	=							self.image_processing_class.from_dict(self.image_processor_dict      , size=42      , crop_size=84   )
              self.assertEqual(image_processor.size      , {"""shortest_edge""": 42}   )
              self.assertEqual(image_processor.crop_size      , {"""height""": 84, """width""": 84}   )


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






              """simple docstring"""


              __snake_case       	=							self.image_processing_class(**self.image_processor_dict   )
              # create random PIL videos
              __snake_case       	=							prepare_video_inputs(self.image_processor_tester      , equal_resolution=_UpperCamelCase   )
              for video in video_inputs:
                     self.assertIsInstance(_UpperCamelCase      , _UpperCamelCase   )
                     self.assertIsInstance(video[0]      , Image.Image   )

              # Test not batched input
              __snake_case       	=							image_processing(video_inputs[0]      , return_tensors="""pt"""   ).pixel_values
              self.assertEqual(
                  encoded_videos.shape      , (
                      1,
                      self.image_processor_tester.num_frames,
                      self.image_processor_tester.num_channels,
                      self.image_processor_tester.crop_size["""height"""],
                      self.image_processor_tester.crop_size["""width"""],
                  )      , )

              # Test batched
              __snake_case       	=							image_processing(_UpperCamelCase      , return_tensors="""pt"""   ).pixel_values
              self.assertEqual(
                  encoded_videos.shape      , (
                      self.image_processor_tester.batch_size,
                      self.image_processor_tester.num_frames,
                      self.image_processor_tester.num_channels,
                      self.image_processor_tester.crop_size["""height"""],
                      self.image_processor_tester.crop_size["""width"""],
                  )      , )


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






              """simple docstring"""


              __snake_case       	=							self.image_processing_class(**self.image_processor_dict   )
              # create random numpy tensors
              __snake_case       	=							prepare_video_inputs(self.image_processor_tester      , equal_resolution=_UpperCamelCase      , numpify=_UpperCamelCase   )
              for video in video_inputs:
                     self.assertIsInstance(_UpperCamelCase      , _UpperCamelCase   )
                     self.assertIsInstance(video[0]      , np.ndarray   )

              # Test not batched input
              __snake_case       	=							image_processing(video_inputs[0]      , return_tensors="""pt"""   ).pixel_values
              self.assertEqual(
                  encoded_videos.shape      , (
                      1,
                      self.image_processor_tester.num_frames,
                      self.image_processor_tester.num_channels,
                      self.image_processor_tester.crop_size["""height"""],
                      self.image_processor_tester.crop_size["""width"""],
                  )      , )

              # Test batched
              __snake_case       	=							image_processing(_UpperCamelCase      , return_tensors="""pt"""   ).pixel_values
              self.assertEqual(
                  encoded_videos.shape      , (
                      self.image_processor_tester.batch_size,
                      self.image_processor_tester.num_frames,
                      self.image_processor_tester.num_channels,
                      self.image_processor_tester.crop_size["""height"""],
                      self.image_processor_tester.crop_size["""width"""],
                  )      , )






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






              """simple docstring"""


              __snake_case       	=							self.image_processing_class(**self.image_processor_dict   )
              # create random PyTorch tensors
              __snake_case       	=							prepare_video_inputs(self.image_processor_tester      , equal_resolution=_UpperCamelCase      , torchify=_UpperCamelCase   )
              for video in video_inputs:
                     self.assertIsInstance(_UpperCamelCase      , _UpperCamelCase   )
                     self.assertIsInstance(video[0]      , torch.Tensor   )

              # Test not batched input
              __snake_case       	=							image_processing(video_inputs[0]      , return_tensors="""pt"""   ).pixel_values
              self.assertEqual(
                  encoded_videos.shape      , (
                      1,
                      self.image_processor_tester.num_frames,
                      self.image_processor_tester.num_channels,
                      self.image_processor_tester.crop_size["""height"""],
                      self.image_processor_tester.crop_size["""width"""],
                  )      , )

              # Test batched
              __snake_case       	=							image_processing(_UpperCamelCase      , return_tensors="""pt"""   ).pixel_values
              self.assertEqual(
                  encoded_videos.shape      , (
                      self.image_processor_tester.batch_size,
                      self.image_processor_tester.num_frames,
                      self.image_processor_tester.num_channels,
                      self.image_processor_tester.crop_size["""height"""],
                      self.image_processor_tester.crop_size["""width"""],
                  )      , )

