





'''simple docstring'''

import unittest

import numpy as np
import requests

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

			from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
			__lowerCamelCase			:			int									=      False

if is_vision_available():
			from PIL import Image

			from transformers import PixaStructImageProcessor

class    UpperCAmelCase			(    unittest.TestCase	):




		def __init__(self   :						List[str]				,      A__   :						Any				,      A__   :						List[str]=7				,      A__   :						List[str]=3				,      A__   :						List[str]=1_8				,      A__   :						Union[str, Any]=3_0				,      A__   :						Any=4_0_0				,      A__   :						List[str]=None				,      A__   :						Dict=True				,      A__   :						Union[str, Any]=True				,      A__   :						Tuple=None				,      )       ->			Union[str, Any]:
						lowercase    =			size if size is not None else {"""height""": 2_0, """width""": 2_0}
						lowercase    =			parent
						lowercase    =			batch_size
						lowercase    =			num_channels
						lowercase    =			image_size
						lowercase    =			min_resolution
						lowercase    =			max_resolution
						lowercase    =			size
						lowercase    =			do_normalize
						lowercase    =			do_convert_rgb
						lowercase    =			[5_1_2, 1_0_2_4, 2_0_4_8, 4_0_9_6]
						lowercase    =			patch_size if patch_size is not None else {"""height""": 1_6, """width""": 1_6}




		def 					UpperCAmelCase__ (self   :						Optional[Any]					)       ->			Tuple:
						return {"do_normalize": self.do_normalize, "do_convert_rgb": self.do_convert_rgb}





		def 					UpperCAmelCase__ (self   :						str					)       ->			Optional[Any]:
						lowercase    =			"""https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/australia.jpg"""
						lowercase    =			Image.open(requests.get(lowerCamelCase__				,      stream=lowerCamelCase__					).raw					).convert("RGB"					)
						return raw_image




