
import inspect
import unittest
import warnings

from transformers import DeiTConfig
from transformers.models.auto import get_values
from transformers.testing_utils import (
    require_accelerate,
    require_torch,
    require_torch_gpu,
    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 (
		    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
		    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
		    MODEL_MAPPING,
		    DeiTForImageClassification,
		    DeiTForImageClassificationWithTeacher,
		    DeiTForMaskedImageModeling,
		    DeiTModel,
		)
		from transformers.models.deit.modeling_deit import DEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
		from PIL import Image

		from transformers import DeiTImageProcessor







class 							lowerCAmelCase__   :

						def __init__(      self							,				a							,				a=13							,				a=30							,				a=2							,				a=3							,				a=True							,				a=True							,				a=32							,				a=5							,				a=4							,				a=37							,				a="gelu"							,				a=0.1							,				a=0.1							,				a=10							,				a=0.02							,				a=3							,				a=None							,				a=2							,				)       ->   Any:


								'''simple docstring'''

								_UpperCamelCase         =						parent
								_UpperCamelCase         =						batch_size
								_UpperCamelCase         =						image_size
								_UpperCamelCase         =						patch_size
								_UpperCamelCase         =						num_channels
								_UpperCamelCase         =						is_training
								_UpperCamelCase         =						use_labels
								_UpperCamelCase         =						hidden_size
								_UpperCamelCase         =						num_hidden_layers
								_UpperCamelCase         =						num_attention_heads
								_UpperCamelCase         =						intermediate_size
								_UpperCamelCase         =						hidden_act
								_UpperCamelCase         =						hidden_dropout_prob
								_UpperCamelCase         =						attention_probs_dropout_prob
								_UpperCamelCase         =						type_sequence_label_size
								_UpperCamelCase         =						initializer_range
								_UpperCamelCase         =						scope
								_UpperCamelCase         =						encoder_stride

								# in DeiT, the seq length equals the number of patches + 2 (we add 2 for the [CLS] and distilation tokens)
								_UpperCamelCase         =						(image_size // patch_size) ** 2
								_UpperCamelCase         =						num_patches + 2

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


								'''simple docstring'''

								_UpperCamelCase         =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

								_UpperCamelCase         =						None
								if self.use_labels:
										_UpperCamelCase         =						ids_tensor([self.batch_size]							,				self.type_sequence_label_size					)

								_UpperCamelCase         =						self.get_config()

								return config, pixel_values, labels

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


								'''simple docstring'''

								return DeiTConfig(
								    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							,				encoder_stride=self.encoder_stride							,				)

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


								'''simple docstring'''

								_UpperCamelCase         =						DeiTModel(config=__UpperCAmelCase					)
								model.to(__UpperCAmelCase					)
								model.eval()
								_UpperCamelCase         =						model(__UpperCAmelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape							,				(self.batch_size, self.seq_length, self.hidden_size)					)

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


								'''simple docstring'''

								_UpperCamelCase         =						DeiTForMaskedImageModeling(config=__UpperCAmelCase					)
								model.to(__UpperCAmelCase					)
								model.eval()
								_UpperCamelCase         =						model(__UpperCAmelCase					)
								self.parent.assertEqual(
								    result.reconstruction.shape							,				(self.batch_size, self.num_channels, self.image_size, self.image_size)					)

								# test greyscale images
								_UpperCamelCase         =						1
								_UpperCamelCase         =						DeiTForMaskedImageModeling(__UpperCAmelCase					)
								model.to(__UpperCAmelCase					)
								model.eval()

								_UpperCamelCase         =						floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
								_UpperCamelCase         =						model(__UpperCAmelCase					)
								self.parent.assertEqual(result.reconstruction.shape							,				(self.batch_size, 1, self.image_size, self.image_size)					)

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


								'''simple docstring'''

								_UpperCamelCase         =						self.type_sequence_label_size
								_UpperCamelCase         =						DeiTForImageClassification(__UpperCAmelCase					)
								model.to(__UpperCAmelCase					)
								model.eval()
								_UpperCamelCase         =						model(__UpperCAmelCase							,				labels=__UpperCAmelCase					)
								self.parent.assertEqual(result.logits.shape							,				(self.batch_size, self.type_sequence_label_size)					)

								# test greyscale images
								_UpperCamelCase         =						1
								_UpperCamelCase         =						DeiTForImageClassification(__UpperCAmelCase					)
								model.to(__UpperCAmelCase					)
								model.eval()

								_UpperCamelCase         =						floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
								_UpperCamelCase         =						model(__UpperCAmelCase							,				labels=__UpperCAmelCase					)
								self.parent.assertEqual(result.logits.shape							,				(self.batch_size, self.type_sequence_label_size)					)







						def 			A_					(      self					)       ->   Dict:


								'''simple docstring'''

								_UpperCamelCase         =						self.prepare_config_and_inputs()
								(
								    (
								    _UpperCamelCase		
								)     ,						(
								    _UpperCamelCase		
								)     ,						(
								    _UpperCamelCase		
								)     ,								
								)         =						config_and_inputs
								_UpperCamelCase         =						{"""pixel_values""": pixel_values}
								return config, inputs_dict







@require_torch
class 							lowerCAmelCase__   ( A__		,						A__		,						unittest.TestCase						):
						UpperCamelCase_				:			Any						=		(
						    (
						        DeiTModel,
						        DeiTForImageClassification,
						        DeiTForImageClassificationWithTeacher,
						        DeiTForMaskedImageModeling,
						    )
						    if is_torch_available()
						    else ()
						)
						UpperCamelCase_				:			Tuple						=		(
						    {
						        'feature-extraction': DeiTModel,
						        'image-classification': (DeiTForImageClassification, DeiTForImageClassificationWithTeacher),
						    }
						    if is_torch_available()
						    else {}
						)

						UpperCamelCase_				:			List[str]						=		False
						UpperCamelCase_				:			Optional[Any]						=		False
						UpperCamelCase_				:			Optional[int]						=		False

						def 			A_					(      self					)       ->   int:


								'''simple docstring'''

								_UpperCamelCase         =						DeiTModelTester(self					)
								_UpperCamelCase         =						ConfigTester(self							,				config_class=__UpperCAmelCase							,				has_text_modality=__UpperCAmelCase							,				hidden_size=37					)

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


								'''simple docstring'''

								self.config_tester.run_common_tests()

						@unittest.skip(reason="""DeiT does not use inputs_embeds"""					)
						def 			A_					(      self					)       ->   Tuple:


								'''simple docstring'''

								pass

						def 			A_					(      self					)       ->   str:


								'''simple docstring'''

								_UpperCamelCase     ,						_UpperCamelCase         =						self.model_tester.prepare_config_and_inputs_for_common()

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

						def 			A_					(      self					)       ->   int:


								'''simple docstring'''

								_UpperCamelCase     ,						_UpperCamelCase         =						self.model_tester.prepare_config_and_inputs_for_common()

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

										_UpperCamelCase         =						["""pixel_values"""]
										self.assertListEqual(arg_names[:1]							,				__UpperCAmelCase					)

						def 			A_					(      self					)       ->   Dict:


								'''simple docstring'''

								_UpperCamelCase         =						self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__UpperCAmelCase					)

						def 			A_					(      self					)       ->   int:


								'''simple docstring'''

								_UpperCamelCase         =						self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_image_modeling(*__UpperCAmelCase					)

						def 			A_					(      self					)       ->   Dict:


								'''simple docstring'''

								_UpperCamelCase         =						self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*__UpperCAmelCase					)

						def 			A_					(      self							,				a							,				a							,				a=False					)       ->   str:


								'''simple docstring'''

								_UpperCamelCase         =						super()._prepare_for_class(__UpperCAmelCase							,				__UpperCAmelCase							,				return_labels=__UpperCAmelCase					)

								if return_labels:
										if model_class.__name__ == "DeiTForImageClassificationWithTeacher":
												del inputs_dict["labels"]

								return inputs_dict

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


								'''simple docstring'''

								if not self.model_tester.is_training:
										return

								_UpperCamelCase     ,						_UpperCamelCase         =						self.model_tester.prepare_config_and_inputs_for_common()
								_UpperCamelCase         =						True

								for model_class in self.all_model_classes:
										# DeiTForImageClassificationWithTeacher supports inference-only
										if (
										    model_class in get_values(__UpperCAmelCase					)
										    or model_class.__name__ == "DeiTForImageClassificationWithTeacher"
										):
												continue
										_UpperCamelCase         =						model_class(__UpperCAmelCase					)
										model.to(__UpperCAmelCase					)
										model.train()
										_UpperCamelCase         =						self._prepare_for_class(__UpperCAmelCase							,				__UpperCAmelCase							,				return_labels=__UpperCAmelCase					)
										_UpperCamelCase         =						model(**__UpperCAmelCase					).loss
										loss.backward()

						def 			A_					(      self					)       ->   Dict:


								'''simple docstring'''

								_UpperCamelCase     ,						_UpperCamelCase         =						self.model_tester.prepare_config_and_inputs_for_common()
								if not self.model_tester.is_training:
										return

								_UpperCamelCase         =						False
								_UpperCamelCase         =						True

								for model_class in self.all_model_classes:
										if model_class in get_values(__UpperCAmelCase					) or not model_class.supports_gradient_checkpointing:
												continue
										# DeiTForImageClassificationWithTeacher supports inference-only
										if model_class.__name__ == "DeiTForImageClassificationWithTeacher":
												continue
										_UpperCamelCase         =						model_class(__UpperCAmelCase					)
										model.gradient_checkpointing_enable()
										model.to(__UpperCAmelCase					)
										model.train()
										_UpperCamelCase         =						self._prepare_for_class(__UpperCAmelCase							,				__UpperCAmelCase							,				return_labels=__UpperCAmelCase					)
										_UpperCamelCase         =						model(**__UpperCAmelCase					).loss
										loss.backward()

						def 			A_					(      self					)       ->   Any:


								'''simple docstring'''

								_UpperCamelCase     ,						_UpperCamelCase         =						self.model_tester.prepare_config_and_inputs_for_common()

								_UpperCamelCase         =						[
								    {"""title""": """multi_label_classification""", """num_labels""": 2, """dtype""": torch.float},
								    {"""title""": """single_label_classification""", """num_labels""": 1, """dtype""": torch.long},
								    {"""title""": """regression""", """num_labels""": 1, """dtype""": torch.float},
								]

								for model_class in self.all_model_classes:
										if (
										    model_class
										    not in [
										        *get_values(__UpperCAmelCase					),
										        *get_values(__UpperCAmelCase					),
										    ]
										    or model_class.__name__ == "DeiTForImageClassificationWithTeacher"
										):
												continue

										for problem_type in problem_types:
												with self.subTest(msg=F'Testing {model_class} with {problem_type["title"]}'					):
														_UpperCamelCase         =						problem_type["""title"""]
														_UpperCamelCase         =						problem_type["""num_labels"""]

														_UpperCamelCase         =						model_class(__UpperCAmelCase					)
														model.to(__UpperCAmelCase					)
														model.train()

														_UpperCamelCase         =						self._prepare_for_class(__UpperCAmelCase							,				__UpperCAmelCase							,				return_labels=__UpperCAmelCase					)

														if problem_type["num_labels"] > 1:
																_UpperCamelCase         =						inputs["""labels"""].unsqueeze(1					).repeat(1							,				problem_type["""num_labels"""]					)

														_UpperCamelCase         =						inputs["""labels"""].to(problem_type["""dtype"""]					)

														# This tests that we do not trigger the warning form PyTorch "Using a target size that is different
														# to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
														# they have the same size." which is a symptom something in wrong for the regression problem.
														# See https://github.com/huggingface/transformers/issues/11780
														with warnings.catch_warnings(record=__UpperCAmelCase					) as warning_list:
																_UpperCamelCase         =						model(**__UpperCAmelCase					).loss
														for w in warning_list:
																if "Using a target size that is different to the input size" in str(w.message					):
																		raise ValueError(
																		    F'Something is going wrong in the regression problem: intercepted {w.message}'					)

														loss.backward()







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


								'''simple docstring'''

								for model_name in DEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										_UpperCamelCase         =						DeiTModel.from_pretrained(__UpperCAmelCase					)
										self.assertIsNotNone(__UpperCAmelCase					)




