

'''simple docstring'''


import inspect
import unittest

from transformers import 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, PoolFormerConfig, PoolFormerForImageClassification, PoolFormerModel
						from transformers.models.poolformer.modeling_poolformer import POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image

						from transformers import PoolFormerImageProcessor



class        lowercase    (	lowerCAmelCase_			):


							def     _snake_case				(      self)				->					int:
								UpperCAmelCase_		:   int													=       self.config_class(**self.inputs_dict)
								self.parent.assertTrue(hasattr(__UpperCamelCase     ,      'hidden_sizes'))
								self.parent.assertTrue(hasattr(__UpperCamelCase     ,      'num_encoder_blocks'))



class        lowercase    :


							def __init__(      self     ,      _snake_case     ,      _snake_case=13     ,      _snake_case=64     ,      _snake_case=3     ,      _snake_case=4     ,      _snake_case=[2, 2, 2, 2]     ,      _snake_case=[8, 4, 2, 1]     ,      _snake_case=[16, 32, 64, 128]     ,      _snake_case=[1, 4, 8, 16]     ,      _snake_case=False     ,      _snake_case=True     ,      _snake_case="gelu"     ,      _snake_case=0.1     ,      _snake_case=0.02     ,      _snake_case=3     ,      _snake_case=None     ,      )				->					Any:
								UpperCAmelCase_		:   Tuple													=       parent
								UpperCAmelCase_		:   Dict													=       batch_size
								UpperCAmelCase_		:   List[Any]													=       image_size
								UpperCAmelCase_		:   int													=       num_channels
								UpperCAmelCase_		:   str													=       num_encoder_blocks
								UpperCAmelCase_		:   List[Any]													=       sr_ratios
								UpperCAmelCase_		:   List[Any]													=       depths
								UpperCAmelCase_		:   Tuple													=       hidden_sizes
								UpperCAmelCase_		:   List[Any]													=       downsampling_rates
								UpperCAmelCase_		:   List[str]													=       is_training
								UpperCAmelCase_		:   Optional[int]													=       use_labels
								UpperCAmelCase_		:   int													=       hidden_act
								UpperCAmelCase_		:   Dict													=       hidden_dropout_prob
								UpperCAmelCase_		:   Optional[Any]													=       initializer_range
								UpperCAmelCase_		:   List[str]													=       num_labels
								UpperCAmelCase_		:   Optional[int]													=       scope


							def     _snake_case				(      self)				->					List[str]:
								UpperCAmelCase_		:   List[Any]													=       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

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

								UpperCAmelCase_		:   Dict													=       PoolFormerConfig(
								    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     ,      hidden_act=self.hidden_act     ,      hidden_dropout_prob=self.hidden_dropout_prob     ,      initializer_range=self.initializer_range     ,      )

								return config, pixel_values, labels


							def     _snake_case				(      self     ,      _snake_case     ,      _snake_case     ,      _snake_case)				->					Any:
								UpperCAmelCase_		:   Union[str, Any]													=       PoolFormerModel(config=__UpperCamelCase)
								model.to(__UpperCamelCase)
								model.eval()
								UpperCAmelCase_		:   Union[str, Any]													=       model(__UpperCamelCase)
								UpperCAmelCase_		:   int													=       self.image_size // 32.0
								self.parent.assertEqual(
								    result.last_hidden_state.shape     ,      (self.batch_size, self.hidden_sizes[-1], expected_height, expected_width))





							def     _snake_case				(      self)				->					Optional[int]:
								UpperCAmelCase_		:   Any													=       self.prepare_config_and_inputs()
								UpperCAmelCase_						,     UpperCAmelCase_						,     UpperCAmelCase_		:   Any													=       config_and_inputs
								UpperCAmelCase_		:   Tuple													=       {'pixel_values': pixel_values}
								return config, inputs_dict