@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11      ,							reason='''`Pix2StructImageProcessor` requires `torch>=1.11.0`.'''      ,							)
@require_torch
@require_vision
class    UpperCAmelCase			(    __UpperCAmelCase      ,							unittest.TestCase	):
		UpperCAmelCase       :						Optional[Any]			      =		PixaStructImageProcessor if is_vision_available() else None




		def 					UpperCAmelCase__ (self   :						int					)       ->			List[str]:
						lowercase    =			PixaStructImageProcessingTester(self					)




		@property
		def 					UpperCAmelCase__ (self   :						int					)       ->			List[Any]:
						return self.image_processor_tester.prepare_image_processor_dict()




		def 					UpperCAmelCase__ (self   :						Optional[Any]					)       ->			Optional[Any]:
						lowercase    =			self.image_processing_class(**self.image_processor_dict					)
						self.assertTrue(hasattr(lowerCamelCase__				,      "do_normalize"					)					)
						self.assertTrue(hasattr(lowerCamelCase__				,      "do_convert_rgb"					)					)




		def 					UpperCAmelCase__ (self   :						Tuple					)       ->			List[str]:
						lowercase    =			self.image_processor_tester.prepare_dummy_image()

						lowercase    =			self.image_processing_class(**self.image_processor_dict					)
						lowercase    =			2_0_4_8

						lowercase    =			image_processor(lowerCamelCase__				,      return_tensors="pt"				,      max_patches=lowerCamelCase__					)
						self.assertTrue(torch.allclose(inputs.flattened_patches.mean()				,      torch.tensor(0.0_6_0_6					)				,      atol=1e-3				,      rtol=1e-3					)					)




		def 					UpperCAmelCase__ (self   :						Optional[Any]					)       ->			Union[str, Any]:
						# Initialize image_processor
						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    =			(
						    (self.image_processor_tester.patch_size["""height"""] * self.image_processor_tester.patch_size["""width"""])
						    * self.image_processor_tester.num_channels
						) + 2

						for max_patch in self.image_processor_tester.max_patches:
										# Test not batched input
										lowercase    =			image_processor(
										    image_inputs[0]				,      return_tensors="pt"				,      max_patches=lowerCamelCase__					).flattened_patches
										self.assertEqual(
										    encoded_images.shape				,      (1, max_patch, expected_hidden_dim)				,      )

										# Test batched
										lowercase    =			image_processor(
										    lowerCamelCase__				,      return_tensors="pt"				,      max_patches=lowerCamelCase__					).flattened_patches
										self.assertEqual(
										    encoded_images.shape				,      (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)				,      )




		def 					UpperCAmelCase__ (self   :						List[Any]					)       ->			Optional[Any]:
						# Initialize image_processor
						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    =			(
						    (self.image_processor_tester.patch_size["""height"""] * self.image_processor_tester.patch_size["""width"""])
						    * self.image_processor_tester.num_channels
						) + 2

						lowercase    =			True

						for max_patch in self.image_processor_tester.max_patches:
										# Test not batched input
										with self.assertRaises(lowerCamelCase__					):
														lowercase    =			image_processor(
														    image_inputs[0]				,      return_tensors="pt"				,      max_patches=lowerCamelCase__					).flattened_patches

										lowercase    =			"""Hello"""

										lowercase    =			image_processor(
										    image_inputs[0]				,      return_tensors="pt"				,      max_patches=lowerCamelCase__				,      header_text=lowerCamelCase__					).flattened_patches
										self.assertEqual(
										    encoded_images.shape				,      (1, max_patch, expected_hidden_dim)				,      )

										# Test batched
										lowercase    =			image_processor(
										    lowerCamelCase__				,      return_tensors="pt"				,      max_patches=lowerCamelCase__				,      header_text=lowerCamelCase__					).flattened_patches
										self.assertEqual(
										    encoded_images.shape				,      (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)				,      )




		def 					UpperCAmelCase__ (self   :						int					)       ->			Any:
						# Initialize image_processor
						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					)

						lowercase    =			(
						    (self.image_processor_tester.patch_size["""height"""] * self.image_processor_tester.patch_size["""width"""])
						    * self.image_processor_tester.num_channels
						) + 2

						for max_patch in self.image_processor_tester.max_patches:
										# Test not batched input
										lowercase    =			image_processor(
										    image_inputs[0]				,      return_tensors="pt"				,      max_patches=lowerCamelCase__					).flattened_patches
										self.assertEqual(
										    encoded_images.shape				,      (1, max_patch, expected_hidden_dim)				,      )

										# Test batched
										lowercase    =			image_processor(
										    lowerCamelCase__				,      return_tensors="pt"				,      max_patches=lowerCamelCase__					).flattened_patches
										self.assertEqual(
										    encoded_images.shape				,      (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)				,      )





		def 					UpperCAmelCase__ (self   :						Optional[int]					)       ->			List[str]:
						# Initialize image_processor
						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    =			(
						    (self.image_processor_tester.patch_size["""height"""] * self.image_processor_tester.patch_size["""width"""])
						    * self.image_processor_tester.num_channels
						) + 2

						for max_patch in self.image_processor_tester.max_patches:
										# Test not batched input
										lowercase    =			image_processor(
										    image_inputs[0]				,      return_tensors="pt"				,      max_patches=lowerCamelCase__					).flattened_patches
										self.assertEqual(
										    encoded_images.shape				,      (1, max_patch, expected_hidden_dim)				,      )

										# Test batched
										lowercase    =			image_processor(
										    lowerCamelCase__				,      return_tensors="pt"				,      max_patches=lowerCamelCase__					).flattened_patches
										self.assertEqual(
										    encoded_images.shape				,      (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)				,      )




@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11      ,							reason='''`Pix2StructImageProcessor` requires `torch>=1.11.0`.'''      ,							)
@require_torch
@require_vision
class    UpperCAmelCase			(    __UpperCAmelCase      ,							unittest.TestCase	):
		UpperCAmelCase       :						Any			      =		PixaStructImageProcessor if is_vision_available() else None




		def 					UpperCAmelCase__ (self   :						Union[str, Any]					)       ->			List[str]:
						lowercase    =			PixaStructImageProcessingTester(self				,      num_channels=4					)
						lowercase    =			3




		@property
		def 					UpperCAmelCase__ (self   :						Optional[Any]					)       ->			int:
						return self.image_processor_tester.prepare_image_processor_dict()




		def 					UpperCAmelCase__ (self   :						Optional[int]					)       ->			Optional[Any]:
						lowercase    =			self.image_processing_class(**self.image_processor_dict					)
						self.assertTrue(hasattr(lowerCamelCase__				,      "do_normalize"					)					)
						self.assertTrue(hasattr(lowerCamelCase__				,      "do_convert_rgb"					)					)





		def 					UpperCAmelCase__ (self   :						List[str]					)       ->			Dict:
						# Initialize image_processor
						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    =			(
						    (self.image_processor_tester.patch_size["""height"""] * self.image_processor_tester.patch_size["""width"""])
						    * (self.image_processor_tester.num_channels - 1)
						) + 2

						for max_patch in self.image_processor_tester.max_patches:
										# Test not batched input
										lowercase    =			image_processor(
										    image_inputs[0]				,      return_tensors="pt"				,      max_patches=lowerCamelCase__					).flattened_patches
										self.assertEqual(
										    encoded_images.shape				,      (1, max_patch, expected_hidden_dim)				,      )

										# Test batched
										lowercase    =			image_processor(
										    lowerCamelCase__				,      return_tensors="pt"				,      max_patches=lowerCamelCase__					).flattened_patches
										self.assertEqual(
										    encoded_images.shape				,      (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)				,      )








