


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							(			UpperCamelCase__			):

							def       lowerCamelCase_ (							self:	Tuple							)			->   List[str]:





									"""simple docstring"""







									lowercase__            =      self.config_class(**self.inputs_dict							)
									self.parent.assertTrue(hasattr(UpperCamelCase_    ,						'''hidden_sizes'''							)							)
									self.parent.assertTrue(hasattr(UpperCamelCase_    ,						'''num_attention_heads'''							)							)
									self.parent.assertTrue(hasattr(UpperCamelCase_    ,						'''num_encoder_blocks'''							)							)


class        _a							:

							def __init__(							self:	Union[str, Any]    ,						UpperCamelCase_:	Optional[Any]    ,						UpperCamelCase_:	List[str]=13    ,						UpperCamelCase_:	Dict=64    ,						UpperCamelCase_:	List[str]=3    ,						UpperCamelCase_:	List[Any]=4    ,						UpperCamelCase_:	List[Any]=[2, 2, 2, 2]    ,						UpperCamelCase_:	Optional[Any]=[8, 4, 2, 1]    ,						UpperCamelCase_:	Tuple=[16, 32, 64, 128]    ,						UpperCamelCase_:	Dict=[1, 4, 8, 16]    ,						UpperCamelCase_:	Union[str, Any]=[1, 2, 4, 8]    ,						UpperCamelCase_:	List[Any]=True    ,						UpperCamelCase_:	Dict=True    ,						UpperCamelCase_:	Optional[Any]="gelu"    ,						UpperCamelCase_:	str=0.1    ,						UpperCamelCase_:	List[str]=0.1    ,						UpperCamelCase_:	Dict=0.02    ,						UpperCamelCase_:	Optional[Any]=3    ,						UpperCamelCase_:	str=None    ,						)			->   Any:





									"""simple docstring"""







									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       lowerCamelCase_ (							self:	int							)			->   int:





									"""simple docstring"""







									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       lowerCamelCase_ (							self:	Any							)			->   Dict:





									"""simple docstring"""







									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       lowerCamelCase_ (							self:	Optional[Any]    ,						UpperCamelCase_:	List[Any]    ,						UpperCamelCase_:	Dict    ,						UpperCamelCase_:	str							)			->   str:





									"""simple docstring"""







									lowercase__            =      SegformerModel(config=UpperCamelCase_							)
									model.to(UpperCamelCase_							)
									model.eval()
									lowercase__            =      model(UpperCamelCase_							)
									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       lowerCamelCase_ (							self:	Optional[Any]    ,						UpperCamelCase_:	Optional[Any]    ,						UpperCamelCase_:	List[str]    ,						UpperCamelCase_:	List[Any]							)			->   List[str]:





									"""simple docstring"""







									lowercase__            =      self.num_labels
									lowercase__            =      SegformerForSemanticSegmentation(UpperCamelCase_							)
									model.to(UpperCamelCase_							)
									model.eval()
									lowercase__            =      model(UpperCamelCase_							)
									self.parent.assertEqual(
									    result.logits.shape    ,						(self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)							)
									lowercase__            =      model(UpperCamelCase_    ,						labels=UpperCamelCase_							)
									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       lowerCamelCase_ (							self:	Tuple    ,						UpperCamelCase_:	Tuple    ,						UpperCamelCase_:	Any    ,						UpperCamelCase_:	List[Any]							)			->   List[Any]:





									"""simple docstring"""







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


							def       lowerCamelCase_ (							self:	Dict							)			->   Any:





									"""simple docstring"""







									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							(			UpperCamelCase__     ,	UpperCamelCase__     ,	unittest.TestCase			):
							_lowercase	:			Union[str, Any]        = (
							    (
							        SegformerModel,
							        SegformerForSemanticSegmentation,
							        SegformerForImageClassification,
							    )
							    if is_torch_available()
							    else ()
							)
							_lowercase	:			Union[str, Any]        = (
							    {
							        '''feature-extraction''': SegformerModel,
							        '''image-classification''': SegformerForImageClassification,
							        '''image-segmentation''': SegformerForSemanticSegmentation,
							    }
							    if is_torch_available()
							    else {}
							)

							_lowercase	:			Union[str, Any]        = True
							_lowercase	:			Any        = False
							_lowercase	:			Optional[int]        = False
							_lowercase	:			str        = False

							def       lowerCamelCase_ (							self:	int							)			->   Any:





									"""simple docstring"""







									lowercase__            =      SegformerModelTester(self							)
									lowercase__            =      SegformerConfigTester(self    ,						config_class=UpperCamelCase_							)

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





									"""simple docstring"""







									self.config_tester.run_common_tests()

							def       lowerCamelCase_ (							self:	Any							)			->   Any:





									"""simple docstring"""







									lowercase__            =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*UpperCamelCase_							)

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





									"""simple docstring"""







									lowercase__            =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_binary_image_segmentation(*UpperCamelCase_							)

							def       lowerCamelCase_ (							self:	Union[str, Any]							)			->   List[str]:





									"""simple docstring"""







									lowercase__            =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_segmentation(*UpperCamelCase_							)

							@unittest.skip('''SegFormer does not use inputs_embeds'''							)
							def       lowerCamelCase_ (							self:	Dict							)			->   List[Any]:





									"""simple docstring"""







									pass

							@unittest.skip('''SegFormer does not have get_input_embeddings method and get_output_embeddings methods'''							)
							def       lowerCamelCase_ (							self:	str							)			->   Any:





									"""simple docstring"""







									pass

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





									"""simple docstring"""







									lowercase__     ,		lowercase__            =      self.model_tester.prepare_config_and_inputs_for_common()

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

							def       lowerCamelCase_ (							self:	Tuple							)			->   int:





									"""simple docstring"""







									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(UpperCamelCase_							)
											model.to(UpperCamelCase_							)
											model.eval()
											with torch.no_grad():
													lowercase__            =      model(**self._prepare_for_class(UpperCamelCase_    ,						UpperCamelCase_							)							)
											lowercase__            =      outputs.attentions

											lowercase__            =      sum(self.model_tester.depths							)
											self.assertEqual(len(UpperCamelCase_							)    ,						UpperCamelCase_							)

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

											self.assertEqual(len(UpperCamelCase_							)    ,						UpperCamelCase_							)

											# 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 // 32) ** 2
											lowercase__            =      (self.model_tester.image_size // (32 * 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(UpperCamelCase_							)

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

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

											lowercase__            =      outputs.attentions

											self.assertEqual(len(UpperCamelCase_							)    ,						UpperCamelCase_							)
											# 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       lowerCamelCase_ (							self:	int							)			->   str:





									"""simple docstring"""







									def check_hidden_states_output(UpperCamelCase_:	Tuple    ,						UpperCamelCase_:	List[Any]    ,						UpperCamelCase_:	Optional[Any]							):
											lowercase__            =      model_class(UpperCamelCase_							)
											model.to(UpperCamelCase_							)
											model.eval()

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

											lowercase__            =      outputs.hidden_states

											lowercase__            =      self.model_tester.num_encoder_blocks
											self.assertEqual(len(UpperCamelCase_							)    ,						UpperCamelCase_							)

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

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

											check_hidden_states_output(UpperCamelCase_    ,						UpperCamelCase_    ,						UpperCamelCase_							)

							def       lowerCamelCase_ (							self:	Tuple							)			->   Union[str, Any]:





									"""simple docstring"""







									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(UpperCamelCase_							):
													continue

											lowercase__            =      model_class(UpperCamelCase_							)
											model.to(UpperCamelCase_							)
											model.train()
											lowercase__            =      self._prepare_for_class(UpperCamelCase_    ,						UpperCamelCase_    ,						return_labels=UpperCamelCase_							)
											lowercase__            =      model(**UpperCamelCase_							).loss
											loss.backward()

							@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''							)
							def       lowerCamelCase_ (							self:	Dict							)			->   Any:





									"""simple docstring"""







									pass


							@slow
							def       lowerCamelCase_ (							self:	Tuple							)			->   List[str]:





									"""simple docstring"""







									for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											lowercase__            =      SegformerModel.from_pretrained(UpperCamelCase_							)
											self.assertIsNotNone(UpperCamelCase_							)