@require_torch
class        lowercase    (	lowerCAmelCase_,       lowerCAmelCase_,       unittest.TestCase			):
							_lowerCamelCase		:   int= (PoolFormerModel, PoolFormerForImageClassification) if is_torch_available() else ()
							_lowerCamelCase		:   List[str]= (
							    {"feature-extraction": PoolFormerModel, "image-classification": PoolFormerForImageClassification}
							    if is_torch_available()
							    else {}
							)

							_lowerCamelCase		:   int= False
							_lowerCamelCase		:   Tuple= False
							_lowerCamelCase		:   str= False
							_lowerCamelCase		:   Optional[int]= False
							_lowerCamelCase		:   List[Any]= False


							def     _snake_case				(      self)				->					Dict:
								UpperCAmelCase_		:   Optional[Any]													=       PoolFormerModelTester(self)
								UpperCAmelCase_		:   List[Any]													=       PoolFormerConfigTester(self     ,      config_class=__UpperCamelCase)


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


							def     _snake_case				(      self)				->					Any:
								UpperCAmelCase_		:   List[str]													=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__UpperCamelCase)


							@unittest.skip('PoolFormer does not use inputs_embeds')
							def     _snake_case				(      self)				->					Dict:
								pass


							@unittest.skip('PoolFormer does not have get_input_embeddings method and get_output_embeddings methods')
							def     _snake_case				(      self)				->					int:
								pass


							def     _snake_case				(      self)				->					List[Any]:
								def check_hidden_states_output(_snake_case     ,      _snake_case     ,      _snake_case):
									UpperCAmelCase_		:   int													=       model_class(__UpperCamelCase)
									model.to(__UpperCamelCase)
									model.eval()

									with torch.no_grad():
										UpperCAmelCase_		:   Any													=       model(**self._prepare_for_class(__UpperCamelCase     ,      __UpperCamelCase))

									UpperCAmelCase_		:   Dict													=       outputs.hidden_states

									UpperCAmelCase_		:   Any													=       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,
									    ]     ,      )

								UpperCAmelCase_						,     UpperCAmelCase_		:   List[Any]													=       self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
									UpperCAmelCase_		:   Any													=       True
									check_hidden_states_output(__UpperCamelCase     ,      __UpperCamelCase     ,      __UpperCamelCase)

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									UpperCAmelCase_		:   Dict													=       True

									check_hidden_states_output(__UpperCamelCase     ,      __UpperCamelCase     ,      __UpperCamelCase)


							def     _snake_case				(      self)				->					Union[str, Any]:
								if not self.model_tester.is_training:
									return

								UpperCAmelCase_						,     UpperCAmelCase_		:   str													=       self.model_tester.prepare_config_and_inputs_for_common()
								UpperCAmelCase_		:   Optional[int]													=       True

								for model_class in self.all_model_classes:
									if model_class in get_values(__UpperCamelCase):
										continue
									UpperCAmelCase_		:   str													=       model_class(__UpperCamelCase)
									model.to(__UpperCamelCase)
									model.train()
									UpperCAmelCase_		:   Union[str, Any]													=       self._prepare_for_class(__UpperCamelCase     ,      __UpperCamelCase     ,      return_labels=__UpperCamelCase)
									UpperCAmelCase_		:   Dict													=       model(**__UpperCamelCase).loss
									loss.backward()


							def     _snake_case				(      self)				->					Any:
								UpperCAmelCase_						,     UpperCAmelCase_		:   Dict													=       self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
									UpperCAmelCase_		:   int													=       model_class(__UpperCamelCase)
									UpperCAmelCase_		:   Optional[Any]													=       inspect.signature(model.forward)
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									UpperCAmelCase_		:   str													=       [*signature.parameters.keys()]

									UpperCAmelCase_		:   int													=       ['pixel_values']
									self.assertListEqual(arg_names[:1]     ,      __UpperCamelCase)





							@slow
							def     _snake_case				(      self)				->					int:
								for model_name in POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									UpperCAmelCase_		:   Optional[Any]													=       PoolFormerModel.from_pretrained(__UpperCamelCase)
									self.assertIsNotNone(__UpperCamelCase)







def     SCREAMING_SNAKE_CASE(	)     ->     int:
	UpperCAmelCase_		:   Dict													=       Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'	)
	return image







