





'''simple docstring'''

import inspect
import unittest

from transformers import ConvNextVaConfig
from transformers.models.auto import get_values
from transformers.models.auto.modeling_auto import MODEL_FOR_BACKBONE_MAPPING_NAMES, MODEL_MAPPING_NAMES
from transformers.testing_utils import require_torch, 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 transformers import ConvNextVaBackbone, ConvNextVaForImageClassification, ConvNextVaModel
 from transformers.models.convnextva.modeling_convnextva import CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 from PIL import Image

 from transformers import AutoImageProcessor







class __a :





   def __init__(					self				:			List[str]				,lowerCamelCase				:			int				,lowerCamelCase				:			Tuple=13				,lowerCamelCase				:			int=32				,lowerCamelCase				:			Optional[Any]=3				,lowerCamelCase				:			int=4				,lowerCamelCase				:			Tuple=[10, 20, 30, 40]				,lowerCamelCase				:			List[str]=[2, 2, 3, 2]				,lowerCamelCase				:			Tuple=True				,lowerCamelCase				:			List[Any]=True				,lowerCamelCase				:			Any=37				,lowerCamelCase				:			Optional[Any]="gelu"				,lowerCamelCase				:			str=10				,lowerCamelCase				:			Optional[int]=0.02				,lowerCamelCase				:			Optional[int]=["stage2", "stage3", "stage4"]				,lowerCamelCase				:			Optional[Any]=[2, 3, 4]				,lowerCamelCase				:			List[Any]=None				,):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       parent
      __SCREAMING_SNAKE_CASE      							=       batch_size
      __SCREAMING_SNAKE_CASE      							=       image_size
      __SCREAMING_SNAKE_CASE      							=       num_channels
      __SCREAMING_SNAKE_CASE      							=       num_stages
      __SCREAMING_SNAKE_CASE      							=       hidden_sizes
      __SCREAMING_SNAKE_CASE      							=       depths
      __SCREAMING_SNAKE_CASE      							=       is_training
      __SCREAMING_SNAKE_CASE      							=       use_labels
      __SCREAMING_SNAKE_CASE      							=       intermediate_size
      __SCREAMING_SNAKE_CASE      							=       hidden_act
      __SCREAMING_SNAKE_CASE      							=       num_labels
      __SCREAMING_SNAKE_CASE      							=       initializer_range
      __SCREAMING_SNAKE_CASE      							=       out_features
      __SCREAMING_SNAKE_CASE      							=       out_indices
      __SCREAMING_SNAKE_CASE      							=       scope





   def      UpperCAmelCase__     (					self				:			Optional[Any]    ):

      '''simple docstring'''

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

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

      __SCREAMING_SNAKE_CASE      							=       self.get_config()

      return config, pixel_values, labels





   def      UpperCAmelCase__     (					self				:			Tuple    ):

      '''simple docstring'''

      return ConvNextVaConfig(
          num_channels=self.num_channels				,hidden_sizes=self.hidden_sizes				,depths=self.depths				,num_stages=self.num_stages				,hidden_act=self.hidden_act				,is_decoder=_lowercase				,initializer_range=self.initializer_range				,out_features=self.out_features				,out_indices=self.out_indices				,num_labels=self.num_labels				,)





   def      UpperCAmelCase__     (					self				:			Optional[Any]				,lowerCamelCase				:			Union[str, Any]				,lowerCamelCase				:			List[str]				,lowerCamelCase				:			str    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       ConvNextVaModel(config=_lowercase    )
      model.to(_lowercase    )
      model.eval()
      __SCREAMING_SNAKE_CASE      							=       model(_lowercase    )
      # expected last hidden states: B, C, H // 32, W // 32
      self.parent.assertEqual(
          result.last_hidden_state.shape				,(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)				,)





   def      UpperCAmelCase__     (					self				:			int				,lowerCamelCase				:			Dict				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			List[str]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       ConvNextVaForImageClassification(_lowercase    )
      model.to(_lowercase    )
      model.eval()
      __SCREAMING_SNAKE_CASE      							=       model(_lowercase				,labels=_lowercase    )
      self.parent.assertEqual(result.logits.shape				,(self.batch_size, self.num_labels)    )





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

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       ConvNextVaBackbone(config=_lowercase    )
      model.to(_lowercase    )
      model.eval()
      __SCREAMING_SNAKE_CASE      							=       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, self.hidden_sizes[1], 4, 4]    )

      # verify channels
      self.parent.assertEqual(len(model.channels    )				,len(config.out_features    )    )
      self.parent.assertListEqual(model.channels				,config.hidden_sizes[1:]    )

      # verify backbone works with out_features=None
      __SCREAMING_SNAKE_CASE      							=       None
      __SCREAMING_SNAKE_CASE      							=       ConvNextVaBackbone(config=_lowercase    )
      model.to(_lowercase    )
      model.eval()
      __SCREAMING_SNAKE_CASE      							=       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, self.hidden_sizes[-1], 1, 1]    )

      # verify channels
      self.parent.assertEqual(len(model.channels    )				,1    )
      self.parent.assertListEqual(model.channels				,[config.hidden_sizes[-1]]    )





   def      UpperCAmelCase__     (					self				:			List[str]    ):

      '''simple docstring'''

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





   def      UpperCAmelCase__     (					self				:			List[Any]    ):

      '''simple docstring'''

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







