
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       :



  """simple docstring"""





  def __init__(					self						,    __UpperCamelCase						,    __UpperCamelCase=13						,    __UpperCamelCase=64						,    __UpperCamelCase=4						,    __UpperCamelCase=3						,    __UpperCamelCase=16						,    __UpperCamelCase=[1, 2, 1]						,    __UpperCamelCase=[2, 4, 8]						,    __UpperCamelCase=3						,    __UpperCamelCase=[[3], [1, 2], [1]]						,    __UpperCamelCase=2.0						,    __UpperCamelCase=True						,    __UpperCamelCase=0.0						,    __UpperCamelCase=0.0						,    __UpperCamelCase=0.1						,    __UpperCamelCase="gelu"						,    __UpperCamelCase=True						,    __UpperCamelCase=0.02						,    __UpperCamelCase=1E-5						,    __UpperCamelCase=True						,    __UpperCamelCase=None						,    __UpperCamelCase=True						,    __UpperCamelCase=10						,    __UpperCamelCase=["stage1", "stage2"]						,    __UpperCamelCase=[1, 2]						,    ):
      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 					lowercase_						(					self					):
      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 					lowercase_						(					self					):
      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 					lowercase_						(					self						,    __UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase					):
      A_								=					DinatModel(config=__UpperCAmelCase					)
      model.to(__UpperCAmelCase					)
      model.eval()
      A_								=					model(__UpperCAmelCase					)

      A_								=					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 					lowercase_						(					self						,    __UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase					):
      A_								=					DinatForImageClassification(__UpperCAmelCase					)
      model.to(__UpperCAmelCase					)
      model.eval()
      A_								=					model(__UpperCAmelCase						,    labels=__UpperCAmelCase					)
      self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.num_labels)					)

      # test greyscale images
      A_								=					1
      A_								=					DinatForImageClassification(__UpperCAmelCase					)
      model.to(__UpperCAmelCase					)
      model.eval()

      A_								=					floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
      A_								=					model(__UpperCAmelCase					)
      self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.num_labels)					)

  def 					lowercase_						(					self						,    __UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase					):
      A_								=					DinatBackbone(config=__UpperCAmelCase					)
      model.to(__UpperCAmelCase					)
      model.eval()
      A_								=					model(__UpperCAmelCase					)

      # 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=__UpperCAmelCase					)
      model.to(__UpperCAmelCase					)
      model.eval()
      A_								=					model(__UpperCAmelCase					)

      # 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					):
      A_								=					self.prepare_config_and_inputs()
      A_	,	A_	,	A_								=					config_and_inputs
      A_								=					{"pixel_values": pixel_values}
      return config, inputs_dict