"""simple docstring"""


import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch

   from transformers import MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation, MobileNetVaModel
   from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
   from PIL import Image

   from transformers import MobileNetVaImageProcessor

class 				_SCREAMING_SNAKE_CASE				(							__UpperCAmelCase  ):
   """simple docstring"""



   def 					UpperCAmelCase__(						self						)      ->							Union[str, Any]:
    lowercase__       :       Optional[Any]				=						self.config_class(**self.inputs_dict						)
    self.parent.assertTrue(hasattr(lowerCamelCase__ ,     """tf_padding"""						)						)
    self.parent.assertTrue(hasattr(lowerCamelCase__ ,     """depth_multiplier"""						)						)

class 				_SCREAMING_SNAKE_CASE				:
   """simple docstring"""



   def __init__(						self ,     lowerCamelCase__ ,     lowerCamelCase__=13 ,     lowerCamelCase__=3 ,     lowerCamelCase__=32 ,     lowerCamelCase__=0.25 ,     lowerCamelCase__=8 ,     lowerCamelCase__=8 ,     lowerCamelCase__=6 ,     lowerCamelCase__=32 ,     lowerCamelCase__=True ,     lowerCamelCase__=True ,     lowerCamelCase__=True ,     lowerCamelCase__="relu6" ,     lowerCamelCase__=1280 ,     lowerCamelCase__=0.1 ,     lowerCamelCase__=0.02 ,     lowerCamelCase__=True ,     lowerCamelCase__=True ,     lowerCamelCase__=10 ,     lowerCamelCase__=None ,     )      ->							List[Any]:
    lowercase__       :       int				=						parent
    lowercase__       :       Any				=						batch_size
    lowercase__       :       Optional[int]				=						num_channels
    lowercase__       :       int				=						image_size
    lowercase__       :       Tuple				=						depth_multiplier
    lowercase__       :       Tuple				=						depth_divisible_by
    lowercase__       :       str				=						min_depth
    lowercase__       :       int				=						expand_ratio
    lowercase__       :       List[str]				=						tf_padding
    lowercase__       :       Union[str, Any]				=						output_stride
    lowercase__       :       Optional[int]				=						first_layer_is_expansion
    lowercase__       :       Optional[Any]				=						finegrained_output
    lowercase__       :       Union[str, Any]				=						hidden_act
    lowercase__       :       List[Any]				=						last_hidden_size if finegrained_output else int(last_hidden_size * depth_multiplier						)
    lowercase__       :       Union[str, Any]				=						classifier_dropout_prob
    lowercase__       :       str				=						use_labels
    lowercase__       :       Optional[Any]				=						is_training
    lowercase__       :       List[Any]				=						num_labels
    lowercase__       :       List[str]				=						initializer_range
    lowercase__       :       Optional[int]				=						scope


   def 					UpperCAmelCase__(						self						)      ->							Any:
    lowercase__       :       Dict				=						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

    lowercase__       :       List[str]				=						None
    lowercase__       :       Tuple				=						None
    if self.use_labels:
     lowercase__       :       Optional[Any]				=						ids_tensor([self.batch_size] ,     self.num_labels						)
     lowercase__       :       Dict				=						ids_tensor([self.batch_size, self.image_size, self.image_size] ,     self.num_labels						)

    lowercase__       :       Dict				=						self.get_config()

    return config, pixel_values, labels, pixel_labels


   def 					UpperCAmelCase__(						self						)      ->							int:
    return MobileNetVaConfig(
        num_channels=self.num_channels ,     image_size=self.image_size ,     depth_multiplier=self.depth_multiplier ,     depth_divisible_by=self.depth_divisible_by ,     min_depth=self.min_depth ,     expand_ratio=self.expand_ratio ,     output_stride=self.output_stride ,     first_layer_is_expansion=self.first_layer_is_expansion ,     finegrained_output=self.finegrained_output ,     hidden_act=self.hidden_act ,     tf_padding=self.tf_padding ,     classifier_dropout_prob=self.classifier_dropout_prob ,     initializer_range=self.initializer_range ,     )


   def 					UpperCAmelCase__(						self ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__						)      ->							Dict:
    lowercase__       :       str				=						MobileNetVaModel(config=lowerCamelCase__						)
    model.to(lowerCamelCase__						)
    model.eval()
    lowercase__       :       List[Any]				=						model(lowerCamelCase__						)
    self.parent.assertEqual(
        result.last_hidden_state.shape ,     (
            self.batch_size,
            self.last_hidden_size,
            self.image_size // self.output_stride,
            self.image_size // self.output_stride,
        ) ,     )
    self.parent.assertEqual(
        result.pooler_output.shape ,     (self.batch_size, self.last_hidden_size) ,     )


   def 					UpperCAmelCase__(						self ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__						)      ->							List[Any]:
    lowercase__       :       Optional[int]				=						self.num_labels
    lowercase__       :       List[str]				=						MobileNetVaForImageClassification(lowerCamelCase__						)
    model.to(lowerCamelCase__						)
    model.eval()
    lowercase__       :       Dict				=						model(lowerCamelCase__ ,     labels=lowerCamelCase__						)
    self.parent.assertEqual(result.logits.shape ,     (self.batch_size, self.num_labels)						)


   def 					UpperCAmelCase__(						self ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__						)      ->							str:
    lowercase__       :       Dict				=						self.num_labels
    lowercase__       :       List[Any]				=						MobileNetVaForSemanticSegmentation(lowerCamelCase__						)
    model.to(lowerCamelCase__						)
    model.eval()
    lowercase__       :       List[Any]				=						model(lowerCamelCase__						)
    self.parent.assertEqual(
        result.logits.shape ,     (
            self.batch_size,
            self.num_labels,
            self.image_size // self.output_stride,
            self.image_size // self.output_stride,
        ) ,     )
    lowercase__       :       Tuple				=						model(lowerCamelCase__ ,     labels=lowerCamelCase__						)
    self.parent.assertEqual(
        result.logits.shape ,     (
            self.batch_size,
            self.num_labels,
            self.image_size // self.output_stride,
            self.image_size // self.output_stride,
        ) ,     )







   def 					UpperCAmelCase__(						self						)      ->							int:
    lowercase__       :       Optional[int]				=						self.prepare_config_and_inputs()
    lowercase__	,       lowercase__	,       lowercase__	,       lowercase__       :       Tuple				=						config_and_inputs
    lowercase__       :       List[Any]				=						{"""pixel_values""": pixel_values}
    return config, inputs_dict

