






"""simple docstring"""



import inspect
import unittest

from transformers import SegformerConfig, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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 (
        MODEL_MAPPING,
        SegformerForImageClassification,
        SegformerForSemanticSegmentation,
        SegformerModel,
    )
    from transformers.models.segformer.modeling_segformer import SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
    from PIL import Image

    from transformers import SegformerImageProcessor

class        a     (   a_	):







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       self.config_class(**self.inputs_dict       )
      self.parent.assertTrue(hasattr(_lowerCamelCase							,		'hidden_sizes'       )       )
      self.parent.assertTrue(hasattr(_lowerCamelCase							,		'num_attention_heads'       )       )
      self.parent.assertTrue(hasattr(_lowerCamelCase							,		'num_encoder_blocks'       )       )


class        a     :







    def __init__(			self							,		_lowerCamelCase							,		_lowerCamelCase=1_3							,		_lowerCamelCase=6_4							,		_lowerCamelCase=3							,		_lowerCamelCase=4							,		_lowerCamelCase=[2, 2, 2, 2]							,		_lowerCamelCase=[8, 4, 2, 1]							,		_lowerCamelCase=[1_6, 3_2, 6_4, 1_2_8]							,		_lowerCamelCase=[1, 4, 8, 1_6]							,		_lowerCamelCase=[1, 2, 4, 8]							,		_lowerCamelCase=True							,		_lowerCamelCase=True							,		_lowerCamelCase="gelu"							,		_lowerCamelCase=0.1							,		_lowerCamelCase=0.1							,		_lowerCamelCase=0.0_2							,		_lowerCamelCase=3							,		_lowerCamelCase=None							,		):
      lowercase							    =       parent
      lowercase							    =       batch_size
      lowercase							    =       image_size
      lowercase							    =       num_channels
      lowercase							    =       num_encoder_blocks
      lowercase							    =       sr_ratios
      lowercase							    =       depths
      lowercase							    =       hidden_sizes
      lowercase							    =       downsampling_rates
      lowercase							    =       num_attention_heads
      lowercase							    =       is_training
      lowercase							    =       use_labels
      lowercase							    =       hidden_act
      lowercase							    =       hidden_dropout_prob
      lowercase							    =       attention_probs_dropout_prob
      lowercase							    =       initializer_range
      lowercase							    =       num_labels
      lowercase							    =       scope







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

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

      lowercase							    =       self.get_config()
      return config, pixel_values, labels







    def 			UpperCamelCase_      (			self       ):
      return SegformerConfig(
          image_size=self.image_size							,		num_channels=self.num_channels							,		num_encoder_blocks=self.num_encoder_blocks							,		depths=self.depths							,		hidden_sizes=self.hidden_sizes							,		num_attention_heads=self.num_attention_heads							,		hidden_act=self.hidden_act							,		hidden_dropout_prob=self.hidden_dropout_prob							,		attention_probs_dropout_prob=self.attention_probs_dropout_prob							,		initializer_range=self.initializer_range							,		)







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase       ):
      lowercase							    =       SegformerModel(config=_lowerCamelCase       )
      model.to(_lowerCamelCase       )
      model.eval()
      lowercase							    =       model(_lowerCamelCase       )
      lowercase							    =       lowercase							    =       self.image_size // (self.downsampling_rates[-1] * 2)
      self.parent.assertEqual(
          result.last_hidden_state.shape							,		(self.batch_size, self.hidden_sizes[-1], expected_height, expected_width)       )







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase       ):
      lowercase							    =       self.num_labels
      lowercase							    =       SegformerForSemanticSegmentation(_lowerCamelCase       )
      model.to(_lowerCamelCase       )
      model.eval()
      lowercase							    =       model(_lowerCamelCase       )
      self.parent.assertEqual(
          result.logits.shape							,		(self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)       )
      lowercase							    =       model(_lowerCamelCase							,		labels=_lowerCamelCase       )
      self.parent.assertEqual(
          result.logits.shape							,		(self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)       )
      self.parent.assertGreater(result.loss							,		0.0       )







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase       ):
      lowercase							    =       1
      lowercase							    =       SegformerForSemanticSegmentation(config=_lowerCamelCase       )
      model.to(_lowerCamelCase       )
      model.eval()
      lowercase							    =       torch.randint(0							,		1							,		(self.batch_size, self.image_size, self.image_size)       ).to(_lowerCamelCase       )
      lowercase							    =       model(_lowerCamelCase							,		labels=_lowerCamelCase       )
      self.parent.assertGreater(result.loss							,		0.0       )







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       self.prepare_config_and_inputs()
      lowercase    ,     lowercase    ,     lowercase							    =       config_and_inputs
      lowercase							    =       {'pixel_values': pixel_values}
      return config, inputs_dict