@require_natten
@require_torch
class 							lowerCamelCase       (		lowerCamelCase_			,  lowerCamelCase_			,  unittest.TestCase					):



  """simple docstring"""





  lowerCAmelCase_								=		(
      (
          DinatModel,
          DinatForImageClassification,
          DinatBackbone,
      )
      if is_torch_available()
      else ()
  )
  lowerCAmelCase_								=		(
      {'''feature-extraction''': DinatModel, '''image-classification''': DinatForImageClassification}
      if is_torch_available()
      else {}
  )
  lowerCAmelCase_								=		False

  lowerCAmelCase_								=		False
  lowerCAmelCase_								=		False
  lowerCAmelCase_								=		False
  lowerCAmelCase_								=		False

  def 					lowercase_						(					self					):
      A_								=					DinatModelTester(self					)
      A_								=					ConfigTester(self						,    config_class=__UpperCAmelCase						,    embed_dim=37					)

  def 					lowercase_						(					self					):
      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					):
      return

  def 					lowercase_						(					self					):
      A_								=					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__UpperCAmelCase					)

  def 					lowercase_						(					self					):
      A_								=					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_image_classification(*__UpperCAmelCase					)

  def 					lowercase_						(					self					):
      A_								=					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_backbone(*__UpperCAmelCase					)

  @unittest.skip(reason="Dinat does not use inputs_embeds"					)
  def 					lowercase_						(					self					):
      pass

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

  def 					lowercase_						(					self					):
      A_	,	A_								=					self.model_tester.prepare_config_and_inputs_for_common()

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

  def 					lowercase_						(					self					):
      A_	,	A_								=					self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
          A_								=					model_class(__UpperCAmelCase					)
          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]						,    __UpperCAmelCase					)

  def 					lowercase_						(					self					):
      self.skipTest("Dinat\'s attention operation is handled entirely by NATTEN."					)

  def 					lowercase_						(					self						,    __UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase					):
      A_								=					model_class(__UpperCAmelCase					)
      model.to(__UpperCAmelCase					)
      model.eval()

      with torch.no_grad():
          A_								=					model(**self._prepare_for_class(__UpperCAmelCase						,    __UpperCAmelCase					)					)

      A_								=					outputs.hidden_states

      A_								=					getattr(
          self.model_tester						,    "expected_num_hidden_layers"						,    len(self.model_tester.depths					) + 1					)
      self.assertEqual(len(__UpperCAmelCase					)						,    __UpperCAmelCase					)

      # 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(__UpperCAmelCase					)						,    __UpperCAmelCase					)

          A_	,	A_	,	A_	,	A_								=					reshaped_hidden_states[0].shape
          A_								=					(
              reshaped_hidden_states[0].view(__UpperCAmelCase						,    __UpperCAmelCase						,    __UpperCAmelCase						,    __UpperCAmelCase					).permute(0						,    2						,    3						,    1					)
          )
          self.assertListEqual(
              list(reshaped_hidden_states.shape[-3:]					)						,    [height, width, self.model_tester.embed_dim]						,    )

  def 					lowercase_						(					self					):
      A_	,	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(__UpperCAmelCase						,    __UpperCAmelCase						,    __UpperCAmelCase						,    __UpperCAmelCase					)

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

          self.check_hidden_states_output(__UpperCAmelCase						,    __UpperCAmelCase						,    __UpperCAmelCase						,    __UpperCAmelCase					)

  @slow
  def 					lowercase_						(					self					):



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

  def 					lowercase_						(					self					):
      A_	,	A_								=					self.model_tester.prepare_config_and_inputs_for_common()

      A_								=					_config_zero_init(__UpperCAmelCase					)
      for model_class in self.all_model_classes:
          A_								=					model_class(config=__UpperCAmelCase					)
          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					):



  """simple docstring"""





  @cached_property
  def 					lowercase_						(					self					):
      return AutoImageProcessor.from_pretrained("shi-labs/dinat-mini-in1k-224"					) if is_vision_available() else None

  @slow
  def 					lowercase_						(					self					):
      A_								=					DinatForImageClassification.from_pretrained("shi-labs/dinat-mini-in1k-224"					).to(__UpperCAmelCase					)
      A_								=					self.default_image_processor

      A_								=					Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"					)
      A_								=					image_processor(images=__UpperCAmelCase						,    return_tensors="pt"					).to(__UpperCAmelCase					)

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

      # verify the logits
      A_								=					torch.Size((1, 1000)					)
      self.assertEqual(outputs.logits.shape						,    __UpperCAmelCase					)
      A_								=					torch.tensor([-0.1545, -0.7667, 0.4642]					).to(__UpperCAmelCase					)
      self.assertTrue(torch.allclose(outputs.logits[0, :3]						,    __UpperCAmelCase						,    atol=1E-4					)					)



