






import collections
import inspect
import unittest

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

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


if is_torch_available():
				import torch
				from torch import nn

				from transformers import DinatBackbone, DinatForImageClassification, DinatModel
				from transformers.models.dinat.modeling_dinat import DINAT_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
				from PIL import Image

				from transformers import AutoImageProcessor







class  lowerCamelCase_   :
							def __init__(  self						:    Union[str, Any]							,__lowerCamelCase						:    Tuple							,__lowerCamelCase						:    List[Any]=13							,__lowerCamelCase						:    int=64							,__lowerCamelCase						:    Optional[Any]=4							,__lowerCamelCase						:    Optional[Any]=3							,__lowerCamelCase						:    Dict=16							,__lowerCamelCase						:    Dict=[1, 2, 1]							,__lowerCamelCase						:    List[str]=[2, 4, 8]							,__lowerCamelCase						:    Tuple=3							,__lowerCamelCase						:    Tuple=[[3], [1, 2], [1]]							,__lowerCamelCase						:    List[Any]=2.0							,__lowerCamelCase						:    Optional[Any]=True							,__lowerCamelCase						:    int=0.0							,__lowerCamelCase						:    str=0.0							,__lowerCamelCase						:    int=0.1							,__lowerCamelCase						:    Any="gelu"							,__lowerCamelCase						:    Any=True							,__lowerCamelCase						:    str=0.02							,__lowerCamelCase						:    Tuple=1e-5							,__lowerCamelCase						:    List[Any]=True							,__lowerCamelCase						:    Optional[int]=None							,__lowerCamelCase						:    Optional[Any]=True							,__lowerCamelCase						:    List[str]=10							,__lowerCamelCase						:    str=["stage1", "stage2"]							,__lowerCamelCase						:    Tuple=[1, 2]							,):





								'''simple docstring'''



								a				=	parent
								a				=	batch_size
								a				=	image_size
								a				=	patch_size
								a				=	num_channels
								a				=	embed_dim
								a				=	depths
								a				=	num_heads
								a				=	kernel_size
								a				=	dilations
								a				=	mlp_ratio
								a				=	qkv_bias
								a				=	hidden_dropout_prob
								a				=	attention_probs_dropout_prob
								a				=	drop_path_rate
								a				=	hidden_act
								a				=	patch_norm
								a				=	layer_norm_eps
								a				=	initializer_range
								a				=	is_training
								a				=	scope
								a				=	use_labels
								a				=	num_labels
								a				=	out_features
								a				=	out_indices
							def        SCREAMING_SNAKE_CASE_       (  self						:    str    ):





								'''simple docstring'''



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

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

								a				=	self.get_config()

								return config, pixel_values, labels
							def        SCREAMING_SNAKE_CASE_       (  self						:    Any    ):





								'''simple docstring'''



								return DinatConfig(
								    num_labels=self.num_labels							,image_size=self.image_size							,patch_size=self.patch_size							,num_channels=self.num_channels							,embed_dim=self.embed_dim							,depths=self.depths							,num_heads=self.num_heads							,kernel_size=self.kernel_size							,dilations=self.dilations							,mlp_ratio=self.mlp_ratio							,qkv_bias=self.qkv_bias							,hidden_dropout_prob=self.hidden_dropout_prob							,attention_probs_dropout_prob=self.attention_probs_dropout_prob							,drop_path_rate=self.drop_path_rate							,hidden_act=self.hidden_act							,patch_norm=self.patch_norm							,layer_norm_eps=self.layer_norm_eps							,initializer_range=self.initializer_range							,out_features=self.out_features							,out_indices=self.out_indices							,)
							def        SCREAMING_SNAKE_CASE_       (  self						:    str							,__lowerCamelCase						:    Optional[Any]							,__lowerCamelCase						:    Optional[int]							,__lowerCamelCase						:    List[Any]    ):





								'''simple docstring'''



								a				=	DinatModel(config=__lowerCamelCase    )
								model.to(__lowerCamelCase    )
								model.eval()
								a				=	model(__lowerCamelCase    )

								a				=	(config.image_size // config.patch_size) // (2 ** (len(config.depths    ) - 1))
								a				=	int(config.embed_dim * 2 ** (len(config.depths    ) - 1)    )

								self.parent.assertEqual(
								    result.last_hidden_state.shape							,(self.batch_size, expected_height, expected_width, expected_dim)    )
							def        SCREAMING_SNAKE_CASE_       (  self						:    Union[str, Any]							,__lowerCamelCase						:    Union[str, Any]							,__lowerCamelCase						:    str							,__lowerCamelCase						:    Optional[int]    ):





								'''simple docstring'''



								a				=	DinatForImageClassification(__lowerCamelCase    )
								model.to(__lowerCamelCase    )
								model.eval()
								a				=	model(__lowerCamelCase							,labels=__lowerCamelCase    )
								self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.num_labels)    )

								# test greyscale images
								a				=	1
								a				=	DinatForImageClassification(__lowerCamelCase    )
								model.to(__lowerCamelCase    )
								model.eval()

								a				=	floats_tensor([self.batch_size, 1, self.image_size, self.image_size]    )
								a				=	model(__lowerCamelCase    )
								self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.num_labels)    )
							def        SCREAMING_SNAKE_CASE_       (  self						:    Optional[Any]							,__lowerCamelCase						:    Optional[int]							,__lowerCamelCase						:    Any							,__lowerCamelCase						:    List[str]    ):





								'''simple docstring'''



								a				=	DinatBackbone(config=__lowerCamelCase    )
								model.to(__lowerCamelCase    )
								model.eval()
								a				=	model(__lowerCamelCase    )

								# verify hidden states
								self.parent.assertEqual(len(result.feature_maps    )							,len(config.out_features    )    )
								self.parent.assertListEqual(list(result.feature_maps[0].shape    )							,[self.batch_size, model.channels[0], 16, 16]    )

								# verify channels
								self.parent.assertEqual(len(model.channels    )							,len(config.out_features    )    )

								# verify backbone works with out_features=None
								a				=	None
								a				=	DinatBackbone(config=__lowerCamelCase    )
								model.to(__lowerCamelCase    )
								model.eval()
								a				=	model(__lowerCamelCase    )

								# verify feature maps
								self.parent.assertEqual(len(result.feature_maps    )							,1    )
								self.parent.assertListEqual(list(result.feature_maps[0].shape    )							,[self.batch_size, model.channels[-1], 4, 4]    )

								# verify channels
								self.parent.assertEqual(len(model.channels    )							,1    )




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





								'''simple docstring'''



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