def 				__A()		->					Any:

		"""simple docstring"""






		_UpperCamelCase         =						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""			)
		return image







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

						@cached_property
						def 			A_					(      self					)       ->   List[str]:


								'''simple docstring'''

								return (
								    DeiTImageProcessor.from_pretrained("""facebook/deit-base-distilled-patch16-224"""					)
								    if is_vision_available()
								    else None
								)

						@slow
						def 			A_					(      self					)       ->   Dict:


								'''simple docstring'''

								_UpperCamelCase         =						DeiTForImageClassificationWithTeacher.from_pretrained("""facebook/deit-base-distilled-patch16-224"""					).to(
								    __UpperCAmelCase					)

								_UpperCamelCase         =						self.default_image_processor
								_UpperCamelCase         =						prepare_img()
								_UpperCamelCase         =						image_processor(images=__UpperCAmelCase							,				return_tensors="""pt"""					).to(__UpperCAmelCase					)

								# forward pass
								with torch.no_grad():
										_UpperCamelCase         =						model(**__UpperCAmelCase					)

								# verify the logits
								_UpperCamelCase         =						torch.Size((1, 10_00)					)
								self.assertEqual(outputs.logits.shape							,				__UpperCAmelCase					)

								_UpperCamelCase         =						torch.tensor([-1.0266, 0.1912, -1.2861]					).to(__UpperCAmelCase					)

								self.assertTrue(torch.allclose(outputs.logits[0, :3]							,				__UpperCAmelCase							,				atol=1e-4					)					)







						@slow
						@require_accelerate
						@require_torch_gpu
						def 			A_					(      self					)       ->   List[str]:


								'''simple docstring'''

								_UpperCamelCase         =						DeiTModel.from_pretrained(
								    """facebook/deit-base-distilled-patch16-224"""							,				torch_dtype=torch.floataa							,				device_map="""auto"""					)
								_UpperCamelCase         =						self.default_image_processor

								_UpperCamelCase         =						prepare_img()
								_UpperCamelCase         =						image_processor(images=__UpperCAmelCase							,				return_tensors="""pt"""					)
								_UpperCamelCase         =						inputs.pixel_values.to(__UpperCAmelCase					)

								# forward pass to make sure inference works in fp16
								with torch.no_grad():
										_UpperCamelCase         =						model(__UpperCAmelCase					)