@require_torch
@require_natten
class 							lowerCamelCase       (		unittest.TestCase			,  lowerCamelCase_					):



  """simple docstring"""





  lowerCAmelCase_								=		(DinatBackbone,) if is_torch_available() else ()
  lowerCAmelCase_								=		DinatConfig

  def 					lowercase_						(					self					):
      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     A					(				unittest.TestCase       ):







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

										"""simple docstring"""



										UpperCamelCase_     				= size if size is not None else {'shortest_edge': 20}
										UpperCamelCase_     				= crop_size if crop_size is not None else {'height': 18, 'width': 18}
										UpperCamelCase_     				= parent
										UpperCamelCase_     				= batch_size
										UpperCamelCase_     				= num_channels
										UpperCamelCase_     				= image_size
										UpperCamelCase_     				= min_resolution
										UpperCamelCase_     				= max_resolution
										UpperCamelCase_     				= do_resize
										UpperCamelCase_     				= size
										UpperCamelCase_     				= do_center_crop
										UpperCamelCase_     				= crop_size
										UpperCamelCase_     				= do_normalize
										UpperCamelCase_     				= image_mean
										UpperCamelCase_     				= image_std
										UpperCamelCase_     				= do_convert_rgb







							def        lowercase__							(    self   :	Tuple				)		->					List[Any]:

										"""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   :	List[Any]   ,     __UpperCAmelCase   :	str=False   ,     __UpperCAmelCase   :	Tuple=False   ,     __UpperCAmelCase   :	Optional[int]=False				)		->					Any:

										"""simple docstring"""



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

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

										if torchify:
													UpperCamelCase_     				= [torch.from_numpy(__UpperCAmelCase				) for x in image_inputs]

										return image_inputs







@require_torch
@require_vision
class     A					(				lowerCamelCase_  ,						unittest.TestCase       ):
							_SCREAMING_SNAKE_CASE  :		Any			  =       CLIPImageProcessor if is_vision_available() else None







							def        lowercase__							(    self   :	Dict				)		->					List[str]:

										"""simple docstring"""



										UpperCamelCase_     				= CLIPImageProcessingTester(self				)







							@property
							def        lowercase__							(    self   :	Optional[int]				)		->					Optional[Any]:

										"""simple docstring"""



										return self.image_processor_tester.prepare_image_processor_dict()







							def        lowercase__							(    self   :	Tuple				)		->					Tuple:

										"""simple docstring"""



										UpperCamelCase_     				= self.image_processing_class(**self.image_processor_dict				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'do_resize'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'size'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'do_center_crop'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'center_crop'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'do_normalize'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'image_mean'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'image_std'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'do_convert_rgb'				)				)







							def        lowercase__							(    self   :	Optional[int]				)		->					Tuple:

										"""simple docstring"""



										UpperCamelCase_     				= 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}				)

										UpperCamelCase_     				= 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   :	Union[str, Any]				)		->					Optional[int]:

										"""simple docstring"""



										pass







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

										"""simple docstring"""



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

										# Test not batched input
										UpperCamelCase_     				= 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
										UpperCamelCase_     				= image_processing(__UpperCAmelCase   ,     return_tensors='pt'				).pixel_values
										self.assertEqual(
										    encoded_images.shape   ,     (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )   ,     )







							def        lowercase__							(    self   :	Optional[Any]				)		->					Tuple:

										"""simple docstring"""



										UpperCamelCase_     				= self.image_processing_class(**self.image_processor_dict				)
										# create random numpy tensors
										UpperCamelCase_     				= self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCAmelCase   ,     numpify=__UpperCAmelCase				)
										for image in image_inputs:
													self.assertIsInstance(__UpperCAmelCase   ,     np.ndarray				)

										# Test not batched input
										UpperCamelCase_     				= 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
										UpperCamelCase_     				= image_processing(__UpperCAmelCase   ,     return_tensors='pt'				).pixel_values
										self.assertEqual(
										    encoded_images.shape   ,     (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )   ,     )







							def        lowercase__							(    self   :	Optional[Any]				)		->					Any:

										"""simple docstring"""



										UpperCamelCase_     				= self.image_processing_class(**self.image_processor_dict				)
										# create random PyTorch tensors
										UpperCamelCase_     				= self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCAmelCase   ,     torchify=__UpperCAmelCase				)
										for image in image_inputs:
													self.assertIsInstance(__UpperCAmelCase   ,     torch.Tensor				)

										# Test not batched input
										UpperCamelCase_     				= 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
										UpperCamelCase_     				= image_processing(__UpperCAmelCase   ,     return_tensors='pt'				).pixel_values
										self.assertEqual(
										    encoded_images.shape   ,     (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )   ,     )







@require_torch
@require_vision
class     A					(				lowerCamelCase_  ,						unittest.TestCase       ):
							_SCREAMING_SNAKE_CASE  :		str			  =       CLIPImageProcessor if is_vision_available() else None







							def        lowercase__							(    self   :	str				)		->					Any:

										"""simple docstring"""



										UpperCamelCase_     				= CLIPImageProcessingTester(self   ,     num_channels=4				)
										UpperCamelCase_     				= 3







							@property
							def        lowercase__							(    self   :	Dict				)		->					str:

										"""simple docstring"""



										return self.image_processor_tester.prepare_image_processor_dict()







							def        lowercase__							(    self   :	Optional[int]				)		->					List[str]:

										"""simple docstring"""



										UpperCamelCase_     				= self.image_processing_class(**self.image_processor_dict				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'do_resize'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'size'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'do_center_crop'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'center_crop'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'do_normalize'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'image_mean'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'image_std'				)				)
										self.assertTrue(hasattr(__UpperCAmelCase   ,     'do_convert_rgb'				)				)







							def        lowercase__							(    self   :	int				)		->					Any:

										"""simple docstring"""



										pass







							def        lowercase__							(    self   :	Any				)		->					Optional[int]:

										"""simple docstring"""



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

										# Test not batched input
										UpperCamelCase_     				= 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
										UpperCamelCase_     				= image_processing(__UpperCAmelCase   ,     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'],
										    )   ,     )
