





import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import MaskaFormerConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import MaskaFormerForUniversalSegmentation, MaskaFormerModel

			if is_vision_available():
						from transformers import MaskaFormerImageProcessor

if is_vision_available():
			from PIL import Image
class   a_ :

			def __init__(   self   :  int     , UpperCAmelCase__   :  List[Any]     , UpperCAmelCase__   :  str=2     , UpperCAmelCase__   :  Dict=True     , UpperCAmelCase__   :  Tuple=False     , UpperCAmelCase__   :  List[str]=10     , UpperCAmelCase__   :  int=3     , UpperCAmelCase__   :  str=32 * 8     , UpperCAmelCase__   :  Tuple=32 * 8     , UpperCAmelCase__   :  Tuple=4     , UpperCAmelCase__   :  Optional[int]=64     , ):






							"""simple docstring"""
							snake_case   :					Tuple    						=				parent
							snake_case   :					Any    						=				batch_size
							snake_case   :					List[str]    						=				is_training
							snake_case   :					Dict    						=				use_auxiliary_loss
							snake_case   :					Any    						=				num_queries
							snake_case   :					List[Any]    						=				num_channels
							snake_case   :					Any    						=				min_size
							snake_case   :					Optional[int]    						=				max_size
							snake_case   :					List[Any]    						=				num_labels
							snake_case   :					Optional[int]    						=				hidden_dim
							snake_case   :					Dict    						=				hidden_dim

			def      lowerCAmelCase(   self   :  Optional[int]						):






							"""simple docstring"""
							snake_case   :					Tuple    						=				floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]						).to(
							    _UpperCamelCase						)

							snake_case   :					List[Any]    						=				torch.ones([self.batch_size, self.min_size, self.max_size]     , device=_UpperCamelCase						)

							snake_case   :					List[str]    						=				(
							    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]     , device=_UpperCamelCase						) > 0.5
							).float()
							snake_case   :					Optional[Any]    						=				(torch.rand((self.batch_size, self.num_labels)     , device=_UpperCamelCase						) > 0.5).long()

							snake_case   :					Tuple    						=				self.get_config()
							return config, pixel_values, pixel_mask, mask_labels, class_labels

			def      lowerCAmelCase(   self   :  Any						):






							"""simple docstring"""
							snake_case   :					Optional[Any]    						=				MaskaFormerConfig(
							    hidden_size=self.hidden_dim     , )
							snake_case   :					Optional[int]    						=				self.num_queries
							snake_case   :					Dict    						=				self.num_labels

							snake_case   :					str    						=				[1, 1, 1, 1]
							snake_case   :					str    						=				self.num_channels

							snake_case   :					Optional[int]    						=				64
							snake_case   :					Tuple    						=				128
							snake_case   :					List[Any]    						=				self.hidden_dim
							snake_case   :					List[str]    						=				self.hidden_dim
							snake_case   :					str    						=				self.hidden_dim
							return config

			def      lowerCAmelCase(   self   :  List[Any]						):






							"""simple docstring"""
							snake_case						,						snake_case						,						snake_case						,						snake_case						,						snake_case   :					Optional[int]    						=				self.prepare_config_and_inputs()
							snake_case   :					Optional[int]    						=				{'''pixel_values''': pixel_values, '''pixel_mask''': pixel_mask}
							return config, inputs_dict

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






							"""simple docstring"""
							snake_case   :					List[str]    						=				output.encoder_hidden_states
							snake_case   :					Optional[int]    						=				output.pixel_decoder_hidden_states
							snake_case   :					str    						=				output.transformer_decoder_hidden_states

							self.parent.assertTrue(len(_UpperCamelCase						)     , len(config.backbone_config.depths						)						)
							self.parent.assertTrue(len(_UpperCamelCase						)     , len(config.backbone_config.depths						)						)
							self.parent.assertTrue(len(_UpperCamelCase						)     , config.decoder_layers						)

			def      lowerCAmelCase(   self   :  Optional[int]     , UpperCAmelCase__   :  Union[str, Any]     , UpperCAmelCase__   :  Dict     , UpperCAmelCase__   :  int     , UpperCAmelCase__   :  Tuple=False						):






							"""simple docstring"""


							with torch.no_grad():
											snake_case   :					List[str]    						=				MaskaFormerModel(config=_UpperCamelCase						)
											model.to(_UpperCamelCase						)
											model.eval()

											snake_case   :					Any    						=				model(pixel_values=_UpperCamelCase     , pixel_mask=_UpperCamelCase						)
											snake_case   :					Optional[int]    						=				model(_UpperCamelCase     , output_hidden_states=_UpperCamelCase						)

							self.parent.assertEqual(
							    output.transformer_decoder_last_hidden_state.shape     , (self.batch_size, self.num_queries, self.hidden_dim)     , )
							# let's ensure the other two hidden state exists
							self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None						)
							self.parent.assertTrue(output.encoder_last_hidden_state is not None						)

							if output_hidden_states:
											self.check_output_hidden_state(_UpperCamelCase     , _UpperCamelCase						)



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






							"""simple docstring"""
							snake_case   :					Union[str, Any]    						=				MaskaFormerForUniversalSegmentation(config=_UpperCamelCase						)
							model.to(_UpperCamelCase						)
							model.eval()

							def comm_check_on_output(UpperCAmelCase__   :  int						):
											# let's still check that all the required stuff is there
											self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None						)
											self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None						)
											self.parent.assertTrue(result.encoder_last_hidden_state is not None						)
											# okay, now we need to check the logits shape
											# due to the encoder compression, masks have a //4 spatial size
											self.parent.assertEqual(
											    result.masks_queries_logits.shape     , (self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)     , )
											# + 1 for null class
											self.parent.assertEqual(
											    result.class_queries_logits.shape     , (self.batch_size, self.num_queries, self.num_labels + 1)						)

							with torch.no_grad():
											snake_case   :					int    						=				model(pixel_values=_UpperCamelCase     , pixel_mask=_UpperCamelCase						)
											snake_case   :					int    						=				model(_UpperCamelCase						)

											comm_check_on_output(_UpperCamelCase						)

											snake_case   :					Optional[Any]    						=				model(
											    pixel_values=_UpperCamelCase     , pixel_mask=_UpperCamelCase     , mask_labels=_UpperCamelCase     , class_labels=_UpperCamelCase						)

							comm_check_on_output(_UpperCamelCase						)

							self.parent.assertTrue(result.loss is not None						)
							self.parent.assertEqual(result.loss.shape     , torch.Size([1]						)						)