"""simple docstring"""




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_image_inputs


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import MobileViTImageProcessor





class  lowerCamelCase    (unittest.TestCase      ):

			def __init__(       self					:    Tuple     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    Any=7     ,					__UpperCAmelCase					:    Union[str, Any]=3     ,					__UpperCAmelCase					:    Any=1_8     ,					__UpperCAmelCase					:    Tuple=3_0     ,					__UpperCAmelCase					:    List[Any]=4_0_0     ,					__UpperCAmelCase					:    Dict=True     ,					__UpperCAmelCase					:    int=None     ,					__UpperCAmelCase					:    List[Any]=True     ,					__UpperCAmelCase					:    Any=None     ,					__UpperCAmelCase					:    Any=True     ,					) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   size if size is not None else {"""shortest_edge""": 2_0}
						SCREAMING_SNAKE_CASE__										=   crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}
						SCREAMING_SNAKE_CASE__										=   parent
						SCREAMING_SNAKE_CASE__										=   batch_size
						SCREAMING_SNAKE_CASE__										=   num_channels
						SCREAMING_SNAKE_CASE__										=   image_size
						SCREAMING_SNAKE_CASE__										=   min_resolution
						SCREAMING_SNAKE_CASE__										=   max_resolution
						SCREAMING_SNAKE_CASE__										=   do_resize
						SCREAMING_SNAKE_CASE__										=   size
						SCREAMING_SNAKE_CASE__										=   do_center_crop
						SCREAMING_SNAKE_CASE__										=   crop_size
						SCREAMING_SNAKE_CASE__										=   do_flip_channel_order





			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     Any:
						return {
						    "do_resize": self.do_resize,
						    "size": self.size,
						    "do_center_crop": self.do_center_crop,
						    "crop_size": self.crop_size,
						    "do_flip_channel_order": self.do_flip_channel_order,
						}





