




'''simple docstring'''


import collections
import inspect
import unittest

from transformers import NatConfig
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 NatBackbone, NatForImageClassification, NatModel
 from transformers.models.nat.modeling_nat import NAT_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
 from PIL import Image

 from transformers import AutoImageProcessor







class     SCREAMING_SNAKE_CASE						:






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


           '''simple docstring'''

           a_    :       List[str]    	=     parent
           a_    :       int    	=     batch_size
           a_    :       List[Any]    	=     image_size
           a_    :       Dict    	=     patch_size
           a_    :       List[str]    	=     num_channels
           a_    :       Optional[int]    	=     embed_dim
           a_    :       Any    	=     depths
           a_    :       Tuple    	=     num_heads
           a_    :       Optional[Any]    	=     kernel_size
           a_    :       Dict    	=     mlp_ratio
           a_    :       Union[str, Any]    	=     qkv_bias
           a_    :       List[str]    	=     hidden_dropout_prob
           a_    :       str    	=     attention_probs_dropout_prob
           a_    :       Dict    	=     drop_path_rate
           a_    :       Union[str, Any]    	=     hidden_act
           a_    :       Optional[Any]    	=     patch_norm
           a_    :       Union[str, Any]    	=     layer_norm_eps
           a_    :       str    	=     initializer_range
           a_    :       Union[str, Any]    	=     is_training
           a_    :       Any    	=     scope
           a_    :       Optional[int]    	=     use_labels
           a_    :       List[str]    	=     num_labels
           a_    :       List[str]    	=     out_features
           a_    :       str    	=     out_indices






      def        lowercase_	(   self      :     Optional[Any]					):


           '''simple docstring'''

           a_    :       Union[str, Any]    	=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

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

           a_    :       int    	=     self.get_config()

           return config, pixel_values, labels






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


           '''simple docstring'''

           return NatConfig(
               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	,	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        lowercase_	(   self      :     str	,	lowercase__      :     int	,	lowercase__      :     List[str]	,	lowercase__      :     List[Any]					):


           '''simple docstring'''

           a_    :       Optional[Any]    	=     NatModel(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       Optional[Any]    	=     model(lowercase__					)

           a_    :       List[Any]    	=     (config.image_size // config.patch_size) // (2 ** (len(config.depths					) - 1))
           a_    :       List[str]    	=     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        lowercase_	(   self      :     Dict	,	lowercase__      :     Tuple	,	lowercase__      :     Any	,	lowercase__      :     Optional[int]					):


           '''simple docstring'''

           a_    :       Optional[int]    	=     NatForImageClassification(lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       str    	=     model(lowercase__	,	labels=lowercase__					)
           self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.num_labels)					)

           # test greyscale images
           a_    :       Optional[Any]    	=     1
           a_    :       Optional[Any]    	=     NatForImageClassification(lowercase__					)
           model.to(lowercase__					)
           model.eval()

           a_    :       Optional[int]    	=     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
           a_    :       int    	=     model(lowercase__					)
           self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.num_labels)					)






      def        lowercase_	(   self      :     Optional[Any]	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     int					):


           '''simple docstring'''

           a_    :       Optional[Any]    	=     NatBackbone(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       str    	=     model(lowercase__					)

           # 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_    :       Any    	=     None
           a_    :       Any    	=     NatBackbone(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       List[Any]    	=     model(lowercase__					)

           # 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        lowercase_	(   self      :     List[str]					):


           '''simple docstring'''

           a_    :       Any    	=     self.prepare_config_and_inputs()
           a_	,    a_	,    a_    :       Any    	=     config_and_inputs
           a_    :       List[str]    	=     {"""pixel_values""": pixel_values}
           return config, inputs_dict







@require_natten
@require_torch
class     SCREAMING_SNAKE_CASE						(	snake_case_       ,			snake_case_       ,			unittest.TestCase							):
      __magic_name__     :					str             =				(
          (
              NatModel,
              NatForImageClassification,
              NatBackbone,
          )
          if is_torch_available()
          else ()
      )
      __magic_name__     :					Optional[Any]             =				(
          {'''feature-extraction''': NatModel, '''image-classification''': NatForImageClassification}
          if is_torch_available()
          else {}
      )
      __magic_name__     :					Optional[Any]             =				False

      __magic_name__     :					Optional[int]             =				False
      __magic_name__     :					int             =				False
      __magic_name__     :					Optional[Any]             =				False
      __magic_name__     :					Tuple             =				False






      def        lowercase_	(   self      :     Optional[int]					):


           '''simple docstring'''

           a_    :       List[str]    	=     NatModelTester(self					)
           a_    :       List[Any]    	=     ConfigTester(self	,	config_class=lowercase__	,	embed_dim=37					)






      def        lowercase_	(   self      :     int					):


           '''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        lowercase_	(   self      :     str					):


           '''simple docstring'''

           return






      def        lowercase_	(   self      :     List[str]					):


           '''simple docstring'''

           a_    :       str    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*lowercase__					)






      def        lowercase_	(   self      :     Any					):


           '''simple docstring'''

           a_    :       Optional[int]    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_image_classification(*lowercase__					)






      def        lowercase_	(   self      :     int					):


           '''simple docstring'''

           a_    :       str    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_backbone(*lowercase__					)






      @unittest.skip(reason="""Nat does not use inputs_embeds"""					)
      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           pass






      @unittest.skip(reason="""Nat does not use feedforward chunking"""					)
      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           pass






      def        lowercase_	(   self      :     Any					):


           '''simple docstring'''

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

           for model_class in self.all_model_classes:
                a_    :       List[str]    	=     model_class(lowercase__					)
                self.assertIsInstance(model.get_input_embeddings()	,	(nn.Module)					)
                a_    :       List[str]    	=     model.get_output_embeddings()
                self.assertTrue(x is None or isinstance(lowercase__	,	nn.Linear					)					)






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


           '''simple docstring'''

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

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

                a_    :       Dict    	=     ["""pixel_values"""]
                self.assertListEqual(arg_names[:1]	,	lowercase__					)






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


           '''simple docstring'''

           self.skipTest("""Nat's attention operation is handled entirely by NATTEN."""					)






      def        lowercase_	(   self      :     Any	,	lowercase__      :     Any	,	lowercase__      :     int	,	lowercase__      :     Optional[int]	,	lowercase__      :     List[Any]					):


           '''simple docstring'''

           a_    :       Union[str, Any]    	=     model_class(lowercase__					)
           model.to(lowercase__					)
           model.eval()

           with torch.no_grad():
                a_    :       Dict    	=     model(**self._prepare_for_class(lowercase__	,	lowercase__					)					)

           a_    :       List[str]    	=     outputs.hidden_states

           a_    :       Any    	=     getattr(
               self.model_tester	,	"""expected_num_hidden_layers"""	,	len(self.model_tester.depths					) + 1					)
           self.assertEqual(len(lowercase__					)	,	lowercase__					)

           # Nat has a different seq_length
           a_    :       Optional[Any]    	=     (
               config.patch_size
               if isinstance(config.patch_size	,	collections.abc.Iterable					)
               else (config.patch_size, config.patch_size)
           )

           a_    :       Any    	=     image_size[0] // patch_size[0]
           a_    :       Optional[int]    	=     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__ != "NatBackbone":
                a_    :       Optional[int]    	=     outputs.reshaped_hidden_states
                self.assertEqual(len(lowercase__					)	,	lowercase__					)

                a_	,    a_	,    a_	,    a_    :       Optional[Any]    	=     reshaped_hidden_states[0].shape
                a_    :       Tuple    	=     (
                    reshaped_hidden_states[0].view(lowercase__	,	lowercase__	,	lowercase__	,	lowercase__					).permute(0	,	2	,	3	,	1					)
                )
                self.assertListEqual(
                    list(reshaped_hidden_states.shape[-3:]					)	,	[height, width, self.model_tester.embed_dim]	,	)






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


           '''simple docstring'''

           a_	,    a_    :       Union[str, Any]    	=     self.model_tester.prepare_config_and_inputs_for_common()

           a_    :       Tuple    	=     (
               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_    :       List[Any]    	=     True
                self.check_hidden_states_output(lowercase__	,	lowercase__	,	lowercase__	,	lowercase__					)

                # check that output_hidden_states also work using config
                del inputs_dict["output_hidden_states"]
                a_    :       str    	=     True

                self.check_hidden_states_output(lowercase__	,	lowercase__	,	lowercase__	,	lowercase__					)






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


           '''simple docstring'''

           for model_name in NAT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                a_    :       List[Any]    	=     NatModel.from_pretrained(lowercase__					)
                self.assertIsNotNone(lowercase__					)






      def        lowercase_	(   self      :     int					):


           '''simple docstring'''

           a_	,    a_    :       Optional[int]    	=     self.model_tester.prepare_config_and_inputs_for_common()

           a_    :       str    	=     _config_zero_init(lowercase__					)
           for model_class in self.all_model_classes:
                a_    :       int    	=     model_class(config=lowercase__					)
                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     SCREAMING_SNAKE_CASE						(	unittest.TestCase							):






      @cached_property
      def        lowercase_	(   self      :     Any					):


           '''simple docstring'''

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






      @slow
      def        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           a_    :       List[str]    	=     NatForImageClassification.from_pretrained("""shi-labs/nat-mini-in1k-224"""					).to(lowercase__					)
           a_    :       str    	=     self.default_image_processor

           a_    :       int    	=     Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""					)
           a_    :       Optional[int]    	=     image_processor(images=lowercase__	,	return_tensors="""pt"""					).to(lowercase__					)

           # forward pass
           with torch.no_grad():
                a_    :       Dict    	=     model(**lowercase__					)

           # verify the logits
           a_    :       List[str]    	=     torch.Size((1, 1000)					)
           self.assertEqual(outputs.logits.shape	,	lowercase__					)
           a_    :       Union[str, Any]    	=     torch.tensor([0.3805, -0.8676, -0.3912]					).to(lowercase__					)
           self.assertTrue(torch.allclose(outputs.logits[0, :3]	,	lowercase__	,	atol=1e-4					)					)







@require_torch
@require_natten
class     SCREAMING_SNAKE_CASE						(	unittest.TestCase       ,			snake_case_							):
      __magic_name__     :					Optional[int]             =				(NatBackbone,) if is_torch_available() else ()
      __magic_name__     :					List[str]             =				NatConfig






      def        lowercase_	(   self      :     Optional[Any]					):


           '''simple docstring'''

           a_    :       Union[str, Any]    	=     NatModelTester(self					)






'''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


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import CLIPImageProcessor







class     SCREAMING_SNAKE_CASE						(	unittest.TestCase							):






      def __init__(   self      :     Tuple	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     Optional[Any]=7	,	lowercase__      :     str=3	,	lowercase__      :     Tuple=18	,	lowercase__      :     Dict=30	,	lowercase__      :     List[Any]=400	,	lowercase__      :     Optional[Any]=True	,	lowercase__      :     Union[str, Any]=None	,	lowercase__      :     Union[str, Any]=True	,	lowercase__      :     Tuple=None	,	lowercase__      :     str=True	,	lowercase__      :     List[Any]=[0.48145466, 0.4578275, 0.40821073]	,	lowercase__      :     Optional[Any]=[0.26862954, 0.26130258, 0.27577711]	,	lowercase__      :     str=True	,	):


           '''simple docstring'''

           a_    :       Dict    	=     size if size is not None else {"""shortest_edge""": 20}
           a_    :       Any    	=     crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
           a_    :       List[str]    	=     parent
           a_    :       Dict    	=     batch_size
           a_    :       Any    	=     num_channels
           a_    :       Optional[int]    	=     image_size
           a_    :       Union[str, Any]    	=     min_resolution
           a_    :       Tuple    	=     max_resolution
           a_    :       int    	=     do_resize
           a_    :       List[str]    	=     size
           a_    :       Optional[int]    	=     do_center_crop
           a_    :       str    	=     crop_size
           a_    :       str    	=     do_normalize
           a_    :       Any    	=     image_mean
           a_    :       List[str]    	=     image_std
           a_    :       Any    	=     do_convert_rgb






      def        lowercase_	(   self      :     Optional[int]					):


           '''simple docstring'''

           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        lowercase_	(   self      :     str	,	lowercase__      :     Union[str, Any]=False	,	lowercase__      :     Union[str, Any]=False	,	lowercase__      :     Union[str, Any]=False					):


           '''simple docstring'''

           assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

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

           return image_inputs







@require_torch
@require_vision
class     SCREAMING_SNAKE_CASE						(	snake_case_       ,			unittest.TestCase							):
      __magic_name__     :					int             =				CLIPImageProcessor if is_vision_available() else None






      def        lowercase_	(   self      :     List[str]					):


           '''simple docstring'''

           a_    :       Dict    	=     CLIPImageProcessingTester(self					)






      @property
      def        lowercase_	(   self      :     Optional[int]					):


           '''simple docstring'''

           return self.image_processor_tester.prepare_image_processor_dict()






      def        lowercase_	(   self      :     Optional[Any]					):


           '''simple docstring'''

           a_    :       List[Any]    	=     self.image_processing_class(**self.image_processor_dict					)
           self.assertTrue(hasattr(lowercase__	,	"""do_resize"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""size"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""do_center_crop"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""center_crop"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""do_normalize"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""image_mean"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""image_std"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""do_convert_rgb"""					)					)






      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           a_    :       Optional[Any]    	=     self.image_processing_class.from_dict(self.image_processor_dict					)
           self.assertEqual(image_processor.size	,	{"""shortest_edge""": 20}					)
           self.assertEqual(image_processor.crop_size	,	{"""height""": 18, """width""": 18}					)

           a_    :       Optional[int]    	=     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        lowercase_	(   self      :     List[str]					):


           '''simple docstring'''

           pass






      def        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           a_    :       str    	=     self.image_processing_class(**self.image_processor_dict					)
           # create random PIL images
           a_    :       str    	=     self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__					)
           for image in image_inputs:
                self.assertIsInstance(lowercase__	,	Image.Image					)

           # Test not batched input
           a_    :       Optional[Any]    	=     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
           a_    :       str    	=     image_processing(lowercase__	,	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        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           a_    :       Optional[Any]    	=     self.image_processing_class(**self.image_processor_dict					)
           # create random numpy tensors
           a_    :       Optional[int]    	=     self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__	,	numpify=lowercase__					)
           for image in image_inputs:
                self.assertIsInstance(lowercase__	,	np.ndarray					)

           # Test not batched input
           a_    :       Tuple    	=     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
           a_    :       str    	=     image_processing(lowercase__	,	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        lowercase_	(   self      :     str					):


           '''simple docstring'''

           a_    :       Dict    	=     self.image_processing_class(**self.image_processor_dict					)
           # create random PyTorch tensors
           a_    :       Optional[int]    	=     self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__	,	torchify=lowercase__					)
           for image in image_inputs:
                self.assertIsInstance(lowercase__	,	torch.Tensor					)

           # Test not batched input
           a_    :       Optional[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
           a_    :       int    	=     image_processing(lowercase__	,	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     SCREAMING_SNAKE_CASE						(	snake_case_       ,			unittest.TestCase							):
      __magic_name__     :					List[str]             =				CLIPImageProcessor if is_vision_available() else None






      def        lowercase_	(   self      :     str					):


           '''simple docstring'''

           a_    :       str    	=     CLIPImageProcessingTester(self	,	num_channels=4					)
           a_    :       Dict    	=     3






      @property
      def        lowercase_	(   self      :     Any					):


           '''simple docstring'''

           return self.image_processor_tester.prepare_image_processor_dict()






      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           a_    :       int    	=     self.image_processing_class(**self.image_processor_dict					)
           self.assertTrue(hasattr(lowercase__	,	"""do_resize"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""size"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""do_center_crop"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""center_crop"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""do_normalize"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""image_mean"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""image_std"""					)					)
           self.assertTrue(hasattr(lowercase__	,	"""do_convert_rgb"""					)					)






      def        lowercase_	(   self      :     int					):


           '''simple docstring'''

           pass






      def        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           a_    :       List[Any]    	=     self.image_processing_class(**self.image_processor_dict					)
           # create random PIL images
           a_    :       Union[str, Any]    	=     self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__					)
           for image in image_inputs:
                self.assertIsInstance(lowercase__	,	Image.Image					)

           # Test not batched input
           a_    :       Optional[Any]    	=     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
           a_    :       List[str]    	=     image_processing(lowercase__	,	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"""],
               )	,	)