@require_torch
class   a_ (			snake_case__		,							snake_case__		,							unittest.TestCase      ):
			A__      :			List[Any]       	=  (MaskaFormerModel, MaskaFormerForUniversalSegmentation) if is_torch_available() else ()
			A__      :			str       	=  {'feature-extraction': MaskaFormerModel} if is_torch_available() else {}

			A__      :			int       	=  False
			A__      :			int       	=  False
			A__      :			str       	=  False
			A__      :			Dict       	=  False

			def      lowerCAmelCase(   self   :  List[Any]						):






							"""simple docstring"""
							snake_case   :					Any    						=				MaskaFormerModelTester(self						)
							snake_case   :					Tuple    						=				ConfigTester(self     , config_class=_UpperCamelCase     , has_text_modality=_UpperCamelCase						)

			def      lowerCAmelCase(   self   :  str						):






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

			def      lowerCAmelCase(   self   :  List[Any]						):






							"""simple docstring"""
							snake_case						,						snake_case   :					Any    						=				self.model_tester.prepare_config_and_inputs_for_common()
							self.model_tester.create_and_check_maskaformer_model(_UpperCamelCase     , **_UpperCamelCase     , output_hidden_states=_UpperCamelCase						)

			def      lowerCAmelCase(   self   :  Optional[Any]						):






							"""simple docstring"""
							snake_case   :					Any    						=				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_maskaformer_instance_segmentation_head_model(*_UpperCamelCase						)

			@unittest.skip(reason='''Mask2Former does not use inputs_embeds'''						)
			def      lowerCAmelCase(   self   :  List[str]						):






							"""simple docstring"""
							pass

			@unittest.skip(reason='''Mask2Former does not have a get_input_embeddings method'''						)
			def      lowerCAmelCase(   self   :  Any						):






							"""simple docstring"""
							pass

			@unittest.skip(reason='''Mask2Former is not a generative model'''						)
			def      lowerCAmelCase(   self   :  int						):






							"""simple docstring"""
							pass

			@unittest.skip(reason='''Mask2Former does not use token embeddings'''						)
			def      lowerCAmelCase(   self   :  int						):






							"""simple docstring"""
							pass

			@require_torch_multi_gpu
			@unittest.skip(
			    reason='''Mask2Former has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''						)
			def      lowerCAmelCase(   self   :  int						):






							"""simple docstring"""
							pass

			@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''						)
			def      lowerCAmelCase(   self   :  Any						):






							"""simple docstring"""
							pass

			def      lowerCAmelCase(   self   :  List[Any]						):






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

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

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

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






							"""simple docstring"""


							for model_name in ["facebook/mask2former-swin-small-coco-instance"]:
											snake_case   :					str    						=				MaskaFormerModel.from_pretrained(_UpperCamelCase						)
											self.assertIsNotNone(_UpperCamelCase						)

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






							"""simple docstring"""
							snake_case   :					Optional[Any]    						=				(self.model_tester.min_size,) * 2
							snake_case   :					List[str]    						=				{
							    '''pixel_values''': torch.randn((2, 3, *size)     , device=_UpperCamelCase						),
							    '''mask_labels''': torch.randn((2, 10, *size)     , device=_UpperCamelCase						),
							    '''class_labels''': torch.zeros(2     , 10     , device=_UpperCamelCase						).long(),
							}
							snake_case   :					Optional[int]    						=				self.model_tester.get_config()

							snake_case   :					Union[str, Any]    						=				MaskaFormerForUniversalSegmentation(_UpperCamelCase						).to(_UpperCamelCase						)
							snake_case   :					Optional[int]    						=				model(**_UpperCamelCase						)
							self.assertTrue(outputs.loss is not None						)

			def      lowerCAmelCase(   self   :  Dict						):






							"""simple docstring"""
							snake_case						,						snake_case   :					Optional[int]    						=				self.model_tester.prepare_config_and_inputs_for_common()
							self.model_tester.create_and_check_maskaformer_model(_UpperCamelCase     , **_UpperCamelCase     , output_hidden_states=_UpperCamelCase						)

			def      lowerCAmelCase(   self   :  Dict						):






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

							for model_class in self.all_model_classes:
											snake_case   :					List[str]    						=				model_class(_UpperCamelCase						).to(_UpperCamelCase						)
											snake_case   :					List[Any]    						=				model(**_UpperCamelCase     , output_attentions=_UpperCamelCase						)
											self.assertTrue(outputs.attentions is not None						)

			def      lowerCAmelCase(   self   :  str						):






							"""simple docstring"""


							if not self.model_tester.is_training:
											return

							snake_case   :					int    						=				self.all_model_classes[1]
							snake_case						,						snake_case						,						snake_case						,						snake_case						,						snake_case   :					int    						=				self.model_tester.prepare_config_and_inputs()

							snake_case   :					Optional[Any]    						=				model_class(_UpperCamelCase						)
							model.to(_UpperCamelCase						)
							model.train()

							snake_case   :					int    						=				model(_UpperCamelCase     , mask_labels=_UpperCamelCase     , class_labels=_UpperCamelCase						).loss
							loss.backward()



			def      lowerCAmelCase(   self   :  List[str]						):






							"""simple docstring"""
							snake_case   :					Any    						=				self.all_model_classes[1]
							snake_case						,						snake_case						,						snake_case						,						snake_case						,						snake_case   :					int    						=				self.model_tester.prepare_config_and_inputs()
							snake_case   :					Optional[Any]    						=				True
							snake_case   :					Optional[Any]    						=				True

							snake_case   :					Union[str, Any]    						=				model_class(_UpperCamelCase						).to(_UpperCamelCase						)
							model.train()

							snake_case   :					str    						=				model(_UpperCamelCase     , mask_labels=_UpperCamelCase     , class_labels=_UpperCamelCase						)

							snake_case   :					Optional[Any]    						=				outputs.encoder_hidden_states[0]
							encoder_hidden_states.retain_grad()

							snake_case   :					Union[str, Any]    						=				outputs.pixel_decoder_hidden_states[0]
							pixel_decoder_hidden_states.retain_grad()

							snake_case   :					Dict    						=				outputs.transformer_decoder_hidden_states[0]
							transformer_decoder_hidden_states.retain_grad()

							snake_case   :					Tuple    						=				outputs.attentions[0]
							attentions.retain_grad()

							outputs.loss.backward(retain_graph=_UpperCamelCase						)

							self.assertIsNotNone(encoder_hidden_states.grad						)
							self.assertIsNotNone(pixel_decoder_hidden_states.grad						)
							self.assertIsNotNone(transformer_decoder_hidden_states.grad						)
							self.assertIsNotNone(attentions.grad						)
_a     :    Union[str, Any]         =						1e-4
def 							a_	(    )				->			Any:




				"""simple docstring"""






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

			@cached_property
			def      lowerCAmelCase(   self   :  Tuple						):






							"""simple docstring"""
							return "facebook/mask2former-swin-small-coco-instance"

			@cached_property
			def      lowerCAmelCase(   self   :  int						):






							"""simple docstring"""
							return MaskaFormerImageProcessor.from_pretrained(self.model_checkpoints						) if is_vision_available() else None

			def      lowerCAmelCase(   self   :  int						):






							"""simple docstring"""
							snake_case   :					Dict    						=				MaskaFormerModel.from_pretrained(self.model_checkpoints						).to(_UpperCamelCase						)
							snake_case   :					List[str]    						=				self.default_image_processor
							snake_case   :					Union[str, Any]    						=				prepare_img()
							snake_case   :					List[Any]    						=				image_processor(_UpperCamelCase     , return_tensors='''pt'''						).to(_UpperCamelCase						)
							snake_case   :					Dict    						=				inputs['''pixel_values'''].shape
							# check size is divisible by 32
							self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0						)
							# check size
							self.assertEqual(_UpperCamelCase     , (1, 3, 384, 384)						)

							with torch.no_grad():
											snake_case   :					str    						=				model(**_UpperCamelCase						)

							snake_case   :					str    						=				torch.tensor(
							    [[-0.2790, -1.0717, -1.1668], [-0.5128, -0.3128, -0.4987], [-0.5832, 0.1971, -0.0197]]						).to(_UpperCamelCase						)
							self.assertTrue(
							    torch.allclose(
							        outputs.encoder_last_hidden_state[0, 0, :3, :3]     , _UpperCamelCase     , atol=_UpperCamelCase						)						)

							snake_case   :					Dict    						=				torch.tensor(
							    [[0.8973, 1.1847, 1.1776], [1.1934, 1.5040, 1.5128], [1.1153, 1.4486, 1.4951]]						).to(_UpperCamelCase						)
							self.assertTrue(
							    torch.allclose(
							        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]     , _UpperCamelCase     , atol=_UpperCamelCase						)						)

							snake_case   :					Union[str, Any]    						=				torch.tensor(
							    [[2.1152, 1.7000, -0.8603], [1.5808, 1.8004, -0.9353], [1.6043, 1.7495, -0.5999]]						).to(_UpperCamelCase						)
							self.assertTrue(
							    torch.allclose(
							        outputs.transformer_decoder_last_hidden_state[0, :3, :3]     , _UpperCamelCase     , atol=_UpperCamelCase						)						)

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






							"""simple docstring"""
							snake_case   :					Optional[Any]    						=				MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints						).to(_UpperCamelCase						).eval()
							snake_case   :					Any    						=				self.default_image_processor
							snake_case   :					Dict    						=				prepare_img()
							snake_case   :					Dict    						=				image_processor(_UpperCamelCase     , return_tensors='''pt'''						).to(_UpperCamelCase						)
							snake_case   :					List[Any]    						=				inputs['''pixel_values'''].shape
							# check size is divisible by 32
							self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0						)
							# check size
							self.assertEqual(_UpperCamelCase     , (1, 3, 384, 384)						)

							with torch.no_grad():
											snake_case   :					Optional[int]    						=				model(**_UpperCamelCase						)
							# masks_queries_logits
							snake_case   :					List[Any]    						=				outputs.masks_queries_logits
							self.assertEqual(
							    masks_queries_logits.shape     , (1, model.config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)						)
							snake_case   :					str    						=				[
							    [-8.7839, -9.0056, -8.8121],
							    [-7.4104, -7.0313, -6.5401],
							    [-6.6105, -6.3427, -6.4675],
							]
							snake_case   :					str    						=				torch.tensor(_UpperCamelCase						).to(_UpperCamelCase						)
							self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]     , _UpperCamelCase     , atol=_UpperCamelCase						)						)
							# class_queries_logits
							snake_case   :					Union[str, Any]    						=				outputs.class_queries_logits
							self.assertEqual(class_queries_logits.shape     , (1, model.config.num_queries, model.config.num_labels + 1)						)
							snake_case   :					Tuple    						=				torch.tensor(
							    [
							        [1.8324, -8.0835, -4.1922],
							        [0.8450, -9.0050, -3.6053],
							        [0.3045, -7.7293, -3.0275],
							    ]						).to(_UpperCamelCase						)
							self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]     , _UpperCamelCase     , atol=_UpperCamelCase						)						)



			def      lowerCAmelCase(   self   :  str						):






							"""simple docstring"""
							snake_case   :					int    						=				MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints						).to(_UpperCamelCase						).eval()
							snake_case   :					Union[str, Any]    						=				self.default_image_processor

							snake_case   :					Union[str, Any]    						=				image_processor(
							    [np.zeros((3, 800, 1_333)						), np.zeros((3, 800, 1_333)						)]     , segmentation_maps=[np.zeros((384, 384)						).astype(np.floataa						), np.zeros((384, 384)						).astype(np.floataa						)]     , return_tensors='''pt'''     , )

							snake_case   :					str    						=				inputs['''pixel_values'''].to(_UpperCamelCase						)
							snake_case   :					str    						=				[el.to(_UpperCamelCase						) for el in inputs['''mask_labels''']]
							snake_case   :					Union[str, Any]    						=				[el.to(_UpperCamelCase						) for el in inputs['''class_labels''']]

							with torch.no_grad():
											snake_case   :					Tuple    						=				model(**_UpperCamelCase						)

							self.assertTrue(outputs.loss is not None						)



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"""],
                  )      , )

