


'''simple docstring'''





import glob
import os
from typing import Dict, List, Union

import torch

from diffusers.utils import is_safetensors_available


if is_safetensors_available():
							import safetensors.torch

from huggingface_hub import snapshot_download

from diffusers import DiffusionPipeline, __version__
from diffusers.schedulers.scheduling_utils import SCHEDULER_CONFIG_NAME
from diffusers.utils import CONFIG_NAME, DIFFUSERS_CACHE, ONNX_WEIGHTS_NAME, WEIGHTS_NAME



class    __lowercase  (       UpperCamelCase__							):

							"""simple docstring"""


							def __init__(    self	)->	List[str]:
											self.register_to_config()
											super().__init__()





							def 		__magic_name__			(    self				, A_				, A_	)->	int:




											if dicta == dicta:
															return True
											else:
															_SCREAMING_SNAKE_CASE      = self._remove_meta_keys(lowerCAmelCase__	)
															_SCREAMING_SNAKE_CASE      = self._remove_meta_keys(lowerCAmelCase__	)
															if configa == configa:
																			print(F'''Warning !: Mismatch in keys {meta_keysa} and {meta_keysa}.'''	)
																			return True
											return False





							def 		__magic_name__			(    self				, A_	)->	Tuple:
											_SCREAMING_SNAKE_CASE      = []
											_SCREAMING_SNAKE_CASE      = config_dict.copy()
											for key in config_dict.keys():
															if key.startswith('_'	):
																			temp_dict.pop(lowerCAmelCase__	)
																			meta_keys.append(lowerCAmelCase__	)
											return (temp_dict, meta_keys)





							@torch.no_grad()
							def 		__magic_name__			(    self				, A_				, **A_	)->	Optional[int]:
											_SCREAMING_SNAKE_CASE      = kwargs.pop('cache_dir'				, lowerCAmelCase__	)
											_SCREAMING_SNAKE_CASE      = kwargs.pop('resume_download'				, lowerCAmelCase__	)
											_SCREAMING_SNAKE_CASE      = kwargs.pop('force_download'				, lowerCAmelCase__	)
											_SCREAMING_SNAKE_CASE      = kwargs.pop('proxies'				, lowerCAmelCase__	)
											_SCREAMING_SNAKE_CASE      = kwargs.pop('local_files_only'				, lowerCAmelCase__	)
											_SCREAMING_SNAKE_CASE      = kwargs.pop('use_auth_token'				, lowerCAmelCase__	)
											_SCREAMING_SNAKE_CASE      = kwargs.pop('revision'				, lowerCAmelCase__	)
											_SCREAMING_SNAKE_CASE      = kwargs.pop('torch_dtype'				, lowerCAmelCase__	)
											_SCREAMING_SNAKE_CASE      = kwargs.pop('device_map'				, lowerCAmelCase__	)

											_SCREAMING_SNAKE_CASE      = kwargs.pop('alpha'				, 0.5	)
											_SCREAMING_SNAKE_CASE      = kwargs.pop('interp'				, lowerCAmelCase__	)

											print('Received list'				, lowerCAmelCase__	)
											print(F'''Combining with alpha={alpha}, interpolation mode={interp}'''	)

											_SCREAMING_SNAKE_CASE      = len(lowerCAmelCase__	)
											# Ignore result from model_index_json comparision of the two checkpoints
											_SCREAMING_SNAKE_CASE      = kwargs.pop('force'				, lowerCAmelCase__	)

											# If less than 2 checkpoints, nothing to merge. If more than 3, not supported for now.
											if checkpoint_count > 3 or checkpoint_count < 2:
															raise ValueError(
															    'Received incorrect number of checkpoints to merge. Ensure that either 2 or 3 checkpoints are being'
															    ' passed.'	)

											print('Received the right number of checkpoints'	)
											# chkpt0, chkpt1 = pretrained_model_name_or_path_list[0:2]
											# chkpt2 = pretrained_model_name_or_path_list[2] if checkpoint_count == 3 else None

											# Validate that the checkpoints can be merged
											# Step 1: Load the model config and compare the checkpoints. We'll compare the model_index.json first while ignoring the keys starting with '_'
											_SCREAMING_SNAKE_CASE      = []
											for pretrained_model_name_or_path in pretrained_model_name_or_path_list:
															_SCREAMING_SNAKE_CASE      = DiffusionPipeline.load_config(
															    lowerCAmelCase__				, cache_dir=lowerCAmelCase__				, resume_download=lowerCAmelCase__				, force_download=lowerCAmelCase__				, proxies=lowerCAmelCase__				, local_files_only=lowerCAmelCase__				, use_auth_token=lowerCAmelCase__				, revision=lowerCAmelCase__				, )
															config_dicts.append(lowerCAmelCase__	)

											_SCREAMING_SNAKE_CASE      = True
											for idx in range(1				, len(lowerCAmelCase__	)	):
															comparison_result &= self._compare_model_configs(config_dicts[idx - 1]				, config_dicts[idx]	)
															if not force and comparison_result is False:
																			raise ValueError('Incompatible checkpoints. Please check model_index.json for the models.'	)
																			print(config_dicts[0]				, config_dicts[1]	)
											print('Compatible model_index.json files found'	)
											# Step 2: Basic Validation has succeeded. Let's download the models and save them into our local files.
											_SCREAMING_SNAKE_CASE      = []
											for pretrained_model_name_or_path, config_dict in zip(lowerCAmelCase__				, lowerCAmelCase__	):
															_SCREAMING_SNAKE_CASE      = [k for k in config_dict.keys() if not k.startswith('_'	)]
															_SCREAMING_SNAKE_CASE      = [os.path.join(lowerCAmelCase__				, '*'	) for k in folder_names]
															allow_patterns += [
															    WEIGHTS_NAME,
															    SCHEDULER_CONFIG_NAME,
															    CONFIG_NAME,
															    ONNX_WEIGHTS_NAME,
															    DiffusionPipeline.config_name,
															]
															_SCREAMING_SNAKE_CASE      = config_dict.get('_class_name'	)
															_SCREAMING_SNAKE_CASE      = {"diffusers": __version__, "pipeline_class": requested_pipeline_class}

															_SCREAMING_SNAKE_CASE      = (
															    pretrained_model_name_or_path
															    if os.path.isdir(lowerCAmelCase__	)
															    else snapshot_download(
															        lowerCAmelCase__				, cache_dir=lowerCAmelCase__				, resume_download=lowerCAmelCase__				, proxies=lowerCAmelCase__				, local_files_only=lowerCAmelCase__				, use_auth_token=lowerCAmelCase__				, revision=lowerCAmelCase__				, allow_patterns=lowerCAmelCase__				, user_agent=lowerCAmelCase__				, )
															)
															print('Cached Folder'				, lowerCAmelCase__	)
															cached_folders.append(lowerCAmelCase__	)

											# Step 3:-
											# Load the first checkpoint as a diffusion pipeline and modify its module state_dict in place
											_SCREAMING_SNAKE_CASE      = DiffusionPipeline.from_pretrained(
											    cached_folders[0]				, torch_dtype=lowerCAmelCase__				, device_map=lowerCAmelCase__	)
											final_pipe.to(self.device	)

											_SCREAMING_SNAKE_CASE      = None
											if len(lowerCAmelCase__	) > 2:
															_SCREAMING_SNAKE_CASE      = os.path.join(cached_folders[2]	)

											if interp == "sigmoid":
															_SCREAMING_SNAKE_CASE      = CheckpointMergerPipeline.sigmoid
											elif interp == "inv_sigmoid":
															_SCREAMING_SNAKE_CASE      = CheckpointMergerPipeline.inv_sigmoid
											elif interp == "add_diff":
															_SCREAMING_SNAKE_CASE      = CheckpointMergerPipeline.add_difference
											else:
															_SCREAMING_SNAKE_CASE      = CheckpointMergerPipeline.weighted_sum

											# Find each module's state dict.
											for attr in final_pipe.config.keys():
															if not attr.startswith('_'	):
																			_SCREAMING_SNAKE_CASE      = os.path.join(cached_folders[1]				, lowerCAmelCase__	)
																			if os.path.exists(lowerCAmelCase__	):
																							_SCREAMING_SNAKE_CASE      = [
																							    *glob.glob(os.path.join(lowerCAmelCase__				, '*.safetensors'	)	),
																							    *glob.glob(os.path.join(lowerCAmelCase__				, '*.bin'	)	),
																							]
																							_SCREAMING_SNAKE_CASE      = files[0] if len(lowerCAmelCase__	) > 0 else None
																			if len(lowerCAmelCase__	) < 3:
																							_SCREAMING_SNAKE_CASE      = None
																			else:
																							_SCREAMING_SNAKE_CASE      = os.path.join(cached_folders[2]				, lowerCAmelCase__	)
																							if os.path.exists(lowerCAmelCase__	):
																											_SCREAMING_SNAKE_CASE      = [
																											    *glob.glob(os.path.join(lowerCAmelCase__				, '*.safetensors'	)	),
																											    *glob.glob(os.path.join(lowerCAmelCase__				, '*.bin'	)	),
																											]
																											_SCREAMING_SNAKE_CASE      = files[0] if len(lowerCAmelCase__	) > 0 else None
																											# For an attr if both checkpoint_path_1 and 2 are None, ignore.
																											# If atleast one is present, deal with it according to interp method, of course only if the state_dict keys match.
																			if checkpoint_path_a is None and checkpoint_path_a is None:
																							print(F'''Skipping {attr}: not present in 2nd or 3d model'''	)
																							continue
																			try:
																							_SCREAMING_SNAKE_CASE      = getattr(lowerCAmelCase__				, lowerCAmelCase__	)
																							if isinstance(lowerCAmelCase__				, lowerCAmelCase__	):  # ignore requires_safety_checker boolean
																											continue
																							_SCREAMING_SNAKE_CASE      = getattr(lowerCAmelCase__				, 'state_dict'	)
																							_SCREAMING_SNAKE_CASE      = theta_a()

																							_SCREAMING_SNAKE_CASE      = getattr(lowerCAmelCase__				, 'load_state_dict'	)
																							_SCREAMING_SNAKE_CASE      = (
																							    safetensors.torch.load_file(lowerCAmelCase__	)
																							    if (is_safetensors_available() and checkpoint_path_a.endswith('.safetensors'	))
																							    else torch.load(lowerCAmelCase__				, map_location='cpu'	)
																							)
																							_SCREAMING_SNAKE_CASE      = None
																							if checkpoint_path_a:
																											_SCREAMING_SNAKE_CASE      = (
																											    safetensors.torch.load_file(lowerCAmelCase__	)
																											    if (is_safetensors_available() and checkpoint_path_a.endswith('.safetensors'	))
																											    else torch.load(lowerCAmelCase__				, map_location='cpu'	)
																											)

																							if not theta_a.keys() == theta_a.keys():
																											print(F'''Skipping {attr}: key mismatch'''	)
																											continue
																							if theta_a and not theta_a.keys() == theta_a.keys():
																											print(F'''Skipping {attr}:y mismatch'''	)
																			except Exception as e:
																							print(F'''Skipping {attr} do to an unexpected error: {str(lowerCAmelCase__	)}'''	)
																							continue
																			print(F'''MERGING {attr}'''	)

																			for key in theta_a.keys():
																							if theta_a:
																											_SCREAMING_SNAKE_CASE      = theta_func(theta_a[key]				, theta_a[key]				, theta_a[key]				, lowerCAmelCase__	)
																							else:
																											_SCREAMING_SNAKE_CASE      = theta_func(theta_a[key]				, theta_a[key]				, lowerCAmelCase__				, lowerCAmelCase__	)

																			del theta_a
																			del theta_a
																			update_theta_a(lowerCAmelCase__	)

																			del theta_a
											return final_pipe





							@staticmethod
							def 		__magic_name__			(    A_				, A_				, A_				, A_	)->	Union[str, Any]:
											return ((1 - alpha) * thetaa) + (alpha * thetaa)





							@staticmethod
							def 		__magic_name__			(    A_				, A_				, A_				, A_	)->	List[str]:
											_SCREAMING_SNAKE_CASE      = alpha * alpha * (3 - (2 * alpha))
											return thetaa + ((thetaa - thetaa) * alpha)





							@staticmethod
							def 		__magic_name__			(    A_				, A_				, A_				, A_	)->	str:
											import math

											_SCREAMING_SNAKE_CASE      = 0.5 - math.sin(math.asin(1.0 - 2.0 * alpha	) / 3.0	)
											return thetaa + ((thetaa - thetaa) * alpha)





							@staticmethod
							def 		__magic_name__			(    A_				, A_				, A_				, A_	)->	str:
											return thetaa + (thetaa - thetaa) * (1.0 - alpha)




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  :

							"""simple docstring"""


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





							def 		__magic_name__			(    self	)->	Optional[Any]:
											_SCREAMING_SNAKE_CASE      = floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)

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

											_SCREAMING_SNAKE_CASE      = self.get_config()

											return config, pixel_values, labels





							def 		__magic_name__			(    self	)->	Optional[int]:
											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=A_				, initializer_range=self.initializer_range				, is_hybrid=self.is_hybrid				, )





							def 		__magic_name__			(    self				, A_				, A_				, A_	)->	List[Any]:
											_SCREAMING_SNAKE_CASE      = DPTModel(config=A_	)
											model.to(A_	)
											model.eval()
											_SCREAMING_SNAKE_CASE      = model(A_	)
											self.parent.assertEqual(result.last_hidden_state.shape				, (self.batch_size, self.seq_length, self.hidden_size)	)





							def 		__magic_name__			(    self				, A_				, A_				, A_	)->	Tuple:
											_SCREAMING_SNAKE_CASE      = self.num_labels
											_SCREAMING_SNAKE_CASE      = DPTForDepthEstimation(A_	)
											model.to(A_	)
											model.eval()
											_SCREAMING_SNAKE_CASE      = model(A_	)
											self.parent.assertEqual(result.predicted_depth.shape				, (self.batch_size, self.image_size, self.image_size)	)





							def 		__magic_name__			(    self				, A_				, A_				, A_	)->	str:
											_SCREAMING_SNAKE_CASE      = self.num_labels
											_SCREAMING_SNAKE_CASE      = DPTForSemanticSegmentation(A_	)
											model.to(A_	)
											model.eval()
											_SCREAMING_SNAKE_CASE      = model(A_				, labels=A_	)
											self.parent.assertEqual(
											    result.logits.shape				, (self.batch_size, self.num_labels, self.image_size, self.image_size)	)





							def 		__magic_name__			(    self	)->	str:
											_SCREAMING_SNAKE_CASE      = self.prepare_config_and_inputs()
											_SCREAMING_SNAKE_CASE      ,      _SCREAMING_SNAKE_CASE      ,      _SCREAMING_SNAKE_CASE      = config_and_inputs
											_SCREAMING_SNAKE_CASE      = {'pixel_values': pixel_values}
											return config, inputs_dict







