
from __future__ import annotations

import inspect
import unittest

from transformers import MobileViTConfig
from transformers.file_utils import is_tf_available, is_vision_available
from transformers.testing_utils import require_tf, 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 numpy as np
					import tensorflow as tf

					from transformers import TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation, TFMobileViTModel
					from transformers.models.mobilevit.modeling_tf_mobilevit import TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import MobileViTImageProcessor


class 							lowercase   (						_UpperCamelCase  ):



		def __UpperCamelCase					(					self			)    ->   str:
				"""simple docstring"""
				UpperCamelCase            =	self.config_class(**self.inputs_dict			)
				self.parent.assertTrue(hasattr(__lowerCamelCase							, 'hidden_sizes'			)			)
				self.parent.assertTrue(hasattr(__lowerCamelCase							, 'neck_hidden_sizes'			)			)
				self.parent.assertTrue(hasattr(__lowerCamelCase							, 'num_attention_heads'			)			)






class 							lowercase   :



		def __init__(					self							, A_							, A_=13							, A_=32							, A_=2							, A_=3							, A_=640							, A_=4							, A_="silu"							, A_=3							, A_=32							, A_=0.1							, A_=0.1							, A_=0.1							, A_=0.02							, A_=True							, A_=True							, A_=10							, A_=None							, )    ->   str:
				"""simple docstring"""
				UpperCamelCase            =	parent
				UpperCamelCase            =	batch_size
				UpperCamelCase            =	image_size
				UpperCamelCase            =	patch_size
				UpperCamelCase            =	num_channels
				UpperCamelCase            =	last_hidden_size
				UpperCamelCase            =	num_attention_heads
				UpperCamelCase            =	hidden_act
				UpperCamelCase            =	conv_kernel_size
				UpperCamelCase            =	output_stride
				UpperCamelCase            =	hidden_dropout_prob
				UpperCamelCase            =	attention_probs_dropout_prob
				UpperCamelCase            =	classifier_dropout_prob
				UpperCamelCase            =	use_labels
				UpperCamelCase            =	is_training
				UpperCamelCase            =	num_labels
				UpperCamelCase            =	initializer_range
				UpperCamelCase            =	scope



		def __UpperCamelCase					(					self			)    ->   Tuple:
				"""simple docstring"""
				UpperCamelCase            =	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

				UpperCamelCase            =	None
				UpperCamelCase            =	None
				if self.use_labels:
						UpperCamelCase            =	ids_tensor([self.batch_size]							, self.num_labels			)
						UpperCamelCase            =	ids_tensor([self.batch_size, self.image_size, self.image_size]							, self.num_labels			)

				UpperCamelCase            =	self.get_config()

				return config, pixel_values, labels, pixel_labels



		def __UpperCamelCase					(					self			)    ->   int:
				"""simple docstring"""
				return MobileViTConfig(
				    image_size=self.image_size							, patch_size=self.patch_size							, num_channels=self.num_channels							, num_attention_heads=self.num_attention_heads							, hidden_act=self.hidden_act							, conv_kernel_size=self.conv_kernel_size							, output_stride=self.output_stride							, hidden_dropout_prob=self.hidden_dropout_prob							, attention_probs_dropout_prob=self.attention_probs_dropout_prob							, classifier_dropout_prob=self.classifier_dropout_prob							, initializer_range=self.initializer_range							, )



		def __UpperCamelCase					(					self							, A_							, A_							, A_							, A_			)    ->   Dict:
				"""simple docstring"""
				UpperCamelCase            =	TFMobileViTModel(config=__lowerCamelCase			)
				UpperCamelCase            =	model(__lowerCamelCase							, training=__lowerCamelCase			)
				UpperCamelCase            =	UpperCamelCase            =	self.image_size // self.output_stride
				self.parent.assertEqual(
				    result.last_hidden_state.shape							, (self.batch_size, self.last_hidden_size, expected_height, expected_width)			)



		def __UpperCamelCase					(					self							, A_							, A_							, A_							, A_			)    ->   Union[str, Any]:
				"""simple docstring"""
				UpperCamelCase            =	self.num_labels
				UpperCamelCase            =	TFMobileViTForImageClassification(__lowerCamelCase			)
				UpperCamelCase            =	model(__lowerCamelCase							, labels=__lowerCamelCase							, training=__lowerCamelCase			)
				self.parent.assertEqual(result.logits.shape							, (self.batch_size, self.num_labels)			)



		def __UpperCamelCase					(					self							, A_							, A_							, A_							, A_			)    ->   List[Any]:
				"""simple docstring"""
				UpperCamelCase            =	self.num_labels
				UpperCamelCase            =	TFMobileViTForSemanticSegmentation(__lowerCamelCase			)
				UpperCamelCase            =	UpperCamelCase            =	self.image_size // self.output_stride

				UpperCamelCase            =	model(__lowerCamelCase							, training=__lowerCamelCase			)
				self.parent.assertEqual(
				    result.logits.shape							, (self.batch_size, self.num_labels, expected_height, expected_width)			)

				UpperCamelCase            =	model(__lowerCamelCase							, labels=__lowerCamelCase							, training=__lowerCamelCase			)
				self.parent.assertEqual(
				    result.logits.shape							, (self.batch_size, self.num_labels, expected_height, expected_width)			)



		def __UpperCamelCase					(					self			)    ->   int:
				"""simple docstring"""
				UpperCamelCase            =	self.prepare_config_and_inputs()
				UpperCamelCase      ,    UpperCamelCase      ,    UpperCamelCase      ,    UpperCamelCase            =	config_and_inputs
				UpperCamelCase            =	{'pixel_values': pixel_values}
				return config, inputs_dict