def 			_a (      ):


		"""simple docstring"""




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


@require_torch
class        _a							(			unittest.TestCase			):

							@slow
							def       lowerCamelCase_ (							self:	Union[str, Any]							)			->   Optional[Any]:





									"""simple docstring"""







									lowercase__            =      SegformerImageProcessor(
									    image_scale=(512, 512)    ,						keep_ratio=UpperCamelCase_    ,						align=UpperCamelCase_    ,						do_random_crop=UpperCamelCase_							)
									lowercase__            =      SegformerForSemanticSegmentation.from_pretrained('''nvidia/segformer-b0-finetuned-ade-512-512'''							).to(
									    UpperCamelCase_							)

									lowercase__            =      prepare_img()
									lowercase__            =      image_processor(images=UpperCamelCase_    ,						return_tensors='''pt'''							)
									lowercase__            =      encoded_inputs.pixel_values.to(UpperCamelCase_							)

									with torch.no_grad():
											lowercase__            =      model(UpperCamelCase_							)

									lowercase__            =      torch.Size((1, model.config.num_labels, 128, 128)							)
									self.assertEqual(outputs.logits.shape    ,						UpperCamelCase_							)

									lowercase__            =      torch.tensor(
									    [
									        [[-4.6310, -5.5232, -6.2356], [-5.1921, -6.1444, -6.5996], [-5.4424, -6.2790, -6.7574]],
									        [[-12.1391, -13.3122, -13.9554], [-12.8732, -13.9352, -14.3563], [-12.9438, -13.8226, -14.2513]],
									        [[-12.5134, -13.4686, -14.4915], [-12.8669, -14.4343, -14.7758], [-13.2523, -14.5819, -15.0694]],
									    ]							).to(UpperCamelCase_							)
									self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]    ,						UpperCamelCase_    ,						atol=1E-4							)							)

							@slow
							def       lowerCamelCase_ (							self:	List[str]							)			->   List[Any]:





									"""simple docstring"""







									lowercase__            =      SegformerImageProcessor(
									    image_scale=(512, 512)    ,						keep_ratio=UpperCamelCase_    ,						align=UpperCamelCase_    ,						do_random_crop=UpperCamelCase_							)
									lowercase__            =      SegformerForSemanticSegmentation.from_pretrained(
									    '''nvidia/segformer-b1-finetuned-cityscapes-1024-1024'''							).to(UpperCamelCase_							)

									lowercase__            =      prepare_img()
									lowercase__            =      image_processor(images=UpperCamelCase_    ,						return_tensors='''pt'''							)
									lowercase__            =      encoded_inputs.pixel_values.to(UpperCamelCase_							)

									with torch.no_grad():
											lowercase__            =      model(UpperCamelCase_							)

									lowercase__            =      torch.Size((1, model.config.num_labels, 128, 128)							)
									self.assertEqual(outputs.logits.shape    ,						UpperCamelCase_							)

									lowercase__            =      torch.tensor(
									    [
									        [[-13.5748, -13.9111, -12.6500], [-14.3500, -15.3683, -14.2328], [-14.7532, -16.0424, -15.6087]],
									        [[-17.1651, -15.8725, -12.9653], [-17.2580, -17.3718, -14.8223], [-16.6058, -16.8783, -16.7452]],
									        [[-3.6456, -3.0209, -1.4203], [-3.0797, -3.1959, -2.0000], [-1.8757, -1.9217, -1.6997]],
									    ]							).to(UpperCamelCase_							)
									self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]    ,						UpperCamelCase_    ,						atol=1E-1							)							)


							@slow
							def       lowerCamelCase_ (							self:	Any							)			->   List[str]:





									"""simple docstring"""







									lowercase__            =      SegformerImageProcessor(
									    image_scale=(512, 512)    ,						keep_ratio=UpperCamelCase_    ,						align=UpperCamelCase_    ,						do_random_crop=UpperCamelCase_							)
									lowercase__            =      SegformerForSemanticSegmentation.from_pretrained('''nvidia/segformer-b0-finetuned-ade-512-512'''							).to(
									    UpperCamelCase_							)

									lowercase__            =      prepare_img()
									lowercase__            =      image_processor(images=UpperCamelCase_    ,						return_tensors='''pt'''							)
									lowercase__            =      encoded_inputs.pixel_values.to(UpperCamelCase_							)

									with torch.no_grad():
											lowercase__            =      model(UpperCamelCase_							)

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

									lowercase__            =      image_processor.post_process_semantic_segmentation(outputs=UpperCamelCase_    ,						target_sizes=[(500, 300)]							)
									lowercase__            =      torch.Size((500, 300)							)
									self.assertEqual(segmentation[0].shape    ,						UpperCamelCase_							)

									lowercase__            =      image_processor.post_process_semantic_segmentation(outputs=UpperCamelCase_							)
									lowercase__            =      torch.Size((128, 128)							)
									self.assertEqual(segmentation[0].shape    ,						UpperCamelCase_							)






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 LevitImageProcessor