@require_torch
class        a     (   a_,				a_,				unittest.TestCase	):
    UpperCAmelCase_ :     int	     =(
        (
            SegformerModel,
            SegformerForSemanticSegmentation,
            SegformerForImageClassification,
        )
        if is_torch_available()
        else ()
    )
    UpperCAmelCase_ :     Union[str, Any]	     =(
        {
            "feature-extraction": SegformerModel,
            "image-classification": SegformerForImageClassification,
            "image-segmentation": SegformerForSemanticSegmentation,
        }
        if is_torch_available()
        else {}
    )

    UpperCAmelCase_ :     Tuple	     =True
    UpperCAmelCase_ :     Optional[int]	     =False
    UpperCAmelCase_ :     List[str]	     =False
    UpperCAmelCase_ :     List[Any]	     =False







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       SegformerModelTester(self       )
      lowercase							    =       SegformerConfigTester(self							,		config_class=_lowerCamelCase       )







    def 			UpperCamelCase_      (			self       ):
      self.config_tester.run_common_tests()







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*_lowerCamelCase       )







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_binary_image_segmentation(*_lowerCamelCase       )







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_image_segmentation(*_lowerCamelCase       )







    @unittest.skip('SegFormer does not use inputs_embeds'       )
    def 			UpperCamelCase_      (			self       ):
      pass







    @unittest.skip('SegFormer does not have get_input_embeddings method and get_output_embeddings methods'       )
    def 			UpperCamelCase_      (			self       ):
      pass







    def 			UpperCamelCase_      (			self       ):
      lowercase    ,     lowercase							    =       self.model_tester.prepare_config_and_inputs_for_common()

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

        lowercase							    =       ['pixel_values']
        self.assertListEqual(arg_names[:1]							,		_lowerCamelCase       )







    def 			UpperCamelCase_      (			self       ):
      lowercase    ,     lowercase							    =       self.model_tester.prepare_config_and_inputs_for_common()
      lowercase							    =       True

      for model_class in self.all_model_classes:
        lowercase							    =       True
        lowercase							    =       False
        lowercase							    =       True
        lowercase							    =       model_class(_lowerCamelCase       )
        model.to(_lowerCamelCase       )
        model.eval()
        with torch.no_grad():
          lowercase							    =       model(**self._prepare_for_class(_lowerCamelCase							,		_lowerCamelCase       )       )
        lowercase							    =       outputs.attentions

        lowercase							    =       sum(self.model_tester.depths       )
        self.assertEqual(len(_lowerCamelCase       )							,		_lowerCamelCase       )

        # check that output_attentions also work using config
        del inputs_dict["output_attentions"]
        lowercase							    =       True
        lowercase							    =       model_class(_lowerCamelCase       )
        model.to(_lowerCamelCase       )
        model.eval()
        with torch.no_grad():
          lowercase							    =       model(**self._prepare_for_class(_lowerCamelCase							,		_lowerCamelCase       )       )
        lowercase							    =       outputs.attentions

        self.assertEqual(len(_lowerCamelCase       )							,		_lowerCamelCase       )

        # verify the first attentions (first block, first layer)
        lowercase							    =       (self.model_tester.image_size // 4) ** 2
        lowercase							    =       (self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
        self.assertListEqual(
            list(attentions[0].shape[-3:]       )							,		[self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]							,		)

        # verify the last attentions (last block, last layer)
        lowercase							    =       (self.model_tester.image_size // 3_2) ** 2
        lowercase							    =       (self.model_tester.image_size // (3_2 * self.model_tester.sr_ratios[-1])) ** 2
        self.assertListEqual(
            list(attentions[-1].shape[-3:]       )							,		[self.model_tester.num_attention_heads[-1], expected_seq_len, expected_reduced_seq_len]							,		)
        lowercase							    =       len(_lowerCamelCase       )

        # Check attention is always last and order is fine
        lowercase							    =       True
        lowercase							    =       True
        lowercase							    =       model_class(_lowerCamelCase       )
        model.to(_lowerCamelCase       )
        model.eval()
        with torch.no_grad():
          lowercase							    =       model(**self._prepare_for_class(_lowerCamelCase							,		_lowerCamelCase       )       )

        self.assertEqual(out_len + 1							,		len(_lowerCamelCase       )       )

        lowercase							    =       outputs.attentions

        self.assertEqual(len(_lowerCamelCase       )							,		_lowerCamelCase       )
        # verify the first attentions (first block, first layer)
        lowercase							    =       (self.model_tester.image_size // 4) ** 2
        lowercase							    =       (self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
        self.assertListEqual(
            list(self_attentions[0].shape[-3:]       )							,		[self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]							,		)







    def 			UpperCamelCase_      (			self       ):
      def check_hidden_states_output(_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase       ):
        lowercase							    =       model_class(_lowerCamelCase       )
        model.to(_lowerCamelCase       )
        model.eval()

        with torch.no_grad():
          lowercase							    =       model(**self._prepare_for_class(_lowerCamelCase							,		_lowerCamelCase       )       )

        lowercase							    =       outputs.hidden_states

        lowercase							    =       self.model_tester.num_encoder_blocks
        self.assertEqual(len(_lowerCamelCase       )							,		_lowerCamelCase       )

        # verify the first hidden states (first block)
        self.assertListEqual(
            list(hidden_states[0].shape[-3:]       )							,		[
                self.model_tester.hidden_sizes[0],
                self.model_tester.image_size // 4,
                self.model_tester.image_size // 4,
            ]							,		)

      lowercase    ,     lowercase							    =       self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        lowercase							    =       True
        check_hidden_states_output(_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase       )

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

        check_hidden_states_output(_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase       )







    def 			UpperCamelCase_      (			self       ):
      if not self.model_tester.is_training:
        return

      lowercase    ,     lowercase							    =       self.model_tester.prepare_config_and_inputs_for_common()
      lowercase							    =       True

      for model_class in self.all_model_classes:
        if model_class in get_values(_lowerCamelCase       ):
          continue

        lowercase							    =       model_class(_lowerCamelCase       )
        model.to(_lowerCamelCase       )
        model.train()
        lowercase							    =       self._prepare_for_class(_lowerCamelCase							,		_lowerCamelCase							,		return_labels=_lowerCamelCase       )
        lowercase							    =       model(**_lowerCamelCase       ).loss
        loss.backward()







    @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'       )
    def 			UpperCamelCase_      (			self       ):
      pass







    @slow
    def 			UpperCamelCase_      (			self       ):
      for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        lowercase							    =       SegformerModel.from_pretrained(_lowerCamelCase       )
        self.assertIsNotNone(_lowerCamelCase       )


def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  lowercase							    =       Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'    )
  return image



@require_torch
class        a     (   unittest.TestCase	):







    @slow
    def 			UpperCamelCase_      (			self       ):
      # only resize + normalize
      lowercase							    =       SegformerImageProcessor(
          image_scale=(5_1_2, 5_1_2)							,		keep_ratio=_lowerCamelCase							,		align=_lowerCamelCase							,		do_random_crop=_lowerCamelCase       )
      lowercase							    =       SegformerForSemanticSegmentation.from_pretrained('nvidia/segformer-b0-finetuned-ade-512-512'       ).to(
          _lowerCamelCase       )

      lowercase							    =       prepare_img()
      lowercase							    =       image_processor(images=_lowerCamelCase							,		return_tensors='pt'       )
      lowercase							    =       encoded_inputs.pixel_values.to(_lowerCamelCase       )

      with torch.no_grad():
        lowercase							    =       model(_lowerCamelCase       )

      lowercase							    =       torch.Size((1, model.config.num_labels, 1_2_8, 1_2_8)       )
      self.assertEqual(outputs.logits.shape							,		_lowerCamelCase       )

      lowercase							    =       torch.tensor(
          [
              [[-4.6_3_1_0, -5.5_2_3_2, -6.2_3_5_6], [-5.1_9_2_1, -6.1_4_4_4, -6.5_9_9_6], [-5.4_4_2_4, -6.2_7_9_0, -6.7_5_7_4]],
              [[-1_2.1_3_9_1, -1_3.3_1_2_2, -1_3.9_5_5_4], [-1_2.8_7_3_2, -1_3.9_3_5_2, -1_4.3_5_6_3], [-1_2.9_4_3_8, -1_3.8_2_2_6, -1_4.2_5_1_3]],
              [[-1_2.5_1_3_4, -1_3.4_6_8_6, -1_4.4_9_1_5], [-1_2.8_6_6_9, -1_4.4_3_4_3, -1_4.7_7_5_8], [-1_3.2_5_2_3, -1_4.5_8_1_9, -1_5.0_6_9_4]],
          ]       ).to(_lowerCamelCase       )
      self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]							,		_lowerCamelCase							,		atol=1e-4       )       )







    @slow
    def 			UpperCamelCase_      (			self       ):
      # only resize + normalize
      lowercase							    =       SegformerImageProcessor(
          image_scale=(5_1_2, 5_1_2)							,		keep_ratio=_lowerCamelCase							,		align=_lowerCamelCase							,		do_random_crop=_lowerCamelCase       )
      lowercase							    =       SegformerForSemanticSegmentation.from_pretrained(
          'nvidia/segformer-b1-finetuned-cityscapes-1024-1024'       ).to(_lowerCamelCase       )

      lowercase							    =       prepare_img()
      lowercase							    =       image_processor(images=_lowerCamelCase							,		return_tensors='pt'       )
      lowercase							    =       encoded_inputs.pixel_values.to(_lowerCamelCase       )

      with torch.no_grad():
        lowercase							    =       model(_lowerCamelCase       )

      lowercase							    =       torch.Size((1, model.config.num_labels, 1_2_8, 1_2_8)       )
      self.assertEqual(outputs.logits.shape							,		_lowerCamelCase       )

      lowercase							    =       torch.tensor(
          [
              [[-1_3.5_7_4_8, -1_3.9_1_1_1, -1_2.6_5_0_0], [-1_4.3_5_0_0, -1_5.3_6_8_3, -1_4.2_3_2_8], [-1_4.7_5_3_2, -1_6.0_4_2_4, -1_5.6_0_8_7]],
              [[-1_7.1_6_5_1, -1_5.8_7_2_5, -1_2.9_6_5_3], [-1_7.2_5_8_0, -1_7.3_7_1_8, -1_4.8_2_2_3], [-1_6.6_0_5_8, -1_6.8_7_8_3, -1_6.7_4_5_2]],
              [[-3.6_4_5_6, -3.0_2_0_9, -1.4_2_0_3], [-3.0_7_9_7, -3.1_9_5_9, -2.0_0_0_0], [-1.8_7_5_7, -1.9_2_1_7, -1.6_9_9_7]],
          ]       ).to(_lowerCamelCase       )
      self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]							,		_lowerCamelCase							,		atol=1e-1       )       )







    @slow
    def 			UpperCamelCase_      (			self       ):
      # only resize + normalize
      lowercase							    =       SegformerImageProcessor(
          image_scale=(5_1_2, 5_1_2)							,		keep_ratio=_lowerCamelCase							,		align=_lowerCamelCase							,		do_random_crop=_lowerCamelCase       )
      lowercase							    =       SegformerForSemanticSegmentation.from_pretrained('nvidia/segformer-b0-finetuned-ade-512-512'       ).to(
          _lowerCamelCase       )

      lowercase							    =       prepare_img()
      lowercase							    =       image_processor(images=_lowerCamelCase							,		return_tensors='pt'       )
      lowercase							    =       encoded_inputs.pixel_values.to(_lowerCamelCase       )

      with torch.no_grad():
        lowercase							    =       model(_lowerCamelCase       )

      lowercase							    =       outputs.logits.detach().cpu()

      lowercase							    =       image_processor.post_process_semantic_segmentation(outputs=_lowerCamelCase							,		target_sizes=[(5_0_0, 3_0_0)]       )
      lowercase							    =       torch.Size((5_0_0, 3_0_0)       )
      self.assertEqual(segmentation[0].shape							,		_lowerCamelCase       )

      lowercase							    =       image_processor.post_process_semantic_segmentation(outputs=_lowerCamelCase       )
      lowercase							    =       torch.Size((1_2_8, 1_2_8)       )
      self.assertEqual(segmentation[0].shape							,		_lowerCamelCase       )