@require_tf
class 							lowercase   (						_UpperCamelCase    ,  _UpperCamelCase    ,  unittest.TestCase  ):
		__lowercase			:			Any      	=							(
		    (TFMobileViTModel, TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation)
		    if is_tf_available()
		    else ()
		)
		__lowercase			:			Union[str, Any]      	=							(
		    {"""feature-extraction""": TFMobileViTModel, """image-classification""": TFMobileViTForImageClassification}
		    if is_tf_available()
		    else {}
		)

		__lowercase			:			Optional[int]      	=							False
		__lowercase			:			Optional[int]      	=							False
		__lowercase			:			Tuple      	=							False
		__lowercase			:			str      	=							False
		__lowercase			:			Any      	=							False



		def __UpperCamelCase					(					self			)    ->   List[str]:
				"""simple docstring"""
				UpperCamelCase            =	TFMobileViTModelTester(self			)
				UpperCamelCase            =	TFMobileViTConfigTester(self							, config_class=__lowerCamelCase							, has_text_modality=__lowerCamelCase			)



		def __UpperCamelCase					(					self			)    ->   Optional[int]:
				"""simple docstring"""
				self.config_tester.run_common_tests()



		@unittest.skip(reason='MobileViT does not use inputs_embeds'			)
		def __UpperCamelCase					(					self			)    ->   Any:
				"""simple docstring"""
				pass



		@unittest.skip(reason='MobileViT does not support input and output embeddings'			)
		def __UpperCamelCase					(					self			)    ->   Optional[Any]:
				"""simple docstring"""
				pass



		@unittest.skip(reason='MobileViT does not output attentions'			)
		def __UpperCamelCase					(					self			)    ->   Any:
				"""simple docstring"""
				pass



		def __UpperCamelCase					(					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(__lowerCamelCase			)
						UpperCamelCase            =	inspect.signature(model.call			)
						# signature.parameters is an OrderedDict => so arg_names order is deterministic
						UpperCamelCase            =	[*signature.parameters.keys()]

						UpperCamelCase            =	['pixel_values']
						self.assertListEqual(arg_names[:1]							, __lowerCamelCase			)



		def __UpperCamelCase					(					self			)    ->   List[str]:
				"""simple docstring"""
				UpperCamelCase            =	self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*__lowerCamelCase			)



		def __UpperCamelCase					(					self			)    ->   Dict:
				"""simple docstring"""
				def check_hidden_states_output(A_							, A_							, A_			):
						UpperCamelCase            =	model_class(__lowerCamelCase			)

						UpperCamelCase            =	model(**self._prepare_for_class(__lowerCamelCase							, __lowerCamelCase			)			)

						UpperCamelCase            =	outputs.hidden_states

						UpperCamelCase            =	5
						self.assertEqual(len(__lowerCamelCase			)							, __lowerCamelCase			)

						# MobileViT's feature maps are of shape (batch_size, num_channels, height, width)
						# with the width and height being successively divided by 2.
						UpperCamelCase            =	2
						for i in range(len(__lowerCamelCase			)			):
								self.assertListEqual(
								    list(hidden_states[i].shape[-2:]			)							, [self.model_tester.image_size // divisor, self.model_tester.image_size // divisor]							, )
								divisor *= 2

						self.assertEqual(self.model_tester.output_stride							, divisor // 2			)

				UpperCamelCase      ,    UpperCamelCase            =	self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
						UpperCamelCase            =	True
						check_hidden_states_output(__lowerCamelCase							, __lowerCamelCase							, __lowerCamelCase			)

						# check that output_hidden_states also work using config
						del inputs_dict["output_hidden_states"]
						UpperCamelCase            =	True

						check_hidden_states_output(__lowerCamelCase							, __lowerCamelCase							, __lowerCamelCase			)



		def __UpperCamelCase					(					self			)    ->   Union[str, Any]:
				"""simple docstring"""
				UpperCamelCase            =	self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*__lowerCamelCase			)



		def __UpperCamelCase					(					self			)    ->   Optional[int]:
				"""simple docstring"""
				UpperCamelCase            =	self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_semantic_segmentation(*__lowerCamelCase			)



		@unittest.skipIf(
		    not is_tf_available() or len(tf.config.list_physical_devices('GPU'			)			) == 0							, reason='TF does not support backprop for grouped convolutions on CPU.'							, )
		def __UpperCamelCase					(					self			)    ->   Any:
				"""simple docstring"""
				super().test_dataset_conversion()



		def __UpperCamelCase					(					self							, A_							, A_							, A_=2e-1							, A_=2e-1			)    ->   int:
				"""simple docstring"""
				self.assertTrue(np.allclose(__lowerCamelCase							, __lowerCamelCase							, atol=__lowerCamelCase							, rtol=__lowerCamelCase			)			)



		@unittest.skipIf(
		    not is_tf_available() or len(tf.config.list_physical_devices('GPU'			)			) == 0							, reason='TF does not support backprop for grouped convolutions on CPU.'							, )
		@slow
		def __UpperCamelCase					(					self			)    ->   Optional[Any]:
				"""simple docstring"""
				UpperCamelCase      ,    UpperCamelCase            =	self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
						# Since `TFMobileViTModel` cannot operate with the default `fit()` method.
						if model_class.__name__ != "TFMobileViTModel":
								UpperCamelCase            =	model_class(__lowerCamelCase			)
								if getattr(__lowerCamelCase							, 'hf_compute_loss'							, __lowerCamelCase			):
										super().test_keras_fit()



		def __UpperCamelCase					(					self			)    ->   Tuple:
				"""simple docstring"""
				UpperCamelCase      ,    UpperCamelCase            =	self.model_tester.prepare_config_and_inputs_for_common()
				for model_class in self.all_model_classes:
						# set an ignore index to correctly test the masked loss used in
						# `TFMobileViTForSemanticSegmentation`.
						if model_class.__name__ != "TFMobileViTForSemanticSegmentation":
								UpperCamelCase            =	5

						UpperCamelCase            =	model_class(__lowerCamelCase			)
						if getattr(__lowerCamelCase							, 'hf_compute_loss'							, __lowerCamelCase			):
								# The number of elements in the loss should be the same as the number of elements in the label
								UpperCamelCase            =	self._prepare_for_class(inputs_dict.copy()							, __lowerCamelCase							, return_labels=__lowerCamelCase			)
								UpperCamelCase            =	prepared_for_class[
								    sorted(prepared_for_class.keys() - inputs_dict.keys()							, reverse=__lowerCamelCase			)[0]
								]
								UpperCamelCase            =	added_label.shape.as_list()[:1]

								# Test that model correctly compute the loss with kwargs
								UpperCamelCase            =	self._prepare_for_class(inputs_dict.copy()							, __lowerCamelCase							, return_labels=__lowerCamelCase			)
								UpperCamelCase            =	{'input_ids', 'pixel_values', 'input_features'}
								UpperCamelCase            =	possible_input_names.intersection(set(__lowerCamelCase			)			).pop()
								UpperCamelCase            =	prepared_for_class.pop(__lowerCamelCase			)

								UpperCamelCase            =	model(__lowerCamelCase							, **__lowerCamelCase			)[0]
								self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]			)

								# Test that model correctly compute the loss when we mask some positions
								UpperCamelCase            =	self._prepare_for_class(inputs_dict.copy()							, __lowerCamelCase							, return_labels=__lowerCamelCase			)
								UpperCamelCase            =	{'input_ids', 'pixel_values', 'input_features'}
								UpperCamelCase            =	possible_input_names.intersection(set(__lowerCamelCase			)			).pop()
								UpperCamelCase            =	prepared_for_class.pop(__lowerCamelCase			)
								if "labels" in prepared_for_class:
										UpperCamelCase            =	prepared_for_class['labels'].numpy()
										if len(labels.shape			) > 1 and labels.shape[1] != 1:
												# labels[0] = -100
												UpperCamelCase            =	tf.convert_to_tensor(__lowerCamelCase			)
												UpperCamelCase            =	model(__lowerCamelCase							, **__lowerCamelCase			)[0]
												self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]			)
												self.assertTrue(not np.any(np.isnan(loss.numpy()			)			)			)

                # Test that model correctly compute the loss with a dict
								UpperCamelCase            =	self._prepare_for_class(inputs_dict.copy()							, __lowerCamelCase							, return_labels=__lowerCamelCase			)
								UpperCamelCase            =	model(__lowerCamelCase			)[0]
								self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]			)

								# Test that model correctly compute the loss with a tuple
								UpperCamelCase            =	self._prepare_for_class(inputs_dict.copy()							, __lowerCamelCase							, return_labels=__lowerCamelCase			)

								# Get keys that were added with the _prepare_for_class function
								UpperCamelCase            =	prepared_for_class.keys() - inputs_dict.keys()
								UpperCamelCase            =	inspect.signature(model.call			).parameters
								UpperCamelCase            =	list(signature.keys()			)

								# Create a dictionary holding the location of the tensors in the tuple
								UpperCamelCase            =	{0: input_name}
								for label_key in label_keys:
										UpperCamelCase            =	signature_names.index(__lowerCamelCase			)
										UpperCamelCase            =	label_key
								UpperCamelCase            =	sorted(tuple_index_mapping.items()			)
								# Initialize a list with their default values, update the values and convert to a tuple
								UpperCamelCase            =	[]

								for name in signature_names:
										if name != "kwargs":
												list_input.append(signature[name].default			)

								for index, value in sorted_tuple_index_mapping:
										UpperCamelCase            =	prepared_for_class[value]

								UpperCamelCase            =	tuple(__lowerCamelCase			)

								# Send to model
								UpperCamelCase            =	model(tuple_input[:-1]			)[0]

								self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]			)



		@slow
		def __UpperCamelCase					(					self			)    ->   Optional[Any]:
				"""simple docstring"""
				for model_name in TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						UpperCamelCase            =	TFMobileViTModel.from_pretrained(__lowerCamelCase			)
						self.assertIsNotNone(__lowerCamelCase			)