@require_torch
class        lowercase    (	unittest.TestCase			):


							@slow
							def     _snake_case				(      self)				->					Tuple:
								UpperCAmelCase_		:   str													=       PoolFormerImageProcessor()
								UpperCAmelCase_		:   Tuple													=       PoolFormerForImageClassification.from_pretrained('sail/poolformer_s12').to(__UpperCamelCase)

								UpperCAmelCase_		:   str													=       image_processor(images=prepare_img()     ,      return_tensors='pt').to(__UpperCamelCase)

								# forward pass
								with torch.no_grad():
									UpperCAmelCase_		:   List[str]													=       model(**__UpperCamelCase)

								# verify the logits
								UpperCAmelCase_		:   Dict													=       torch.Size((1, 1000))
								self.assertEqual(outputs.logits.shape     ,      __UpperCamelCase)

								UpperCAmelCase_		:   List[str]													=       torch.tensor([-0.6_113, 0.1_685, -0.0_492]).to(__UpperCamelCase)
								self.assertTrue(torch.allclose(outputs.logits[0, :3]     ,      __UpperCamelCase     ,      atol=1e-4))











'''simple docstring'''







import inspect
import unittest

from transformers import DPTConfig
from transformers.file_utils import is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

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, DPTForDepthEstimation, DPTForSemanticSegmentation, DPTModel
      from transformers.models.dpt.modeling_dpt import DPT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import DPTImageProcessor

class    lowerCamelCase_				:






   '''simple docstring'''

   def __init__(	self  ,    __UpperCamelCase  ,    __UpperCamelCase=2  ,    __UpperCamelCase=32  ,    __UpperCamelCase=16  ,    __UpperCamelCase=3  ,    __UpperCamelCase=True  ,    __UpperCamelCase=True  ,    __UpperCamelCase=32  ,    __UpperCamelCase=4  ,    __UpperCamelCase=[0, 1, 2, 3]  ,    __UpperCamelCase=4  ,    __UpperCamelCase=37  ,    __UpperCamelCase="gelu"  ,    __UpperCamelCase=0.1  ,    __UpperCamelCase=0.1  ,    __UpperCamelCase=0.02  ,    __UpperCamelCase=3  ,    __UpperCamelCase=False  ,    __UpperCamelCase=None  ,    ):
       UpperCamelCase__	     =      parent
       UpperCamelCase__	     =      batch_size
       UpperCamelCase__	     =      image_size
       UpperCamelCase__	     =      patch_size
       UpperCamelCase__	     =      num_channels
       UpperCamelCase__	     =      is_training
       UpperCamelCase__	     =      use_labels
       UpperCamelCase__	     =      hidden_size
       UpperCamelCase__	     =      num_hidden_layers
       UpperCamelCase__	     =      backbone_out_indices
       UpperCamelCase__	     =      num_attention_heads
       UpperCamelCase__	     =      intermediate_size
       UpperCamelCase__	     =      hidden_act
       UpperCamelCase__	     =      hidden_dropout_prob
       UpperCamelCase__	     =      attention_probs_dropout_prob
       UpperCamelCase__	     =      initializer_range
       UpperCamelCase__	     =      num_labels
       UpperCamelCase__	     =      scope
       UpperCamelCase__	     =      is_hybrid
       # sequence length of DPT = num_patches + 1 (we add 1 for the [CLS] token)
       UpperCamelCase__	     =      (image_size // patch_size) ** 2
       UpperCamelCase__	     =      num_patches + 1


   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__	     =      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

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

       UpperCamelCase__	     =      self.get_config()

       return config, pixel_values, labels


   def 						_UpperCamelCase							(	self			):
       return DPTConfig(
           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  ,    backbone_out_indices=self.backbone_out_indices  ,    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=__UpperCamelCase  ,    initializer_range=self.initializer_range  ,    is_hybrid=self.is_hybrid  ,    )


   def 						_UpperCamelCase							(	self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase			):
       UpperCamelCase__	     =      DPTModel(config=__UpperCamelCase			)
       model.to(__UpperCamelCase			)
       model.eval()
       UpperCamelCase__	     =      model(__UpperCamelCase			)
       self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, self.seq_length, self.hidden_size)			)


   def 						_UpperCamelCase							(	self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase			):
       UpperCamelCase__	     =      self.num_labels
       UpperCamelCase__	     =      DPTForDepthEstimation(__UpperCamelCase			)
       model.to(__UpperCamelCase			)
       model.eval()
       UpperCamelCase__	     =      model(__UpperCamelCase			)
       self.parent.assertEqual(result.predicted_depth.shape  ,    (self.batch_size, self.image_size, self.image_size)			)


   def 						_UpperCamelCase							(	self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase			):
       UpperCamelCase__	     =      self.num_labels
       UpperCamelCase__	     =      DPTForSemanticSegmentation(__UpperCamelCase			)
       model.to(__UpperCamelCase			)
       model.eval()
       UpperCamelCase__	     =      model(__UpperCamelCase  ,    labels=__UpperCamelCase			)
       self.parent.assertEqual(
           result.logits.shape  ,    (self.batch_size, self.num_labels, self.image_size, self.image_size)			)







   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__	     =      self.prepare_config_and_inputs()
       UpperCamelCase__     ,	UpperCamelCase__     ,	UpperCamelCase__	     =      config_and_inputs
       UpperCamelCase__	     =      {"pixel_values": pixel_values}
       return config, inputs_dict