@require_natten
@require_torch
class  lowerCamelCase_   (		__lowercase       ,  __lowercase       ,  unittest.TestCase   ):
							SCREAMING_SNAKE_CASE_     =	(
							    (
							        DinatModel,
							        DinatForImageClassification,
							        DinatBackbone,
							    )
							    if is_torch_available()
							    else ()
							)
							SCREAMING_SNAKE_CASE_     =	(
							    {'feature-extraction': DinatModel, 'image-classification': DinatForImageClassification}
							    if is_torch_available()
							    else {}
							)
							SCREAMING_SNAKE_CASE_     =	False

							SCREAMING_SNAKE_CASE_     =	False
							SCREAMING_SNAKE_CASE_     =	False
							SCREAMING_SNAKE_CASE_     =	False
							SCREAMING_SNAKE_CASE_     =	False
							def        SCREAMING_SNAKE_CASE_       (  self						:    str    ):





								'''simple docstring'''



								a				=	DinatModelTester(self    )
								a				=	ConfigTester(self							,config_class=__lowerCamelCase							,embed_dim=37    )
							def        SCREAMING_SNAKE_CASE_       (  self						:    Optional[Any]    ):





								'''simple docstring'''



								self.create_and_test_config_common_properties()
								self.config_tester.create_and_test_config_to_json_string()
								self.config_tester.create_and_test_config_to_json_file()
								self.config_tester.create_and_test_config_from_and_save_pretrained()
								self.config_tester.create_and_test_config_with_num_labels()
								self.config_tester.check_config_can_be_init_without_params()
								self.config_tester.check_config_arguments_init()
							def        SCREAMING_SNAKE_CASE_       (  self						:    Any    ):





								'''simple docstring'''



								return
							def        SCREAMING_SNAKE_CASE_       (  self						:    str    ):





								'''simple docstring'''



								a				=	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__lowerCamelCase    )
							def        SCREAMING_SNAKE_CASE_       (  self						:    List[Any]    ):





								'''simple docstring'''



								a				=	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*__lowerCamelCase    )
							def        SCREAMING_SNAKE_CASE_       (  self						:    List[Any]    ):





								'''simple docstring'''



								a				=	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_backbone(*__lowerCamelCase    )
							@unittest.skip(reason='''Dinat does not use inputs_embeds'''    )
							def        SCREAMING_SNAKE_CASE_       (  self						:    List[str]    ):





								'''simple docstring'''



								pass
							@unittest.skip(reason='''Dinat does not use feedforward chunking'''    )
							def        SCREAMING_SNAKE_CASE_       (  self						:    Dict    ):





								'''simple docstring'''



								pass
							def        SCREAMING_SNAKE_CASE_       (  self						:    str    ):





								'''simple docstring'''



								a				=	self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
									a				=	model_class(__lowerCamelCase    )
									self.assertIsInstance(model.get_input_embeddings()							,(nn.Module)    )
									a				=	model.get_output_embeddings()
									self.assertTrue(x is None or isinstance(__lowerCamelCase							,nn.Linear    )    )
							def        SCREAMING_SNAKE_CASE_       (  self						:    List[Any]    ):





								'''simple docstring'''



								a				=	self.model_tester.prepare_config_and_inputs_for_common()

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

									a				=	["pixel_values"]
									self.assertListEqual(arg_names[:1]							,__lowerCamelCase    )
							def        SCREAMING_SNAKE_CASE_       (  self						:    List[Any]    ):





								'''simple docstring'''



								self.skipTest('''Dinat\'s attention operation is handled entirely by NATTEN.'''    )
							def        SCREAMING_SNAKE_CASE_       (  self						:    List[Any]							,__lowerCamelCase						:    List[str]							,__lowerCamelCase						:    int							,__lowerCamelCase						:    Tuple							,__lowerCamelCase						:    Any    ):





								'''simple docstring'''



								a				=	model_class(__lowerCamelCase    )
								model.to(__lowerCamelCase    )
								model.eval()

								with torch.no_grad():
									a				=	model(**self._prepare_for_class(__lowerCamelCase							,__lowerCamelCase    )    )

								a				=	outputs.hidden_states

								a				=	getattr(
								    self.model_tester							,'''expected_num_hidden_layers'''							,len(self.model_tester.depths    ) + 1    )
								self.assertEqual(len(__lowerCamelCase    )							,__lowerCamelCase    )

								# Dinat has a different seq_length
								a				=	(
								    config.patch_size
								    if isinstance(config.patch_size							,collections.abc.Iterable    )
								    else (config.patch_size, config.patch_size)
								)

								a				=	image_size[0] // patch_size[0]
								a				=	image_size[1] // patch_size[1]

								self.assertListEqual(
								    list(hidden_states[0].shape[-3:]    )							,[height, width, self.model_tester.embed_dim]							,)

								if model_class.__name__ != "DinatBackbone":
									a				=	outputs.reshaped_hidden_states
									self.assertEqual(len(__lowerCamelCase    )							,__lowerCamelCase    )

									a				=	reshaped_hidden_states[0].shape
									a				=	(
									    reshaped_hidden_states[0].view(__lowerCamelCase							,__lowerCamelCase							,__lowerCamelCase							,__lowerCamelCase    ).permute(0							,2							,3							,1    )
									)
									self.assertListEqual(
									    list(reshaped_hidden_states.shape[-3:]    )							,[height, width, self.model_tester.embed_dim]							,)
							def        SCREAMING_SNAKE_CASE_       (  self						:    List[Any]    ):





								'''simple docstring'''



								a				=	self.model_tester.prepare_config_and_inputs_for_common()

								a				=	(
								    self.model_tester.image_size
								    if isinstance(self.model_tester.image_size							,collections.abc.Iterable    )
								    else (self.model_tester.image_size, self.model_tester.image_size)
								)

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

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

									self.check_hidden_states_output(__lowerCamelCase							,__lowerCamelCase							,__lowerCamelCase							,__lowerCamelCase    )
							@slow
							def        SCREAMING_SNAKE_CASE_       (  self						:    int    ):





								'''simple docstring'''



								for model_name in DINAT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									a				=	DinatModel.from_pretrained(__lowerCamelCase    )
									self.assertIsNotNone(__lowerCamelCase    )




							def        SCREAMING_SNAKE_CASE_       (  self						:    int    ):





								'''simple docstring'''



								a				=	self.model_tester.prepare_config_and_inputs_for_common()

								a				=	_config_zero_init(__lowerCamelCase    )
								for model_class in self.all_model_classes:
									a				=	model_class(config=__lowerCamelCase    )
									for name, param in model.named_parameters():
										if "embeddings" not in name and param.requires_grad:
											self.assertIn(
											    ((param.data.mean() * 1e9).round() / 1e9).item()							,[0.0, 1.0]							,msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""							,)