@require_torch
class    __lowercase  (       UpperCamelCase      ,     UpperCamelCase      ,     unittest.TestCase							):

							"""simple docstring"""


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

							SCREAMING_SNAKE_CASE   :					Tuple        =						False
							SCREAMING_SNAKE_CASE   :					str        =						False
							SCREAMING_SNAKE_CASE   :					Dict        =						False





							def 		__magic_name__			(    self	)->	List[str]:
											_SCREAMING_SNAKE_CASE      = DPTModelTester(self	)
											_SCREAMING_SNAKE_CASE      = ConfigTester(self				, config_class=A_				, has_text_modality=A_				, hidden_size=37	)





							def 		__magic_name__			(    self	)->	str:
											self.config_tester.run_common_tests()





							@unittest.skip(reason='DPT does not use inputs_embeds'	)
							def 		__magic_name__			(    self	)->	Optional[Any]:
											pass





							def 		__magic_name__			(    self	)->	int:
											_SCREAMING_SNAKE_CASE      ,      _SCREAMING_SNAKE_CASE      = self.model_tester.prepare_config_and_inputs_for_common()

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





							def 		__magic_name__			(    self	)->	Any:
											_SCREAMING_SNAKE_CASE      ,      _SCREAMING_SNAKE_CASE      = self.model_tester.prepare_config_and_inputs_for_common()

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

															_SCREAMING_SNAKE_CASE      = ['pixel_values']
															self.assertListEqual(arg_names[:1]				, A_	)





							def 		__magic_name__			(    self	)->	Union[str, Any]:
											_SCREAMING_SNAKE_CASE      = self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*A_	)





							def 		__magic_name__			(    self	)->	str:
											_SCREAMING_SNAKE_CASE      = self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_depth_estimation(*A_	)





							def 		__magic_name__			(    self	)->	Any:
											_SCREAMING_SNAKE_CASE      = self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_semantic_segmentation(*A_	)





							def 		__magic_name__			(    self	)->	List[Any]:
											for model_class in self.all_model_classes:
															if model_class.__name__ == "DPTForDepthEstimation":
																			continue

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

															if model_class in get_values(A_	):
																			continue

															_SCREAMING_SNAKE_CASE      = model_class(A_	)
															model.to(A_	)
															model.train()
															_SCREAMING_SNAKE_CASE      = self._prepare_for_class(A_				, A_				, return_labels=A_	)
															_SCREAMING_SNAKE_CASE      = model(**A_	).loss
															loss.backward()





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

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

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





							def 		__magic_name__			(    self	)->	str:
											_SCREAMING_SNAKE_CASE      ,      _SCREAMING_SNAKE_CASE      = self.model_tester.prepare_config_and_inputs_for_common()

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





							@slow
							def 		__magic_name__			(    self	)->	Optional[int]:
											for model_name in DPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															_SCREAMING_SNAKE_CASE      = DPTModel.from_pretrained(A_	)
															self.assertIsNotNone(A_	)







