
"""simple docstring"""

import json
from typing import TYPE_CHECKING, List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_deberta import DebertaTokenizer


if TYPE_CHECKING:
					from transformers.pipelines.conversational import Conversation


_A            = logging.get_logger(__name__)

_A            = {'vocab_file': 'vocab.json', 'merges_file': 'merges.txt', 'tokenizer_file': 'tokenizer.json'}

_A            = {
    'vocab_file': {
        'microsoft/deberta-base': 'https://huggingface.co/microsoft/deberta-base/resolve/main/vocab.json',
        'microsoft/deberta-large': 'https://huggingface.co/microsoft/deberta-large/resolve/main/vocab.json',
        'microsoft/deberta-xlarge': 'https://huggingface.co/microsoft/deberta-xlarge/resolve/main/vocab.json',
        'microsoft/deberta-base-mnli': 'https://huggingface.co/microsoft/deberta-base-mnli/resolve/main/vocab.json',
        'microsoft/deberta-large-mnli': 'https://huggingface.co/microsoft/deberta-large-mnli/resolve/main/vocab.json',
        'microsoft/deberta-xlarge-mnli': (
            'https://huggingface.co/microsoft/deberta-xlarge-mnli/resolve/main/vocab.json'
        ),
    },
    'merges_file': {
        'microsoft/deberta-base': 'https://huggingface.co/microsoft/deberta-base/resolve/main/merges.txt',
        'microsoft/deberta-large': 'https://huggingface.co/microsoft/deberta-large/resolve/main/merges.txt',
        'microsoft/deberta-xlarge': 'https://huggingface.co/microsoft/deberta-xlarge/resolve/main/merges.txt',
        'microsoft/deberta-base-mnli': 'https://huggingface.co/microsoft/deberta-base-mnli/resolve/main/merges.txt',
        'microsoft/deberta-large-mnli': 'https://huggingface.co/microsoft/deberta-large-mnli/resolve/main/merges.txt',
        'microsoft/deberta-xlarge-mnli': (
            'https://huggingface.co/microsoft/deberta-xlarge-mnli/resolve/main/merges.txt'
        ),
    },
}

_A            = {
    'microsoft/deberta-base': 5_1_2,
    'microsoft/deberta-large': 5_1_2,
    'microsoft/deberta-xlarge': 5_1_2,
    'microsoft/deberta-base-mnli': 5_1_2,
    'microsoft/deberta-large-mnli': 5_1_2,
    'microsoft/deberta-xlarge-mnli': 5_1_2,
}

_A            = {
    'microsoft/deberta-base': {'do_lower_case': False},
    'microsoft/deberta-large': {'do_lower_case': False},
}