@require_natten
@require_vision
@require_torch
class  lowerCamelCase_   (		unittest.TestCase   ):
							@cached_property
							def        SCREAMING_SNAKE_CASE_       (  self						:    List[Any]    ):





								'''simple docstring'''



								return AutoImageProcessor.from_pretrained('''shi-labs/dinat-mini-in1k-224'''    ) if is_vision_available() else None




							@slow
							def        SCREAMING_SNAKE_CASE_       (  self						:    Union[str, Any]    ):





								'''simple docstring'''



								a				=	DinatForImageClassification.from_pretrained('''shi-labs/dinat-mini-in1k-224'''    ).to(__lowerCamelCase    )
								a				=	self.default_image_processor

								a				=	Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''    )
								a				=	image_processor(images=__lowerCamelCase							,return_tensors='''pt'''    ).to(__lowerCamelCase    )

								# forward pass
								with torch.no_grad():
									a				=	model(**__lowerCamelCase    )

								# verify the logits
								a				=	torch.Size((1, 10_00)    )
								self.assertEqual(outputs.logits.shape							,__lowerCamelCase    )
								a				=	torch.tensor([-0.1_545, -0.7_667, 0.4_642]    ).to(__lowerCamelCase    )
								self.assertTrue(torch.allclose(outputs.logits[0, :3]							,__lowerCamelCase							,atol=1e-4    )    )