class        _a							(			unittest.TestCase			):

							def __init__(							self:	Dict    ,						UpperCamelCase_:	Any    ,						UpperCamelCase_:	Dict=7    ,						UpperCamelCase_:	Optional[int]=3    ,						UpperCamelCase_:	List[Any]=18    ,						UpperCamelCase_:	Dict=30    ,						UpperCamelCase_:	Optional[int]=400    ,						UpperCamelCase_:	Optional[int]=True    ,						UpperCamelCase_:	Union[str, Any]=None    ,						UpperCamelCase_:	List[str]=True    ,						UpperCamelCase_:	Dict=None    ,						UpperCamelCase_:	Optional[int]=True    ,						UpperCamelCase_:	Tuple=[0.5, 0.5, 0.5]    ,						UpperCamelCase_:	List[str]=[0.5, 0.5, 0.5]    ,						)			->   int:





									"""simple docstring"""







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


							def       lowerCamelCase_ (							self:	List[str]							)			->   Optional[Any]:





									"""simple docstring"""







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


@require_torch
@require_vision
class        _a							(			UpperCamelCase__     ,	unittest.TestCase			):
							_lowercase	:			List[str]        = LevitImageProcessor if is_vision_available() else None

							def       lowerCamelCase_ (							self:	Optional[Any]							)			->   List[str]:





									"""simple docstring"""







									lowercase__            =      LevitImageProcessingTester(self							)

							@property
							def       lowerCamelCase_ (							self:	List[Any]							)			->   Any:





									"""simple docstring"""







									return self.image_processor_tester.prepare_image_processor_dict()

							def       lowerCamelCase_ (							self:	Union[str, Any]							)			->   str:





									"""simple docstring"""







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

							def       lowerCamelCase_ (							self:	str							)			->   Tuple:





									"""simple docstring"""







									lowercase__            =      self.image_processing_class.from_dict(self.image_processor_dict							)
									self.assertEqual(image_processor.size    ,						{'''shortest_edge''': 18}							)
									self.assertEqual(image_processor.crop_size    ,						{'''height''': 18, '''width''': 18}							)

									lowercase__            =      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:	List[str]							)			->   Dict:





									"""simple docstring"""







									pass

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





									"""simple docstring"""







									lowercase__            =      self.image_processing_class(**self.image_processor_dict							)
									# create random PIL images
									lowercase__            =      prepare_image_inputs(self.image_processor_tester    ,						equal_resolution=UpperCamelCase_							)
									for image in image_inputs:
											self.assertIsInstance(UpperCamelCase_    ,						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.crop_size['''height'''],
									        self.image_processor_tester.crop_size['''width'''],
									    )    ,						)

									# Test batched
									lowercase__            =      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       lowerCamelCase_ (							self:	Union[str, Any]							)			->   Optional[int]:





									"""simple docstring"""







									lowercase__            =      self.image_processing_class(**self.image_processor_dict							)
									# create random numpy tensors
									lowercase__            =      prepare_image_inputs(self.image_processor_tester    ,						equal_resolution=UpperCamelCase_    ,						numpify=UpperCamelCase_							)
									for image in image_inputs:
											self.assertIsInstance(UpperCamelCase_    ,						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.crop_size['''height'''],
									        self.image_processor_tester.crop_size['''width'''],
									    )    ,						)

									# Test batched
									lowercase__            =      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       lowerCamelCase_ (							self:	Any							)			->   Optional[Any]:





									"""simple docstring"""







									lowercase__            =      self.image_processing_class(**self.image_processor_dict							)
									# create random PyTorch tensors
									lowercase__            =      prepare_image_inputs(self.image_processor_tester    ,						equal_resolution=UpperCamelCase_    ,						torchify=UpperCamelCase_							)
									for image in image_inputs:
											self.assertIsInstance(UpperCamelCase_    ,						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.crop_size['''height'''],
									        self.image_processor_tester.crop_size['''width'''],
									    )    ,						)

									# Test batched
									lowercase__            =      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'''],
									    )    ,						)