@require_torch
class __a (   __snake_case,   __snake_case,   unittest.TestCase			):
   __UpperCamelCase   : Any	      =	(
       (
           ConvNextVaModel,
           ConvNextVaForImageClassification,
           ConvNextVaBackbone,
       )
       if is_torch_available()
       else ()
   )
   __UpperCamelCase   : int	      =	(
       {'feature-extraction': ConvNextVaModel, 'image-classification': ConvNextVaForImageClassification}
       if is_torch_available()
       else {}
   )

   __UpperCamelCase   : Any	      =	False
   __UpperCamelCase   : Dict	      =	False
   __UpperCamelCase   : str	      =	False
   __UpperCamelCase   : str	      =	False
   __UpperCamelCase   : Union[str, Any]	      =	False





   def      UpperCAmelCase__     (					self				:			Dict    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       ConvNextVaModelTester(self    )
      __SCREAMING_SNAKE_CASE      							=       ConfigTester(self				,config_class=_lowercase				,has_text_modality=_lowercase				,hidden_size=37    )





   def      UpperCAmelCase__     (					self				:			List[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      UpperCAmelCase__     (					self				:			List[Any]    ):

      '''simple docstring'''

      return





   @unittest.skip(reason="""ConvNextV2 does not use inputs_embeds"""    )
   def      UpperCAmelCase__     (					self				:			int    ):

      '''simple docstring'''

      pass





   @unittest.skip(reason="""ConvNextV2 does not support input and output embeddings"""    )
   def      UpperCAmelCase__     (					self				:			Dict    ):

      '''simple docstring'''

      pass





   @unittest.skip(reason="""ConvNextV2 does not use feedforward chunking"""    )
   def      UpperCAmelCase__     (					self				:			List[str]    ):

      '''simple docstring'''

      pass





   def      UpperCAmelCase__     (					self				:			List[str]    ):

      '''simple docstring'''

      if not self.model_tester.is_training:
         return

      for model_class in self.all_model_classes:
         __SCREAMING_SNAKE_CASE      							=       self.model_tester.prepare_config_and_inputs_with_labels()
         __SCREAMING_SNAKE_CASE      							=       True

         if model_class.__name__ in [
             *get_values(_lowercase    ),
             *get_values(_lowercase    ),
         ]:
            continue

         __SCREAMING_SNAKE_CASE      							=       model_class(_lowercase    )
         model.to(_lowercase    )
         model.train()
         __SCREAMING_SNAKE_CASE      							=       self._prepare_for_class(_lowercase				,_lowercase				,return_labels=_lowercase    )
         __SCREAMING_SNAKE_CASE      							=       model(**_lowercase    ).loss
         loss.backward()





   def      UpperCAmelCase__     (					self				:			Any    ):

      '''simple docstring'''

      if not self.model_tester.is_training:
         return

      for model_class in self.all_model_classes:
         __SCREAMING_SNAKE_CASE      							=       self.model_tester.prepare_config_and_inputs_with_labels()
         __SCREAMING_SNAKE_CASE      							=       False
         __SCREAMING_SNAKE_CASE      							=       True

         if (
             model_class.__name__
             in [*get_values(_lowercase    ), *get_values(_lowercase    )]
             or not model_class.supports_gradient_checkpointing
         ):
            continue

         __SCREAMING_SNAKE_CASE      							=       model_class(_lowercase    )
         model.to(_lowercase    )
         model.gradient_checkpointing_enable()
         model.train()
         __SCREAMING_SNAKE_CASE      							=       self._prepare_for_class(_lowercase				,_lowercase				,return_labels=_lowercase    )
         __SCREAMING_SNAKE_CASE      							=       model(**_lowercase    ).loss
         loss.backward()





   def      UpperCAmelCase__     (					self				:			List[Any]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.model_tester.prepare_config_and_inputs_for_common()

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

         __SCREAMING_SNAKE_CASE      							=       ["""pixel_values"""]
         self.assertListEqual(arg_names[:1]				,_lowercase    )





   def      UpperCAmelCase__     (					self				:			int    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*_lowercase    )





   def      UpperCAmelCase__     (					self				:			Tuple    ):

      '''simple docstring'''

      def check_hidden_states_output(lowerCamelCase				:			List[Any]				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			Optional[int]    ):
         __SCREAMING_SNAKE_CASE      							=       model_class(_lowercase    )
         model.to(_lowercase    )
         model.eval()

         with torch.no_grad():
            __SCREAMING_SNAKE_CASE      							=       model(**self._prepare_for_class(_lowercase				,_lowercase    )    )

         __SCREAMING_SNAKE_CASE      							=       outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

         __SCREAMING_SNAKE_CASE      							=       self.model_tester.num_stages
         self.assertEqual(len(_lowercase    )				,expected_num_stages + 1    )

         # ConvNextV2's feature maps are of shape (batch_size, num_channels, height, width)
         self.assertListEqual(
             list(hidden_states[0].shape[-2:]    )				,[self.model_tester.image_size // 4, self.model_tester.image_size // 4]				,)

      __SCREAMING_SNAKE_CASE      							=       self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
         __SCREAMING_SNAKE_CASE      							=       True
         check_hidden_states_output(_lowercase				,_lowercase				,_lowercase    )

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

         check_hidden_states_output(_lowercase				,_lowercase				,_lowercase    )





   def      UpperCAmelCase__     (					self				:			List[str]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_image_classification(*_lowercase    )





   @slow
   def      UpperCAmelCase__     (					self				:			Any    ):

      '''simple docstring'''

      for model_name in CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         __SCREAMING_SNAKE_CASE      							=       ConvNextVaModel.from_pretrained(_lowercase    )
         self.assertIsNotNone(_lowercase    )





def 						__magic_name__       (							)						->					str:

   '''simple docstring'''







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







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





   @cached_property
   def      UpperCAmelCase__     (					self				:			int    ):

      '''simple docstring'''

      return AutoImageProcessor.from_pretrained("""facebook/convnextv2-tiny-1k-224"""    ) if is_vision_available() else None





   @slow
   def      UpperCAmelCase__     (					self				:			List[str]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       ConvNextVaForImageClassification.from_pretrained("""facebook/convnextv2-tiny-1k-224"""    ).to(_lowercase    )

      __SCREAMING_SNAKE_CASE      							=       self.default_image_processor
      __SCREAMING_SNAKE_CASE      							=       prepare_img()
      __SCREAMING_SNAKE_CASE      							=       preprocessor(images=_lowercase				,return_tensors="""pt"""    ).to(_lowercase    )

      # forward pass
      with torch.no_grad():
         __SCREAMING_SNAKE_CASE      							=       model(**_lowercase    )

      # verify the logits
      __SCREAMING_SNAKE_CASE      							=       torch.Size((1, 1000)    )
      self.assertEqual(outputs.logits.shape				,_lowercase    )

      __SCREAMING_SNAKE_CASE      							=       torch.tensor([0.9_996, 0.1_966, -0.4_386]    ).to(_lowercase    )
      self.assertTrue(torch.allclose(outputs.logits[0, :3]				,_lowercase				,atol=1E-4    )    )












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







class __a (   unittest.TestCase			):





   def __init__(					self				:			List[Any]				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			List[str]=7				,lowerCamelCase				:			List[str]=3				,lowerCamelCase				:			List[str]=18				,lowerCamelCase				:			Any=30				,lowerCamelCase				:			Optional[Any]=400				,lowerCamelCase				:			Optional[Any]=True				,lowerCamelCase				:			Optional[Any]=None				,lowerCamelCase				:			Optional[int]=True				,lowerCamelCase				:			int=None				,lowerCamelCase				:			str=True				,lowerCamelCase				:			Dict=[0.48_145_466, 0.4_578_275, 0.40_821_073]				,lowerCamelCase				:			List[str]=[0.26_862_954, 0.26_130_258, 0.27_577_711]				,lowerCamelCase				:			Tuple=True				,):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       size if size is not None else {"""height""": 224, """width""": 224}
      __SCREAMING_SNAKE_CASE      							=       crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
      __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_normalize
      __SCREAMING_SNAKE_CASE      							=       image_mean
      __SCREAMING_SNAKE_CASE      							=       image_std
      __SCREAMING_SNAKE_CASE      							=       do_convert_rgb





   def      UpperCAmelCase__     (					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      UpperCAmelCase__     (					self				:			int				,lowerCamelCase				:			Union[str, Any]=False				,lowerCamelCase				:			str=False				,lowerCamelCase				:			str=False    ):

      '''simple docstring'''

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

      if equal_resolution:
         __SCREAMING_SNAKE_CASE      							=       []
         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:
         __SCREAMING_SNAKE_CASE      							=       []
         for i in range(self.batch_size    ):
            __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE      							=       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
         __SCREAMING_SNAKE_CASE      							=       [Image.fromarray(np.moveaxis(lowerCamelCase				,0				,-1    )    ) for x in image_inputs]

      if torchify:
         __SCREAMING_SNAKE_CASE      							=       [torch.from_numpy(lowerCamelCase    ) for x in image_inputs]

      return image_inputs







@require_torch
@require_vision
class __a (   _snake_case,   unittest.TestCase			):
   __UpperCamelCase   : int	      =	ChineseCLIPImageProcessor if is_vision_available() else None





   def      UpperCAmelCase__     (					self				:			Any    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       ChineseCLIPImageProcessingTester(self				,do_center_crop=lowerCamelCase    )





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

      '''simple docstring'''

      return self.image_processor_tester.prepare_image_processor_dict()





   def      UpperCAmelCase__     (					self				:			Tuple    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       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[Any]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class.from_dict(self.image_processor_dict    )
      self.assertEqual(image_processor.size				,{"""height""": 224, """width""": 224}    )
      self.assertEqual(image_processor.crop_size				,{"""height""": 18, """width""": 18}    )

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class.from_dict(self.image_processor_dict				,size=42				,crop_size=84    )
      self.assertEqual(image_processor.size				,{"""shortest_edge""": 42}    )
      self.assertEqual(image_processor.crop_size				,{"""height""": 84, """width""": 84}    )





   def      UpperCAmelCase__     (					self				:			Dict    ):

      '''simple docstring'''

      pass





   def      UpperCAmelCase__     (					self				:			List[str]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random PIL images
      __SCREAMING_SNAKE_CASE      							=       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      							=       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(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				:			Optional[int]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random numpy tensors
      __SCREAMING_SNAKE_CASE      							=       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      							=       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(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				:			str    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random PyTorch tensors
      __SCREAMING_SNAKE_CASE      							=       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      							=       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(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 __a (   _snake_case,   unittest.TestCase			):
   __UpperCamelCase   : Optional[int]	      =	ChineseCLIPImageProcessor if is_vision_available() else None





   def      UpperCAmelCase__     (					self				:			Tuple    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       ChineseCLIPImageProcessingTester(self				,num_channels=4				,do_center_crop=lowerCamelCase    )
      __SCREAMING_SNAKE_CASE      							=       3





   @property
   def      UpperCAmelCase__     (					self				:			Dict    ):

      '''simple docstring'''

      return self.image_processor_tester.prepare_image_processor_dict()





   def      UpperCAmelCase__     (					self				:			int    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       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				:			Tuple    ):

      '''simple docstring'''

      pass





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

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random PIL images
      __SCREAMING_SNAKE_CASE      							=       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      							=       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      							=       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"""],
          )				,)