class        _lowercase   (				__UpperCAmelCase		):
	lowercase_        =	VOCAB_FILES_NAMES
	lowercase_        =	PRETRAINED_VOCAB_FILES_MAP
	lowercase_        =	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	lowercase_        =	['input_ids', 'attention_mask', 'token_type_ids']
	lowercase_        =	DebertaTokenizer




	def __init__( self		, UpperCAmelCase_=None		, UpperCAmelCase_=None		, UpperCAmelCase_=None		, UpperCAmelCase_="replace"		, UpperCAmelCase_="[CLS]"		, UpperCAmelCase_="[SEP]"		, UpperCAmelCase_="[SEP]"		, UpperCAmelCase_="[CLS]"		, UpperCAmelCase_="[UNK]"		, UpperCAmelCase_="[PAD]"		, UpperCAmelCase_="[MASK]"		, UpperCAmelCase_=False		, **UpperCAmelCase_		, )		->							Dict:
			super().__init__(
			    UpperCAmelCase_		, UpperCAmelCase_		, tokenizer_file=UpperCAmelCase_		, errors=UpperCAmelCase_		, bos_token=UpperCAmelCase_		, eos_token=UpperCAmelCase_		, unk_token=UpperCAmelCase_		, sep_token=UpperCAmelCase_		, cls_token=UpperCAmelCase_		, pad_token=UpperCAmelCase_		, mask_token=UpperCAmelCase_		, add_prefix_space=UpperCAmelCase_		, **UpperCAmelCase_		, )
			lowerCamelCase     :			List[str]		=    kwargs.pop('add_bos_token'		, UpperCAmelCase_					)

			lowerCamelCase     :			int		=    json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()					)
			if pre_tok_state.get('add_prefix_space'		, UpperCAmelCase_					) != add_prefix_space:
					lowerCamelCase     :			List[str]		=    getattr(UpperCAmelCase_		, pre_tok_state.pop('type'					)					)
					lowerCamelCase     :			Optional[Any]		=    add_prefix_space
					lowerCamelCase     :			Any		=    pre_tok_class(**UpperCAmelCase_					)

			lowerCamelCase     :			Dict		=    add_prefix_space




	@property
	def 			_UpperCamelCase    ( self					)		->							str:
			if self._mask_token is None:
					if self.verbose:
							logger.error('Using mask_token, but it is not set yet.'					)
					return None
			return str(self._mask_token					)




	@mask_token.setter
	def 			_UpperCamelCase    ( self		, UpperCAmelCase_					)		->							Optional[int]:
			lowerCamelCase     :			Dict		=    AddedToken(UpperCAmelCase_		, lstrip=UpperCAmelCase_		, rstrip=UpperCAmelCase_					) if isinstance(UpperCAmelCase_		, UpperCAmelCase_					) else value
			lowerCamelCase     :			Tuple		=    value




	def 			_UpperCamelCase    ( self		, UpperCAmelCase_		, UpperCAmelCase_ = None					)		->							List[int]:
			if token_ids_a is None:
					return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
			lowerCamelCase     :			Optional[int]		=    [self.cls_token_id]
			lowerCamelCase     :			Optional[int]		=    [self.sep_token_id]
			return cls + token_ids_a + sep + token_ids_a + sep




	def 			_UpperCamelCase    ( self		, UpperCAmelCase_		, UpperCAmelCase_ = None					)		->							List[int]:
			lowerCamelCase     :			str		=    [self.sep_token_id]
			lowerCamelCase     :			Tuple		=    [self.cls_token_id]

			if token_ids_a is None:
					return len(cls + token_ids_a + sep					) * [0]
			return len(cls + token_ids_a + sep					) * [0] + len(token_ids_a + sep					) * [1]




	def 			_UpperCamelCase    ( self		, *UpperCAmelCase_		, **UpperCAmelCase_					)		->							BatchEncoding:
			lowerCamelCase     :			Tuple		=    kwargs.get('is_split_into_words'		, UpperCAmelCase_					)
			assert self.add_prefix_space or not is_split_into_words, (
			    F"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True """
			    "to use it with pretokenized inputs."
			)

			return super()._batch_encode_plus(*UpperCAmelCase_		, **UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self		, *UpperCAmelCase_		, **UpperCAmelCase_					)		->							BatchEncoding:
			lowerCamelCase     :			Any		=    kwargs.get('is_split_into_words'		, UpperCAmelCase_					)

			assert self.add_prefix_space or not is_split_into_words, (
			    F"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True """
			    "to use it with pretokenized inputs."
			)

			return super()._encode_plus(*UpperCAmelCase_		, **UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self		, UpperCAmelCase_		, UpperCAmelCase_ = None					)		->							Tuple[str]:
			lowerCamelCase     :			Optional[Any]		=    self._tokenizer.model.save(UpperCAmelCase_		, name=UpperCAmelCase_					)
			return tuple(UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self		, UpperCAmelCase_					)		->							List[int]:
			lowerCamelCase     :			str		=    []
			for is_user, text in conversation.iter_texts():
					input_ids.extend(self.encode(UpperCAmelCase_		, add_special_tokens=UpperCAmelCase_					) + [self.eos_token_id]					)

			if len(UpperCAmelCase_					) > self.model_max_length:
					lowerCamelCase     :			List[str]		=    input_ids[-self.model_max_length :]
			return input_ids