@require_torch
class 				_SCREAMING_SNAKE_CASE				(							__UpperCAmelCase     ,   __UpperCAmelCase     ,   unittest.TestCase  ):
   """simple docstring"""



   _a   :       Optional[int]									=    (
       (MobileNetVaModel, MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation)
       if is_torch_available()
       else ()
   )
   _a   :       Tuple									=    (
       {
           '''feature-extraction''': MobileNetVaModel,
           '''image-classification''': MobileNetVaForImageClassification,
           '''image-segmentation''': MobileNetVaForSemanticSegmentation,
       }
       if is_torch_available()
       else {}
   )

   _a   :       List[str]									=    False
   _a   :       int									=    False
   _a   :       Optional[Any]									=    False
   _a   :       List[str]									=    False


   def 					UpperCAmelCase__(						self						)      ->							Optional[int]:
    lowercase__       :       List[Any]				=						MobileNetVaModelTester(self						)
    lowercase__       :       Any				=						MobileNetVaConfigTester(self ,     config_class=lowerCamelCase__ ,     has_text_modality=lowerCamelCase__						)


   def 					UpperCAmelCase__(						self						)      ->							Union[str, Any]:
    self.config_tester.run_common_tests()


   @unittest.skip(reason="""MobileNetV2 does not use inputs_embeds"""						)
   def 					UpperCAmelCase__(						self						)      ->							str:
    pass


   @unittest.skip(reason="""MobileNetV2 does not support input and output embeddings"""						)
   def 					UpperCAmelCase__(						self						)      ->							List[Any]:
    pass


   @unittest.skip(reason="""MobileNetV2 does not output attentions"""						)
   def 					UpperCAmelCase__(						self						)      ->							List[Any]:
    pass


   def 					UpperCAmelCase__(						self						)      ->							str:
    lowercase__	,       lowercase__       :       Optional[int]				=						self.model_tester.prepare_config_and_inputs_for_common()

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

     lowercase__       :       Union[str, Any]				=						["""pixel_values"""]
     self.assertListEqual(arg_names[:1] ,     lowerCamelCase__						)


   def 					UpperCAmelCase__(						self						)      ->							Union[str, Any]:
    lowercase__       :       Any				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*lowerCamelCase__						)


   def 					UpperCAmelCase__(						self						)      ->							Any:
    def check_hidden_states_output(lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__						):
     lowercase__       :       Optional[int]				=						model_class(lowerCamelCase__						)
     model.to(lowerCamelCase__						)
     model.eval()

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

     lowercase__       :       int				=						outputs.hidden_states

     lowercase__       :       Optional[int]				=						16
     self.assertEqual(len(lowerCamelCase__						) ,     lowerCamelCase__						)

    lowercase__	,       lowercase__       :       List[str]				=						self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
     lowercase__       :       Tuple				=						True
     check_hidden_states_output(lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__						)

     # check that output_hidden_states also work using config
     del inputs_dict["output_hidden_states"]
     lowercase__       :       Union[str, Any]				=						True

     check_hidden_states_output(lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__						)


   def 					UpperCAmelCase__(						self						)      ->							str:
    lowercase__       :       Union[str, Any]				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_image_classification(*lowerCamelCase__						)


   def 					UpperCAmelCase__(						self						)      ->							str:
    lowercase__       :       str				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_semantic_segmentation(*lowerCamelCase__						)







   @slow
   def 					UpperCAmelCase__(						self						)      ->							Optional[int]:
    for model_name in MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     lowercase__       :       List[str]				=						MobileNetVaModel.from_pretrained(lowerCamelCase__						)
     self.assertIsNotNone(lowerCamelCase__						)