@require_torch
@require_natten
class  lowerCamelCase_   (		unittest.TestCase       ,  __lowercase   ):
							SCREAMING_SNAKE_CASE_     =	(DinatBackbone,) if is_torch_available() else ()
							SCREAMING_SNAKE_CASE_     =	DinatConfig
							def        SCREAMING_SNAKE_CASE_       (  self						:    Optional[int]    ):





								'''simple docstring'''



								a				=	DinatModelTester(self    )












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 CLIPImageProcessor





class 	lowerCAmelCase__(       unittest.TestCase			):






       '''simple docstring'''


       def __init__(					self			,  __lowerCamelCase			,  __lowerCamelCase=7			,  __lowerCamelCase=3			,  __lowerCamelCase=1_8			,  __lowerCamelCase=3_0			,  __lowerCamelCase=4_0_0			,  __lowerCamelCase=True			,  __lowerCamelCase=None			,  __lowerCamelCase=True			,  __lowerCamelCase=None			,  __lowerCamelCase=True			,  __lowerCamelCase=[0.4814_5466, 0.457_8275, 0.4082_1073]			,  __lowerCamelCase=[0.2686_2954, 0.2613_0258, 0.2757_7711]			,  __lowerCamelCase=True			,  )	->   List[Any]:
            _SCREAMING_SNAKE_CASE				:		Optional[Any]  			=							size if size is not None else {"shortest_edge": 2_0}
            _SCREAMING_SNAKE_CASE				:		int  			=							crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}
            _SCREAMING_SNAKE_CASE				:		str  			=							parent
            _SCREAMING_SNAKE_CASE				:		Optional[Any]  			=							batch_size
            _SCREAMING_SNAKE_CASE				:		Optional[int]  			=							num_channels
            _SCREAMING_SNAKE_CASE				:		Any  			=							image_size
            _SCREAMING_SNAKE_CASE				:		Any  			=							min_resolution
            _SCREAMING_SNAKE_CASE				:		int  			=							max_resolution
            _SCREAMING_SNAKE_CASE				:		List[str]  			=							do_resize
            _SCREAMING_SNAKE_CASE				:		List[Any]  			=							size
            _SCREAMING_SNAKE_CASE				:		int  			=							do_center_crop
            _SCREAMING_SNAKE_CASE				:		Dict  			=							crop_size
            _SCREAMING_SNAKE_CASE				:		int  			=							do_normalize
            _SCREAMING_SNAKE_CASE				:		List[Any]  			=							image_mean
            _SCREAMING_SNAKE_CASE				:		List[str]  			=							image_std
            _SCREAMING_SNAKE_CASE				:		Tuple  			=							do_convert_rgb




       def 			UpperCamelCase_	(					self							)	->   List[str]:
            return {
                "do_resize": self.do_resize,
                "size": self.size,
                "do_center_crop": self.do_center_crop,
                "crop_size": self.crop_size,
                "do_normalize": self.do_normalize,
                "image_mean": self.image_mean,
                "image_std": self.image_std,
                "do_convert_rgb": self.do_convert_rgb,
            }







       def 			UpperCamelCase_	(					self			,  __lowerCamelCase=False			,  __lowerCamelCase=False			,  __lowerCamelCase=False							)	->   Tuple:
            assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

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

            return image_inputs





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






       '''simple docstring'''


       __snake_case       	=			CLIPImageProcessor if is_vision_available() else None




       def 			UpperCamelCase_	(					self							)	->   Dict:
            _SCREAMING_SNAKE_CASE				:		str  			=							CLIPImageProcessingTester(self							)




       @property
       def 			UpperCamelCase_	(					self							)	->   int:
            return self.image_processor_tester.prepare_image_processor_dict()




       def 			UpperCamelCase_	(					self							)	->   int:
            _SCREAMING_SNAKE_CASE				:		List[str]  			=							self.image_processing_class(**self.image_processor_dict							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "do_resize"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "size"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "do_center_crop"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "center_crop"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "do_normalize"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "image_mean"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "image_std"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "do_convert_rgb"							)							)




       def 			UpperCamelCase_	(					self							)	->   Optional[Any]:
            _SCREAMING_SNAKE_CASE				:		Optional[int]  			=							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				:		Optional[int]  			=							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 			UpperCamelCase_	(					self							)	->   Tuple:
            pass




       def 			UpperCamelCase_	(					self							)	->   str:
            # Initialize image_processing
            _SCREAMING_SNAKE_CASE				:		str  			=							self.image_processing_class(**self.image_processor_dict							)
            # create random PIL images
            _SCREAMING_SNAKE_CASE				:		Optional[Any]  			=							self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase							)
            for image in image_inputs:
                 self.assertIsInstance(__lowerCamelCase			,  Image.Image							)

            # Test not batched input
            _SCREAMING_SNAKE_CASE				:		int  			=							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				:		List[str]  			=							image_processing(__lowerCamelCase			,  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 			UpperCamelCase_	(					self							)	->   Union[str, Any]:
            # Initialize image_processing
            _SCREAMING_SNAKE_CASE				:		List[str]  			=							self.image_processing_class(**self.image_processor_dict							)
            # create random numpy tensors
            _SCREAMING_SNAKE_CASE				:		Union[str, Any]  			=							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
            _SCREAMING_SNAKE_CASE				:		Dict  			=							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				:		Union[str, Any]  			=							image_processing(__lowerCamelCase			,  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 			UpperCamelCase_	(					self							)	->   Any:
            # Initialize image_processing
            _SCREAMING_SNAKE_CASE				:		str  			=							self.image_processing_class(**self.image_processor_dict							)
            # create random PyTorch tensors
            _SCREAMING_SNAKE_CASE				:		int  			=							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
            _SCREAMING_SNAKE_CASE				:		List[str]  			=							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				:		List[str]  			=							image_processing(__lowerCamelCase			,  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"],
                )			,  )





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






       '''simple docstring'''


       __snake_case       	=			CLIPImageProcessor if is_vision_available() else None




       def 			UpperCamelCase_	(					self							)	->   int:
            _SCREAMING_SNAKE_CASE				:		Any  			=							CLIPImageProcessingTester(self			,  num_channels=4							)
            _SCREAMING_SNAKE_CASE				:		Any  			=							3




       @property
       def 			UpperCamelCase_	(					self							)	->   Dict:
            return self.image_processor_tester.prepare_image_processor_dict()




       def 			UpperCamelCase_	(					self							)	->   Union[str, Any]:
            _SCREAMING_SNAKE_CASE				:		str  			=							self.image_processing_class(**self.image_processor_dict							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "do_resize"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "size"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "do_center_crop"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "center_crop"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "do_normalize"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "image_mean"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "image_std"							)							)
            self.assertTrue(hasattr(__lowerCamelCase			,  "do_convert_rgb"							)							)




       def 			UpperCamelCase_	(					self							)	->   List[str]:
            pass







       def 			UpperCamelCase_	(					self							)	->   Union[str, Any]:
            # Initialize image_processing
            _SCREAMING_SNAKE_CASE				:		Dict  			=							self.image_processing_class(**self.image_processor_dict							)
            # create random PIL images
            _SCREAMING_SNAKE_CASE				:		Any  			=							self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase							)
            for image in image_inputs:
                 self.assertIsInstance(__lowerCamelCase			,  Image.Image							)

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

            # Test batched
            _SCREAMING_SNAKE_CASE				:		Optional[int]  			=							image_processing(__lowerCamelCase			,  return_tensors="pt"							).pixel_values
            self.assertEqual(
                encoded_images.shape			,  (
                    self.image_processor_tester.batch_size,
                    self.expected_encoded_image_num_channels,
                    self.image_processor_tester.crop_size["height"],
                    self.image_processor_tester.crop_size["width"],
                )			,  )