

'''simple docstring'''






import inspect
import unittest

from transformers import DataaVecVisionConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_multi_gpu, 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, _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 (
          MODEL_MAPPING,
          DataaVecVisionForImageClassification,
          DataaVecVisionForSemanticSegmentation,
          DataaVecVisionModel,
      )
      from transformers.models.dataavec.modeling_dataavec_vision import DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import BeitImageProcessor
class 	SCREAMING_SNAKE_CASE__			:




    def __init__(					self				,     lowercase__				,     lowercase__=100				,     lowercase__=13				,     lowercase__=30				,     lowercase__=2				,     lowercase__=3				,     lowercase__=True				,     lowercase__=True				,     lowercase__=32				,     lowercase__=4				,     lowercase__=4				,     lowercase__=37				,     lowercase__="gelu"				,     lowercase__=0.1				,     lowercase__=0.1				,     lowercase__=10				,     lowercase__=0.02				,     lowercase__=3				,     lowercase__=None				,     lowercase__=[0, 1, 2, 3]				,     ):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			str     =       parent
          SCREAMING_SNAKE_CASE_      :			int     =       100
          SCREAMING_SNAKE_CASE_      :			Any     =       batch_size
          SCREAMING_SNAKE_CASE_      :			Dict     =       image_size
          SCREAMING_SNAKE_CASE_      :			int     =       patch_size
          SCREAMING_SNAKE_CASE_      :			Tuple     =       num_channels
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       is_training
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       use_labels
          SCREAMING_SNAKE_CASE_      :			int     =       hidden_size
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       num_hidden_layers
          SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       num_attention_heads
          SCREAMING_SNAKE_CASE_      :			List[str]     =       intermediate_size
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       hidden_act
          SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       hidden_dropout_prob
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       attention_probs_dropout_prob
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       type_sequence_label_size
          SCREAMING_SNAKE_CASE_      :			str     =       initializer_range
          SCREAMING_SNAKE_CASE_      :			List[str]     =       scope
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       out_indices
          SCREAMING_SNAKE_CASE_      :			Tuple     =       num_labels

          # in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       (image_size // patch_size) ** 2
          SCREAMING_SNAKE_CASE_      :			int     =       num_patches + 1




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

          SCREAMING_SNAKE_CASE_      :			List[Any]     =       None
          SCREAMING_SNAKE_CASE_      :			Dict     =       None
          if self.use_labels:
                SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       ids_tensor([self.batch_size]				,     self.type_sequence_label_size			)
                SCREAMING_SNAKE_CASE_      :			str     =       ids_tensor([self.batch_size, self.image_size, self.image_size]				,     self.num_labels			)

          SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       self.get_config()

          return config, pixel_values, labels, pixel_labels




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          return DataaVecVisionConfig(
              vocab_size=self.vocab_size				,     image_size=self.image_size				,     patch_size=self.patch_size				,     num_channels=self.num_channels				,     hidden_size=self.hidden_size				,     num_hidden_layers=self.num_hidden_layers				,     num_attention_heads=self.num_attention_heads				,     intermediate_size=self.intermediate_size				,     hidden_act=self.hidden_act				,     hidden_dropout_prob=self.hidden_dropout_prob				,     attention_probs_dropout_prob=self.attention_probs_dropout_prob				,     is_decoder=lowercase__				,     initializer_range=self.initializer_range				,     out_indices=self.out_indices				,     )




    def   __lowerCamelCase      (					self				,     lowercase__				,     lowercase__				,     lowercase__				,     lowercase__			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			Dict     =       DataaVecVisionModel(config=lowercase__			)
          model.to(lowercase__			)
          model.eval()
          SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       model(lowercase__			)
          # expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       (self.image_size // self.patch_size) ** 2
          self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, num_patches + 1, self.hidden_size)			)




    def   __lowerCamelCase      (					self				,     lowercase__				,     lowercase__				,     lowercase__				,     lowercase__			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			str     =       self.type_sequence_label_size
          SCREAMING_SNAKE_CASE_      :			Tuple     =       DataaVecVisionForImageClassification(lowercase__			)
          model.to(lowercase__			)
          model.eval()
          SCREAMING_SNAKE_CASE_      :			Dict     =       model(lowercase__				,     labels=lowercase__			)
          self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.type_sequence_label_size)			)




    def   __lowerCamelCase      (					self				,     lowercase__				,     lowercase__				,     lowercase__				,     lowercase__			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			List[Any]     =       self.num_labels
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       DataaVecVisionForSemanticSegmentation(lowercase__			)
          model.to(lowercase__			)
          model.eval()
          SCREAMING_SNAKE_CASE_      :			str     =       model(lowercase__			)
          self.parent.assertEqual(
              result.logits.shape				,     (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)			)
          SCREAMING_SNAKE_CASE_      :			int     =       model(lowercase__				,     labels=lowercase__			)
          self.parent.assertEqual(
              result.logits.shape				,     (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)			)







    def   __lowerCamelCase      (					self			):






          """simple docstring"""






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






@require_torch
class 	SCREAMING_SNAKE_CASE__			(				_UpperCAmelCase,_UpperCAmelCase,unittest.TestCase      ):
    _A			    =							(
        (DataaVecVisionModel, DataaVecVisionForImageClassification, DataaVecVisionForSemanticSegmentation)
        if is_torch_available()
        else ()
    )
    _A			    =							(
        {
            "feature-extraction": DataaVecVisionModel,
            "image-classification": DataaVecVisionForImageClassification,
            "image-segmentation": DataaVecVisionForSemanticSegmentation,
        }
        if is_torch_available()
        else {}
    )

    _A			    =							False
    _A			    =							False
    _A			    =							False




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			str     =       DataaVecVisionModelTester(self			)
          SCREAMING_SNAKE_CASE_      :			Dict     =       ConfigTester(
              self				,     config_class=lowercase__				,     has_text_modality=lowercase__				,     hidden_size=37			)




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          self.config_tester.run_common_tests()




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          pass




    @require_torch_multi_gpu
    @unittest.skip(
        reason="Data2VecVision has some layers using `add_module` which doesn't work well with `nn.DataParallel`"			)
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          pass




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






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

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




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_      :			str     =       self.model_tester.prepare_config_and_inputs_for_common()

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

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




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			int     =       self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*lowercase__			)




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			str     =       self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_segmentation(*lowercase__			)




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          if not self.model_tester.is_training:
                return

          SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       self.model_tester.prepare_config_and_inputs_for_common()
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       True

          for model_class in self.all_model_classes:
                if model_class in [*get_values(lowercase__			)]:
                      continue

                SCREAMING_SNAKE_CASE_      :			List[Any]     =       model_class(lowercase__			)
                model.to(lowercase__			)
                model.train()
                SCREAMING_SNAKE_CASE_      :			Any     =       self._prepare_for_class(lowercase__				,     lowercase__				,     return_labels=lowercase__			)
                SCREAMING_SNAKE_CASE_      :			List[str]     =       model(**lowercase__			).loss
                loss.backward()




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_      :			int     =       self.model_tester.prepare_config_and_inputs_for_common()
          if not self.model_tester.is_training:
                return

          SCREAMING_SNAKE_CASE_      :			Tuple     =       False
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       True

          for model_class in self.all_model_classes:
                if model_class in [*get_values(lowercase__			)] or not model_class.supports_gradient_checkpointing:
                      continue
                # TODO: remove the following 3 lines once we have a MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING
                # this can then be incorporated into _prepare_for_class in test_modeling_common.py
                elif model_class.__name__ == "Data2VecVisionForSemanticSegmentation":
                      SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       inputs_dict["pixel_values"].shape
                      SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       torch.zeros(
                          [self.model_tester.batch_size, height, width]				,     device=lowercase__			).long()
                SCREAMING_SNAKE_CASE_      :			Dict     =       model_class(lowercase__			)
                model.gradient_checkpointing_enable()
                model.to(lowercase__			)
                model.train()
                SCREAMING_SNAKE_CASE_      :			List[str]     =       self._prepare_for_class(lowercase__				,     lowercase__				,     return_labels=lowercase__			)
                SCREAMING_SNAKE_CASE_      :			List[str]     =       model(**lowercase__			).loss
                loss.backward()




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_,						SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       self.model_tester.prepare_config_and_inputs_for_common()

          SCREAMING_SNAKE_CASE_      :			Tuple     =       _config_zero_init(lowercase__			)
          for model_class in self.all_model_classes:
                SCREAMING_SNAKE_CASE_      :			str     =       model_class(config=lowercase__			)
                for name, param in model.named_parameters():
                      # we skip lambda parameters as these require special initial values
                      # determined by config.layer_scale_init_value
                      if "lambda" in name:
                            continue
                      if 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"				,     )




    def   __lowerCamelCase      (					self				,     lowercase__				,     lowercase__				,     lowercase__				,     lowercase__=2e-4				,     lowercase__="outputs"				,     lowercase__=None			):






          """simple docstring"""






          super().check_pt_tf_outputs(lowercase__				,     lowercase__				,     lowercase__				,     lowercase__				,     lowercase__				,     lowercase__			)




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			Dict     =       self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*lowercase__			)







    @slow
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          for model_name in DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       DataaVecVisionModel.from_pretrained(lowercase__			)
                self.assertIsNotNone(lowercase__			)