"""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        _lowercase   :




	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		, )		->							List[str]:
			lowerCamelCase     :			List[str]		=    parent
			lowerCamelCase     :			Optional[int]		=    batch_size
			lowerCamelCase     :			Union[str, Any]		=    image_size
			lowerCamelCase     :			str		=    patch_size
			lowerCamelCase     :			Optional[Any]		=    num_channels
			lowerCamelCase     :			Tuple		=    is_training
			lowerCamelCase     :			int		=    use_labels
			lowerCamelCase     :			Union[str, Any]		=    hidden_size
			lowerCamelCase     :			List[Any]		=    num_hidden_layers
			lowerCamelCase     :			List[str]		=    backbone_out_indices
			lowerCamelCase     :			str		=    num_attention_heads
			lowerCamelCase     :			str		=    intermediate_size
			lowerCamelCase     :			str		=    hidden_act
			lowerCamelCase     :			Union[str, Any]		=    hidden_dropout_prob
			lowerCamelCase     :			Tuple		=    attention_probs_dropout_prob
			lowerCamelCase     :			List[Any]		=    initializer_range
			lowerCamelCase     :			Any		=    num_labels
			lowerCamelCase     :			Optional[Any]		=    scope
			lowerCamelCase     :			List[str]		=    is_hybrid
			# sequence length of DPT = num_patches + 1 (we add 1 for the [CLS] token)
			lowerCamelCase     :			Optional[int]		=    (image_size // patch_size) ** 2
			lowerCamelCase     :			Tuple		=    num_patches + 1




	def 			_UpperCamelCase    ( self					)		->							str:
			lowerCamelCase     :			Optional[Any]		=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

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

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

			return config, pixel_values, labels




	def 			_UpperCamelCase    ( self					)		->							List[str]:
			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_					)		->							Union[str, Any]:
			lowerCamelCase     :			Dict		=    DPTModel(config=UpperCAmelCase_					)
			model.to(UpperCAmelCase_					)
			model.eval()
			lowerCamelCase     :			List[Any]		=    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_					)		->							List[Any]:
			lowerCamelCase     :			str		=    self.num_labels
			lowerCamelCase     :			Optional[int]		=    DPTForDepthEstimation(UpperCAmelCase_					)
			model.to(UpperCAmelCase_					)
			model.eval()
			lowerCamelCase     :			str		=    model(UpperCAmelCase_					)
			self.parent.assertEqual(result.predicted_depth.shape		, (self.batch_size, self.image_size, self.image_size)					)




	def 			_UpperCamelCase    ( self		, UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_					)		->							Tuple:
			lowerCamelCase     :			Optional[Any]		=    self.num_labels
			lowerCamelCase     :			str		=    DPTForSemanticSegmentation(UpperCAmelCase_					)
			model.to(UpperCAmelCase_					)
			model.eval()
			lowerCamelCase     :			List[Any]		=    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					)		->							Dict:
			lowerCamelCase     :			int		=    self.prepare_config_and_inputs()
			lowerCamelCase	,    lowerCamelCase	,    lowerCamelCase     :			List[str]		=    config_and_inputs
			lowerCamelCase     :			int		=    {'pixel_values': pixel_values}
			return config, inputs_dict






@require_torch
class        _lowercase   (				__UpperCAmelCase				,       __UpperCAmelCase				,       unittest.TestCase		):
	lowercase_        =	(DPTModel, DPTForDepthEstimation, DPTForSemanticSegmentation) if is_torch_available() else ()
	lowercase_        =	(
	    {
	        'depth-estimation': DPTForDepthEstimation,
	        'feature-extraction': DPTModel,
	        'image-segmentation': DPTForSemanticSegmentation,
	    }
	    if is_torch_available()
	    else {}
	)

	lowercase_        =	False
	lowercase_        =	False
	lowercase_        =	False




	def 			_UpperCamelCase    ( self					)		->							str:
			lowerCamelCase     :			Optional[Any]		=    DPTModelTester(self					)
			lowerCamelCase     :			Optional[int]		=    ConfigTester(self		, config_class=UpperCAmelCase_		, has_text_modality=UpperCAmelCase_		, hidden_size=37					)




	def 			_UpperCamelCase    ( self					)		->							Tuple:
			self.config_tester.run_common_tests()




	@unittest.skip(reason='DPT does not use inputs_embeds'					)
	def 			_UpperCamelCase    ( self					)		->							int:
			pass




	def 			_UpperCamelCase    ( self					)		->							List[Any]:
			lowerCamelCase	,    lowerCamelCase     :			Optional[Any]		=    self.model_tester.prepare_config_and_inputs_for_common()

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




	def 			_UpperCamelCase    ( self					)		->							List[str]:
			lowerCamelCase	,    lowerCamelCase     :			str		=    self.model_tester.prepare_config_and_inputs_for_common()

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

					lowerCamelCase     :			Any		=    ['pixel_values']
					self.assertListEqual(arg_names[:1]		, UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self					)		->							Tuple:
			lowerCamelCase     :			str		=    self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self					)		->							Any:
			lowerCamelCase     :			Tuple		=    self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_depth_estimation(*UpperCAmelCase_					)




	def 			_UpperCamelCase    ( self					)		->							List[Any]:
			lowerCamelCase     :			int		=    self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_semantic_segmentation(*UpperCAmelCase_					)




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

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

					if model_class in get_values(UpperCAmelCase_					):
							continue

					lowerCamelCase     :			Tuple		=    model_class(UpperCAmelCase_					)
					model.to(UpperCAmelCase_					)
					model.train()
					lowerCamelCase     :			Tuple		=    self._prepare_for_class(UpperCAmelCase_		, UpperCAmelCase_		, return_labels=UpperCAmelCase_					)
					lowerCamelCase     :			int		=    model(**UpperCAmelCase_					).loss
					loss.backward()




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

					lowerCamelCase	,    lowerCamelCase     :			List[Any]		=    self.model_tester.prepare_config_and_inputs_for_common()
					lowerCamelCase     :			List[str]		=    False
					lowerCamelCase     :			int		=    True

					if model_class in get_values(UpperCAmelCase_					) or not model_class.supports_gradient_checkpointing:
							continue
					lowerCamelCase     :			Optional[int]		=    model_class(UpperCAmelCase_					)
					model.to(UpperCAmelCase_					)
					model.gradient_checkpointing_enable()
					model.train()
					lowerCamelCase     :			Optional[Any]		=    self._prepare_for_class(UpperCAmelCase_		, UpperCAmelCase_		, return_labels=UpperCAmelCase_					)
					lowerCamelCase     :			str		=    model(**UpperCAmelCase_					).loss
					loss.backward()




	def 			_UpperCamelCase    ( self					)		->							Dict:
			lowerCamelCase	,    lowerCamelCase     :			Optional[Any]		=    self.model_tester.prepare_config_and_inputs_for_common()

			lowerCamelCase     :			Union[str, Any]		=    _config_zero_init(UpperCAmelCase_					)
			for model_class in self.all_model_classes:
					lowerCamelCase     :			List[str]		=    model_class(config=UpperCAmelCase_					)
					# Skip the check for the backbone
					lowerCamelCase     :			Optional[int]		=    []
					for name, module in model.named_modules():
							if module.__class__.__name__ == "DPTViTHybridEmbeddings":
									lowerCamelCase     :			Optional[int]		=    [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					)		->							Dict:
			pass




	@slow
	def 			_UpperCamelCase    ( self					)		->							str:
			for model_name in DPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					lowerCamelCase     :			List[str]		=    DPTModel.from_pretrained(UpperCAmelCase_					)
					self.assertIsNotNone(UpperCAmelCase_					)


def 		UpperCAmelCase					(		):





		'''simple docstring'''


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






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




	def 			_UpperCamelCase    ( self					)		->							int:
			lowerCamelCase     :			int		=    DPTImageProcessor.from_pretrained('Intel/dpt-large'					)
			lowerCamelCase     :			List[str]		=    DPTForDepthEstimation.from_pretrained('Intel/dpt-large'					).to(UpperCAmelCase_					)

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

			# forward pass
			with torch.no_grad():
					lowerCamelCase     :			Dict		=    model(**UpperCAmelCase_					)
					lowerCamelCase     :			str		=    outputs.predicted_depth

			# verify the predicted depth
			lowerCamelCase     :			List[str]		=    torch.Size((1, 384, 384)					)
			self.assertEqual(predicted_depth.shape		, UpperCAmelCase_					)

			lowerCamelCase     :			Dict		=    torch.tensor(
			    [[6.3199, 6.3629, 6.4148], [6.3850, 6.3615, 6.4166], [6.3519, 6.3176, 6.3575]]					).to(UpperCAmelCase_					)

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




	def 			_UpperCamelCase    ( self					)		->							Tuple:
			lowerCamelCase     :			int		=    DPTImageProcessor.from_pretrained('Intel/dpt-large-ade'					)
			lowerCamelCase     :			Optional[Any]		=    DPTForSemanticSegmentation.from_pretrained('Intel/dpt-large-ade'					).to(UpperCAmelCase_					)

			lowerCamelCase     :			List[Any]		=    prepare_img()
			lowerCamelCase     :			Tuple		=    image_processor(images=UpperCAmelCase_		, return_tensors='pt'					).to(UpperCAmelCase_					)

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

			# verify the logits
			lowerCamelCase     :			int		=    torch.Size((1, 150, 480, 480)					)
			self.assertEqual(outputs.logits.shape		, UpperCAmelCase_					)

			lowerCamelCase     :			Tuple		=    torch.tensor(
			    [[4.0480, 4.2420, 4.4360], [4.3124, 4.5693, 4.8261], [4.5768, 4.8965, 5.2163]]					).to(UpperCAmelCase_					)

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




	def 			_UpperCamelCase    ( self					)		->							List[Any]:
			lowerCamelCase     :			Dict		=    DPTImageProcessor.from_pretrained('Intel/dpt-large-ade'					)
			lowerCamelCase     :			str		=    DPTForSemanticSegmentation.from_pretrained('Intel/dpt-large-ade'					).to(UpperCAmelCase_					)

			lowerCamelCase     :			Any		=    prepare_img()
			lowerCamelCase     :			Any		=    image_processor(images=UpperCAmelCase_		, return_tensors='pt'					).to(UpperCAmelCase_					)

			# forward pass
			with torch.no_grad():
					lowerCamelCase     :			Dict		=    model(**UpperCAmelCase_					)

			lowerCamelCase     :			int		=    outputs.logits.detach().cpu()

			lowerCamelCase     :			int		=    image_processor.post_process_semantic_segmentation(outputs=UpperCAmelCase_		, target_sizes=[(500, 300)]					)
			lowerCamelCase     :			Optional[Any]		=    torch.Size((500, 300)					)
			self.assertEqual(segmentation[0].shape		, UpperCAmelCase_					)

			lowerCamelCase     :			List[Any]		=    image_processor.post_process_semantic_segmentation(outputs=UpperCAmelCase_					)
			lowerCamelCase     :			Any		=    torch.Size((480, 480)					)
			self.assertEqual(segmentation[0].shape		, UpperCAmelCase_					)