def    _lowerCamelCase   (     ):
 lowercase__       :       List[Any]				=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""  )
 return image






@require_torch
@require_vision
class 				_SCREAMING_SNAKE_CASE				(							unittest.TestCase  ):
   """simple docstring"""



   @cached_property
   def 					UpperCAmelCase__(						self						)      ->							Optional[Any]:
    return (
        MobileNetVaImageProcessor.from_pretrained("""google/mobilenet_v2_1.0_224"""						) if is_vision_available() else None
    )


   @slow
   def 					UpperCAmelCase__(						self						)      ->							Optional[int]:
    lowercase__       :       Union[str, Any]				=						MobileNetVaForImageClassification.from_pretrained("""google/mobilenet_v2_1.0_224"""						).to(lowerCamelCase__						)

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

    # forward pass
    with torch.no_grad():
     lowercase__       :       Optional[Any]				=						model(**lowerCamelCase__						)

    # verify the logits
    lowercase__       :       List[Any]				=						torch.Size((1, 1001)						)
    self.assertEqual(outputs.logits.shape ,     lowerCamelCase__						)

    lowercase__       :       List[Any]				=						torch.tensor([0.2445, -1.1993, 0.1905]						).to(lowerCamelCase__						)

    self.assertTrue(torch.allclose(outputs.logits[0, :3] ,     lowerCamelCase__ ,     atol=1E-4						)						)







   @slow
   def 					UpperCAmelCase__(						self						)      ->							List[str]:
    lowercase__       :       Any				=						MobileNetVaForSemanticSegmentation.from_pretrained("""google/deeplabv3_mobilenet_v2_1.0_513"""						)
    lowercase__       :       Optional[int]				=						model.to(lowerCamelCase__						)

    lowercase__       :       int				=						MobileNetVaImageProcessor.from_pretrained("""google/deeplabv3_mobilenet_v2_1.0_513"""						)

    lowercase__       :       Tuple				=						prepare_img()
    lowercase__       :       int				=						image_processor(images=lowerCamelCase__ ,     return_tensors="""pt"""						).to(lowerCamelCase__						)

    # forward pass
    with torch.no_grad():
     lowercase__       :       List[Any]				=						model(**lowerCamelCase__						)
    lowercase__       :       int				=						outputs.logits

    # verify the logits
    lowercase__       :       Any				=						torch.Size((1, 21, 65, 65)						)
    self.assertEqual(logits.shape ,     lowerCamelCase__						)

    lowercase__       :       Union[str, Any]				=						torch.tensor(
        [
            [[17.5790, 17.7581, 18.3355], [18.3257, 18.4230, 18.8973], [18.6169, 18.8650, 19.2187]],
            [[-2.1595, -2.0977, -2.3741], [-2.4226, -2.3028, -2.6835], [-2.7819, -2.5991, -2.7706]],
            [[4.2058, 4.8317, 4.7638], [4.4136, 5.0361, 4.9383], [4.5028, 4.9644, 4.8734]],
        ] ,     device=lowerCamelCase__ ,     )

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