"""simple docstring"""



import unittest

import numpy as np

from transformers.file_utils import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision

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 DPTImageProcessor

class        a     (   unittest.TestCase	):







    def __init__(			self							,		_lowerCamelCase							,		_lowerCamelCase=7							,		_lowerCamelCase=3							,		_lowerCamelCase=1_8							,		_lowerCamelCase=3_0							,		_lowerCamelCase=4_0_0							,		_lowerCamelCase=True							,		_lowerCamelCase=None							,		_lowerCamelCase=True							,		_lowerCamelCase=[0.5, 0.5, 0.5]							,		_lowerCamelCase=[0.5, 0.5, 0.5]							,		):
      lowercase							    =       size if size is not None else {'height': 1_8, 'width': 1_8}
      lowercase							    =       parent
      lowercase							    =       batch_size
      lowercase							    =       num_channels
      lowercase							    =       image_size
      lowercase							    =       min_resolution
      lowercase							    =       max_resolution
      lowercase							    =       do_resize
      lowercase							    =       size
      lowercase							    =       do_normalize
      lowercase							    =       image_mean
      lowercase							    =       image_std







    def 			UpperCamelCase_      (			self       ):
      return {
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_normalize": self.do_normalize,
          "do_resize": self.do_resize,
          "size": self.size,
      }