@require_torch
@require_vision
class  lowerCamelCase    (A__      ,unittest.TestCase      ):
			lowerCamelCase__ :		Tuple       		=				MobileViTImageProcessor if is_vision_available() else None

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     Any:
						SCREAMING_SNAKE_CASE__										=   MobileViTImageProcessingTester(self							)

			@property
			def        SCREAMING_SNAKE_CASE					(       self					:    List[str]							) ->     int:
						return self.image_processor_tester.prepare_image_processor_dict()

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     Optional[Any]:
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""do_resize"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""size"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""do_center_crop"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""center_crop"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""do_flip_channel_order"""							)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     List[str]:
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class.from_dict(self.image_processor_dict							)
						self.assertEqual(image_processor.size     ,					{"""shortest_edge""": 2_0}							)
						self.assertEqual(image_processor.crop_size     ,					{"""height""": 1_8, """width""": 1_8}							)

						SCREAMING_SNAKE_CASE__										=   self.image_processing_class.from_dict(self.image_processor_dict     ,					size=4_2     ,					crop_size=8_4							)
						self.assertEqual(image_processor.size     ,					{"""shortest_edge""": 4_2}							)
						self.assertEqual(image_processor.crop_size     ,					{"""height""": 8_4, """width""": 8_4}							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     Dict:
						pass

			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     List[str]:
						# Initialize image_processing
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						# create random PIL images
						SCREAMING_SNAKE_CASE__										=   prepare_image_inputs(self.image_processor_tester     ,					equal_resolution=__UpperCAmelCase							)
						for image in image_inputs:
									self.assertIsInstance(__UpperCAmelCase     ,					Image.Image							)

						# Test not batched input
						SCREAMING_SNAKE_CASE__										=   image_processing(image_inputs[0]     ,					return_tensors="""pt"""							).pixel_values
						self.assertEqual(
						    encoded_images.shape     ,					(
						        1,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["""height"""],
						        self.image_processor_tester.crop_size["""width"""],
						    )     ,					)

						# Test batched
						SCREAMING_SNAKE_CASE__										=   image_processing(__UpperCAmelCase     ,					return_tensors="""pt"""							).pixel_values
						self.assertEqual(
						    encoded_images.shape     ,					(
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["""height"""],
						        self.image_processor_tester.crop_size["""width"""],
						    )     ,					)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]							) ->     Optional[int]:
						# Initialize image_processing
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						# create random numpy tensors
						SCREAMING_SNAKE_CASE__										=   prepare_image_inputs(self.image_processor_tester     ,					equal_resolution=__UpperCAmelCase     ,					numpify=__UpperCAmelCase							)
						for image in image_inputs:
									self.assertIsInstance(__UpperCAmelCase     ,					np.ndarray							)

						# Test not batched input
						SCREAMING_SNAKE_CASE__										=   image_processing(image_inputs[0]     ,					return_tensors="""pt"""							).pixel_values
						self.assertEqual(
						    encoded_images.shape     ,					(
						        1,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["""height"""],
						        self.image_processor_tester.crop_size["""width"""],
						    )     ,					)

						# Test batched
						SCREAMING_SNAKE_CASE__										=   image_processing(__UpperCAmelCase     ,					return_tensors="""pt"""							).pixel_values
						self.assertEqual(
						    encoded_images.shape     ,					(
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["""height"""],
						        self.image_processor_tester.crop_size["""width"""],
						    )     ,					)





			def        SCREAMING_SNAKE_CASE					(       self					:    List[str]							) ->     str:
						# Initialize image_processing
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						# create random PyTorch tensors
						SCREAMING_SNAKE_CASE__										=   prepare_image_inputs(self.image_processor_tester     ,					equal_resolution=__UpperCAmelCase     ,					torchify=__UpperCAmelCase							)
						for image in image_inputs:
									self.assertIsInstance(__UpperCAmelCase     ,					torch.Tensor							)

						# Test not batched input
						SCREAMING_SNAKE_CASE__										=   image_processing(image_inputs[0]     ,					return_tensors="""pt"""							).pixel_values
						self.assertEqual(
						    encoded_images.shape     ,					(
						        1,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["""height"""],
						        self.image_processor_tester.crop_size["""width"""],
						    )     ,					)

						# Test batched
						SCREAMING_SNAKE_CASE__										=   image_processing(__UpperCAmelCase     ,					return_tensors="""pt"""							).pixel_values
						self.assertEqual(
						    encoded_images.shape     ,					(
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.crop_size["""height"""],
						        self.image_processor_tester.crop_size["""width"""],
						    )     ,					)