@require_torch
class    lowerCamelCase_				(						lowerCAmelCase_       ,     lowerCAmelCase_       ,     unittest.TestCase	):






   '''simple docstring'''

   A			:  int					=						(DPTModel, DPTForDepthEstimation, DPTForSemanticSegmentation) if is_torch_available() else ()
   A			:  Any					=						(
       {
           "depth-estimation": DPTForDepthEstimation,
           "feature-extraction": DPTModel,
           "image-segmentation": DPTForSemanticSegmentation,
       }
       if is_torch_available()
       else {}
   )

   A			:  int					=						False
   A			:  List[str]					=						False
   A			:  int					=						False


   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__	     =      DPTModelTester(self			)
       UpperCamelCase__	     =      ConfigTester(self  ,    config_class=__UpperCamelCase  ,    has_text_modality=__UpperCamelCase  ,    hidden_size=37			)


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


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


   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__     ,	UpperCamelCase__	     =      self.model_tester.prepare_config_and_inputs_for_common()

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


   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__     ,	UpperCamelCase__	     =      self.model_tester.prepare_config_and_inputs_for_common()

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

           UpperCamelCase__	     =      ["pixel_values"]
           self.assertListEqual(arg_names[:1]  ,    __UpperCamelCase			)


   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__	     =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__UpperCamelCase			)


   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__	     =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_depth_estimation(*__UpperCamelCase			)


   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__	     =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_semantic_segmentation(*__UpperCamelCase			)


   def 						_UpperCamelCase							(	self			):
       for model_class in self.all_model_classes:
           if model_class.__name__ == "DPTForDepthEstimation":
               continue

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

           if model_class in get_values(__UpperCamelCase			):
               continue

           UpperCamelCase__	     =      model_class(__UpperCamelCase			)
           model.to(__UpperCamelCase			)
           model.train()
           UpperCamelCase__	     =      self._prepare_for_class(__UpperCamelCase  ,    __UpperCamelCase  ,    return_labels=__UpperCamelCase			)
           UpperCamelCase__	     =      model(**__UpperCamelCase			).loss
           loss.backward()


   def 						_UpperCamelCase							(	self			):
       for model_class in self.all_model_classes:
           if model_class.__name__ == "DPTForDepthEstimation":
               continue

           UpperCamelCase__     ,	UpperCamelCase__	     =      self.model_tester.prepare_config_and_inputs_for_common()
           UpperCamelCase__	     =      False
           UpperCamelCase__	     =      True

           if model_class in get_values(__UpperCamelCase			) or not model_class.supports_gradient_checkpointing:
               continue
           UpperCamelCase__	     =      model_class(__UpperCamelCase			)
           model.to(__UpperCamelCase			)
           model.gradient_checkpointing_enable()
           model.train()
           UpperCamelCase__	     =      self._prepare_for_class(__UpperCamelCase  ,    __UpperCamelCase  ,    return_labels=__UpperCamelCase			)
           UpperCamelCase__	     =      model(**__UpperCamelCase			).loss
           loss.backward()


   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__     ,	UpperCamelCase__	     =      self.model_tester.prepare_config_and_inputs_for_common()

       UpperCamelCase__	     =      _config_zero_init(__UpperCamelCase			)
       for model_class in self.all_model_classes:
           UpperCamelCase__	     =      model_class(config=__UpperCamelCase			)
           # Skip the check for the backbone
           UpperCamelCase__	     =      []
           for name, module in model.named_modules():
               if module.__class__.__name__ == "DPTViTHybridEmbeddings":
                   UpperCamelCase__	     =      [f'{name}.{key}' for key in module.state_dict().keys()]
                   break

           for name, param in model.named_parameters():
               if param.requires_grad:
                   if name in backbone_params:
                       continue
                   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'  ,    )


   @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 DPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           UpperCamelCase__	     =      DPTModel.from_pretrained(__UpperCamelCase			)
           self.assertIsNotNone(__UpperCamelCase			)