@require_torch
@require_vision
class        a     (   a_,				unittest.TestCase	):
    UpperCAmelCase_ :     Optional[int]	     =DPTImageProcessor if is_vision_available() else None







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       DPTImageProcessingTester(self       )







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







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       self.image_processing_class(**self.image_processor_dict       )
      self.assertTrue(hasattr(_lowerCamelCase							,		'image_mean'       )       )
      self.assertTrue(hasattr(_lowerCamelCase							,		'image_std'       )       )
      self.assertTrue(hasattr(_lowerCamelCase							,		'do_normalize'       )       )
      self.assertTrue(hasattr(_lowerCamelCase							,		'do_resize'       )       )
      self.assertTrue(hasattr(_lowerCamelCase							,		'size'       )       )







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       self.image_processing_class.from_dict(self.image_processor_dict       )
      self.assertEqual(image_processor.size							,		{'height': 1_8, 'width': 1_8}       )

      lowercase							    =       self.image_processing_class.from_dict(self.image_processor_dict							,		size=4_2       )
      self.assertEqual(image_processor.size							,		{'height': 4_2, 'width': 4_2}       )







    def 			UpperCamelCase_      (			self       ):
      # Initialize image_processing
      lowercase							    =       self.image_processing_class(**self.image_processor_dict       )
      # create random PIL images
      lowercase							    =       prepare_image_inputs(self.image_processor_tester							,		equal_resolution=_lowerCamelCase       )
      for image in image_inputs:
        self.assertIsInstance(_lowerCamelCase							,		Image.Image       )

      # Test not batched input
      lowercase							    =       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.size['height'],
              self.image_processor_tester.size['width'],
          )							,		)

      # Test batched
      lowercase							    =       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.size['height'],
              self.image_processor_tester.size['width'],
          )							,		)







    def 			UpperCamelCase_      (			self       ):
      # Initialize image_processing
      lowercase							    =       self.image_processing_class(**self.image_processor_dict       )
      # create random numpy tensors
      lowercase							    =       prepare_image_inputs(self.image_processor_tester							,		equal_resolution=_lowerCamelCase							,		numpify=_lowerCamelCase       )
      for image in image_inputs:
        self.assertIsInstance(_lowerCamelCase							,		np.ndarray       )

      # Test not batched input
      lowercase							    =       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.size['height'],
              self.image_processor_tester.size['width'],
          )							,		)

      # Test batched
      lowercase							    =       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.size['height'],
              self.image_processor_tester.size['width'],
          )							,		)







    def 			UpperCamelCase_      (			self       ):
      # Initialize image_processing
      lowercase							    =       self.image_processing_class(**self.image_processor_dict       )
      # create random PyTorch tensors
      lowercase							    =       prepare_image_inputs(self.image_processor_tester							,		equal_resolution=_lowerCamelCase							,		torchify=_lowerCamelCase       )
      for image in image_inputs:
        self.assertIsInstance(_lowerCamelCase							,		torch.Tensor       )

      # Test not batched input
      lowercase							    =       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.size['height'],
              self.image_processor_tester.size['width'],
          )							,		)

      # Test batched
      lowercase							    =       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.size['height'],
              self.image_processor_tester.size['width'],
          )							,		)