def 					__lowerCamelCase			(      )							->   List[str]:
      """simple docstring"""

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





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




    @cached_property
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          return (
              BeitImageProcessor.from_pretrained("facebook/data2vec-vision-base-ft1k"			) if is_vision_available() else None
          )







    @slow
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			Any     =       DataaVecVisionForImageClassification.from_pretrained("facebook/data2vec-vision-base-ft1k"			).to(
              lowercase__			)

          SCREAMING_SNAKE_CASE_      :			Any     =       self.default_image_processor
          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       prepare_img()
          SCREAMING_SNAKE_CASE_      :			Optional[int]     =       image_processor(images=lowercase__				,     return_tensors="pt"			).to(lowercase__			)

          # forward pass
          with torch.no_grad():
                SCREAMING_SNAKE_CASE_      :			Tuple     =       model(**lowercase__			)
          SCREAMING_SNAKE_CASE_      :			List[str]     =       outputs.logits

          # verify the logits
          SCREAMING_SNAKE_CASE_      :			int     =       torch.Size((1, 1000)			)
          self.assertEqual(logits.shape				,     lowercase__			)

          SCREAMING_SNAKE_CASE_      :			List[Any]     =       torch.tensor([0.3277, -0.1395, 0.0911]			).to(lowercase__			)

          self.assertTrue(torch.allclose(logits[0, :3]				,     lowercase__				,     atol=1e-4			)			)

          SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       [model.config.labelaid[i] for i in ["remote control, remote", "tabby, tabby cat"]]
          self.assertEqual(logits[0].topk(2			).indices.cpu().tolist()				,     lowercase__			)




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