def     snake_case__			():
    UpperCamelCase__	     =      Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						)
    return image





@require_torch
@require_vision
@slow
class    lowerCamelCase_				(						unittest.TestCase	):






   '''simple docstring'''

   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__	     =      DPTImageProcessor.from_pretrained("Intel/dpt-large"			)
       UpperCamelCase__	     =      DPTForDepthEstimation.from_pretrained("Intel/dpt-large"			).to(__UpperCamelCase			)

       UpperCamelCase__	     =      prepare_img()
       UpperCamelCase__	     =      image_processor(images=__UpperCamelCase  ,    return_tensors="pt"			).to(__UpperCamelCase			)

       # forward pass
       with torch.no_grad():
           UpperCamelCase__	     =      model(**__UpperCamelCase			)
           UpperCamelCase__	     =      outputs.predicted_depth

       # verify the predicted depth
       UpperCamelCase__	     =      torch.Size((1, 3_84, 3_84)			)
       self.assertEqual(predicted_depth.shape  ,    __UpperCamelCase			)

       UpperCamelCase__	     =      torch.tensor(
           [[6.3_199, 6.3_629, 6.4_148], [6.3_850, 6.3_615, 6.4_166], [6.3_519, 6.3_176, 6.3_575]]			).to(__UpperCamelCase			)

       self.assertTrue(torch.allclose(outputs.predicted_depth[0, :3, :3]  ,    __UpperCamelCase  ,    atol=1e-4			)			)


   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__	     =      DPTImageProcessor.from_pretrained("Intel/dpt-large-ade"			)
       UpperCamelCase__	     =      DPTForSemanticSegmentation.from_pretrained("Intel/dpt-large-ade"			).to(__UpperCamelCase			)

       UpperCamelCase__	     =      prepare_img()
       UpperCamelCase__	     =      image_processor(images=__UpperCamelCase  ,    return_tensors="pt"			).to(__UpperCamelCase			)

       # forward pass
       with torch.no_grad():
           UpperCamelCase__	     =      model(**__UpperCamelCase			)

       # verify the logits
       UpperCamelCase__	     =      torch.Size((1, 1_50, 4_80, 4_80)			)
       self.assertEqual(outputs.logits.shape  ,    __UpperCamelCase			)

       UpperCamelCase__	     =      torch.tensor(
           [[4.0_480, 4.2_420, 4.4_360], [4.3_124, 4.5_693, 4.8_261], [4.5_768, 4.8_965, 5.2_163]]			).to(__UpperCamelCase			)

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







   def 						_UpperCamelCase							(	self			):
       UpperCamelCase__	     =      DPTImageProcessor.from_pretrained("Intel/dpt-large-ade"			)
       UpperCamelCase__	     =      DPTForSemanticSegmentation.from_pretrained("Intel/dpt-large-ade"			).to(__UpperCamelCase			)

       UpperCamelCase__	     =      prepare_img()
       UpperCamelCase__	     =      image_processor(images=__UpperCamelCase  ,    return_tensors="pt"			).to(__UpperCamelCase			)

       # forward pass
       with torch.no_grad():
           UpperCamelCase__	     =      model(**__UpperCamelCase			)

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

       UpperCamelCase__	     =      image_processor.post_process_semantic_segmentation(outputs=__UpperCamelCase  ,    target_sizes=[(5_00, 3_00)]			)
       UpperCamelCase__	     =      torch.Size((5_00, 3_00)			)
       self.assertEqual(segmentation[0].shape  ,    __UpperCamelCase			)

       UpperCamelCase__	     =      image_processor.post_process_semantic_segmentation(outputs=__UpperCamelCase			)
       UpperCamelCase__	     =      torch.Size((4_80, 4_80)			)
       self.assertEqual(segmentation[0].shape  ,    __UpperCamelCase			)