def  A			(   )  ->    List[str]:
		'''simple docstring'''

		UpperCamelCase            =	Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'					)
		return image


@require_tf
class 							lowercase   (						unittest.TestCase  ):



		@slow
		def __UpperCamelCase					(					self			)    ->   str:
				"""simple docstring"""
				UpperCamelCase            =	TFMobileViTForImageClassification.from_pretrained('apple/mobilevit-xx-small'			)

				UpperCamelCase            =	MobileViTImageProcessor.from_pretrained('apple/mobilevit-xx-small'			)
				UpperCamelCase            =	prepare_img()
				UpperCamelCase            =	image_processor(images=__lowerCamelCase							, return_tensors='tf'			)

				# forward pass
				UpperCamelCase            =	model(**__lowerCamelCase							, training=__lowerCamelCase			)

				# verify the logits
				UpperCamelCase            =	tf.TensorShape((1, 1_000)			)
				self.assertEqual(outputs.logits.shape							, __lowerCamelCase			)

				UpperCamelCase            =	tf.constant([-1.9364, -1.2327, -0.4653]			)

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



		@slow
		def __UpperCamelCase					(					self			)    ->   List[str]:
				"""simple docstring"""
				# `from_pt` will be removed
				UpperCamelCase            =	TFMobileViTForSemanticSegmentation.from_pretrained('apple/deeplabv3-mobilevit-xx-small'			)

				UpperCamelCase            =	MobileViTImageProcessor.from_pretrained('apple/deeplabv3-mobilevit-xx-small'			)

				UpperCamelCase            =	prepare_img()
				UpperCamelCase            =	image_processor(images=__lowerCamelCase							, return_tensors='tf'			)

				# forward pass
				UpperCamelCase            =	model(inputs.pixel_values							, training=__lowerCamelCase			)
				UpperCamelCase            =	outputs.logits

				# verify the logits
				UpperCamelCase            =	tf.TensorShape((1, 21, 32, 32)			)
				self.assertEqual(logits.shape							, __lowerCamelCase			)

				UpperCamelCase            =	tf.constant(
				    [
				        [[6.9713, 6.9786, 7.2422], [7.2893, 7.2825, 7.4446], [7.6580, 7.8797, 7.9420]],
				        [[-10.6869, -10.3250, -10.3471], [-10.4228, -9.9868, -9.7132], [-11.0405, -11.0221, -10.7318]],
				        [[-3.3089, -2.8539, -2.6740], [-3.2706, -2.5621, -2.5108], [-3.2534, -2.6615, -2.6651]],
				    ]			)

				tf.debugging.assert_near(logits[0, :3, :3, :3]							, __lowerCamelCase							, rtol=1e-4							, 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


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import SwinaSRImageProcessor
		from transformers.image_transforms import get_image_size




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



				def __init__( self							:	Union[str, Any]   , __lowerCamelCase							:	List[str]   , __lowerCamelCase							:	List[str]=7   , __lowerCamelCase							:	int=3   , __lowerCamelCase							:	Any=18   , __lowerCamelCase							:	Optional[int]=30   , __lowerCamelCase							:	Union[str, Any]=4_00   , __lowerCamelCase							:	Optional[int]=True   , __lowerCamelCase							:	List[str]=1 / 2_55   , __lowerCamelCase							:	Any=True   , __lowerCamelCase							:	Optional[int]=8   , )   ->	Optional[Any]:
							a       =     parent
							a       =     batch_size
							a       =     num_channels
							a       =     image_size
							a       =     min_resolution
							a       =     max_resolution
							a       =     do_rescale
							a       =     rescale_factor
							a       =     do_pad
							a       =     pad_size





				def 				__UpperCAmelCase				( self							:	List[Any]				)   ->	Optional[int]:
							return {
							    "do_rescale": self.do_rescale,
							    "rescale_factor": self.rescale_factor,
							    "do_pad": self.do_pad,
							    "pad_size": self.pad_size,
							}





				def 				__UpperCAmelCase				( self							:	List[Any]   , __lowerCamelCase							:	Optional[int]=False   , __lowerCamelCase							:	Any=False   , __lowerCamelCase							:	List[Any]=False				)   ->	List[Any]:
							assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

							if equal_resolution:
										a       =     []
										for i in range(self.batch_size				):
													image_inputs.append(
													    np.random.randint(
													        2_55   , size=(self.num_channels, self.max_resolution, self.max_resolution)   , dtype=np.uinta				)				)
							else:
										a       =     []
										for i in range(self.batch_size				):
													a       ,						a       =     np.random.choice(np.arange(self.min_resolution   , self.max_resolution				)   , 2				)
													image_inputs.append(np.random.randint(2_55   , size=(self.num_channels, width, height)   , dtype=np.uinta				)				)

							if not numpify and not torchify:
										# PIL expects the channel dimension as last dimension
										a       =     [Image.fromarray(np.moveaxis(__lowerCamelCase   , 0   , -1				)				) for x in image_inputs]

							if torchify:
										a       =     [torch.from_numpy(__lowerCamelCase				) for x in image_inputs]

							return image_inputs




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



				SCREAMING_SNAKE_CASE_			:				Optional[Any]									=   SwinaSRImageProcessor if is_vision_available() else None





				def 				__UpperCAmelCase				( self							:	Dict				)   ->	Tuple:
							a       =     SwinaSRImageProcessingTester(self				)





				@property
				def 				__UpperCAmelCase				( self							:	Optional[Any]				)   ->	List[Any]:
							return self.image_processor_tester.prepare_image_processor_dict()





				def 				__UpperCAmelCase				( self							:	Dict				)   ->	Tuple:
							a       =     self.image_processing_class(**self.image_processor_dict				)
							self.assertTrue(hasattr(__lowerCamelCase   , "do_rescale"				)				)
							self.assertTrue(hasattr(__lowerCamelCase   , "rescale_factor"				)				)
							self.assertTrue(hasattr(__lowerCamelCase   , "do_pad"				)				)
							self.assertTrue(hasattr(__lowerCamelCase   , "pad_size"				)				)





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





				def 				__UpperCAmelCase				( self							:	int   , __lowerCamelCase							:	int				)   ->	Dict:
							a       ,						a       =     get_image_size(__lowerCamelCase				)
							a       =     self.image_processor_tester.pad_size

							a       =     (old_height // size + 1) * size - old_height
							a       =     (old_width // size + 1) * size - old_width
							return old_height + pad_height, old_width + pad_width





				def 				__UpperCAmelCase				( self							:	Any				)   ->	Dict:
							# Initialize image_processor
							a       =     self.image_processing_class(**self.image_processor_dict				)
							# create random PIL images
							a       =     self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase				)
							for image in image_inputs:
										self.assertIsInstance(__lowerCamelCase   , Image.Image				)

							# Test not batched input
							a       =     image_processor(image_inputs[0]   , return_tensors="pt"				).pixel_values
							a       ,						a       =     self.calculate_expected_size(np.array(image_inputs[0]				)				)
							self.assertEqual(
							    encoded_images.shape   , (
							        1,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    )   , )





				def 				__UpperCAmelCase				( self							:	Optional[int]				)   ->	Union[str, Any]:
							# Initialize image_processor
							a       =     self.image_processing_class(**self.image_processor_dict				)
							# create random numpy tensors
							a       =     self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase   , numpify=__lowerCamelCase				)
							for image in image_inputs:
										self.assertIsInstance(__lowerCamelCase   , np.ndarray				)

							# Test not batched input
							a       =     image_processor(image_inputs[0]   , return_tensors="pt"				).pixel_values
							a       ,						a       =     self.calculate_expected_size(image_inputs[0]				)
							self.assertEqual(
							    encoded_images.shape   , (
							        1,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    )   , )





				def 				__UpperCAmelCase				( self							:	Optional[Any]				)   ->	int:
							# Initialize image_processor
							a       =     self.image_processing_class(**self.image_processor_dict				)
							# create random PyTorch tensors
							a       =     self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase   , torchify=__lowerCamelCase				)
							for image in image_inputs:
										self.assertIsInstance(__lowerCamelCase   , torch.Tensor				)

							# Test not batched input
							a       =     image_processor(image_inputs[0]   , return_tensors="pt"				).pixel_values
							a       ,						a       =     self.calculate_expected_size(image_inputs[0]				)
							self.assertEqual(
							    encoded_images.shape   , (
							        1,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    )   , )