def 				SCREAMING_SNAKE_CASE (     ):

				"""simple docstring"""






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



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

							"""simple docstring"""


							def 		__magic_name__			(    self	)->	Optional[Any]:
											_SCREAMING_SNAKE_CASE      = DPTImageProcessor.from_pretrained('Intel/dpt-large'	)
											_SCREAMING_SNAKE_CASE      = DPTForDepthEstimation.from_pretrained('Intel/dpt-large'	).to(A_	)

											_SCREAMING_SNAKE_CASE      = prepare_img()
											_SCREAMING_SNAKE_CASE      = image_processor(images=A_				, return_tensors='pt'	).to(A_	)

											# forward pass
											with torch.no_grad():
															_SCREAMING_SNAKE_CASE      = model(**A_	)
															_SCREAMING_SNAKE_CASE      = outputs.predicted_depth

											# verify the predicted depth
											_SCREAMING_SNAKE_CASE      = torch.Size((1, 384, 384)	)
											self.assertEqual(predicted_depth.shape				, A_	)

											_SCREAMING_SNAKE_CASE      = torch.tensor(
											    [[6.3199, 6.3629, 6.4148], [6.3850, 6.3615, 6.4166], [6.3519, 6.3176, 6.3575]]	).to(A_	)

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





							def 		__magic_name__			(    self	)->	Optional[Any]:
											_SCREAMING_SNAKE_CASE      = DPTImageProcessor.from_pretrained('Intel/dpt-large-ade'	)
											_SCREAMING_SNAKE_CASE      = DPTForSemanticSegmentation.from_pretrained('Intel/dpt-large-ade'	).to(A_	)

											_SCREAMING_SNAKE_CASE      = prepare_img()
											_SCREAMING_SNAKE_CASE      = image_processor(images=A_				, return_tensors='pt'	).to(A_	)

											# forward pass
											with torch.no_grad():
															_SCREAMING_SNAKE_CASE      = model(**A_	)

											# verify the logits
											_SCREAMING_SNAKE_CASE      = torch.Size((1, 150, 480, 480)	)
											self.assertEqual(outputs.logits.shape				, A_	)

											_SCREAMING_SNAKE_CASE      = torch.tensor(
											    [[4.0480, 4.2420, 4.4360], [4.3124, 4.5693, 4.8261], [4.5768, 4.8965, 5.2163]]	).to(A_	)

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





							def 		__magic_name__			(    self	)->	Optional[int]:
											_SCREAMING_SNAKE_CASE      = DPTImageProcessor.from_pretrained('Intel/dpt-large-ade'	)
											_SCREAMING_SNAKE_CASE      = DPTForSemanticSegmentation.from_pretrained('Intel/dpt-large-ade'	).to(A_	)

											_SCREAMING_SNAKE_CASE      = prepare_img()
											_SCREAMING_SNAKE_CASE      = image_processor(images=A_				, return_tensors='pt'	).to(A_	)

											# forward pass
											with torch.no_grad():
															_SCREAMING_SNAKE_CASE      = model(**A_	)

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

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

											_SCREAMING_SNAKE_CASE      = image_processor.post_process_semantic_segmentation(outputs=A_	)
											_SCREAMING_SNAKE_CASE      = torch.Size((480, 480)	)
											self.assertEqual(segmentation[0].shape				, A_	)