if is_torch_available():
      import torch

if is_vision_available():
      from PIL import Image

      from transformers import MobileNetVaImageProcessor
class 	SCREAMING_SNAKE_CASE__			(				unittest.TestCase      ):




    def __init__(					self				,     lowercase__				,     lowercase__=7				,     lowercase__=3				,     lowercase__=18				,     lowercase__=30				,     lowercase__=400				,     lowercase__=True				,     lowercase__=None				,     lowercase__=True				,     lowercase__=None				,     ):






          """simple docstring"""






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







    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          return {
              "do_resize": self.do_resize,
              "size": self.size,
              "do_center_crop": self.do_center_crop,
              "crop_size": self.crop_size,
          }






@require_torch
@require_vision
class 	SCREAMING_SNAKE_CASE__			(				_UpperCAmelCase,unittest.TestCase      ):
    _A			    =							MobileNetVaImageProcessor if is_vision_available() else None




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			Any     =       MobileNetVaImageProcessingTester(self			)




    @property
    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          return self.image_processor_tester.prepare_image_processor_dict()




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			Optional[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"			)			)




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			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}			)

          SCREAMING_SNAKE_CASE_      :			List[str]     =       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   __lowerCamelCase      (					self			):






          """simple docstring"""






          pass




    def   __lowerCamelCase      (					self			):






          """simple docstring"""






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

          # Test not batched input
          SCREAMING_SNAKE_CASE_      :			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
          SCREAMING_SNAKE_CASE_      :			List[Any]     =       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   __lowerCamelCase      (					self			):






          """simple docstring"""






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

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

          # Test batched
          SCREAMING_SNAKE_CASE_      :			Dict     =       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   __lowerCamelCase      (					self			):






          """simple docstring"""






          SCREAMING_SNAKE_CASE_      :			List[str]     =       self.image_processing_class(**self.image_processor_dict			)
          # create random PyTorch tensors
          SCREAMING_SNAKE_CASE_      :			Any     =       prepare_image_inputs(self.image_processor_tester				,     equal_resolution=lowercase__				,     torchify=lowercase__			)
          for image in image_inputs:
                self.assertIsInstance(lowercase__				,     torch.Tensor			)

          # Test not batched input
          SCREAMING_SNAKE_CASE_      :			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
          SCREAMING_SNAKE_CASE_      :			List[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"],
              )				,     )

