import inspect
import unittest

from transformers import SegformerConfig, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
							import torch

							from transformers import (
							    MODEL_MAPPING,
							    SegformerForImageClassification,
							    SegformerForSemanticSegmentation,
							    SegformerModel,
							)
							from transformers.models.segformer.modeling_segformer import SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
							from PIL import Image

							from transformers import SegformerImageProcessor


class 						lowercase    (     a     ):




							def 	__snake_case(						self   :					Tuple      )					->				Tuple:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.config_class(**self.inputs_dict      )
												self.parent.assertTrue(hasattr(_UpperCamelCase	,							"hidden_sizes"      )      )
												self.parent.assertTrue(hasattr(_UpperCamelCase	,							"num_attention_heads"      )      )
												self.parent.assertTrue(hasattr(_UpperCamelCase	,							"num_encoder_blocks"      )      )



class 						lowercase    :




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



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       parent
												SCREAMING_SNAKE_CASE    			=       batch_size
												SCREAMING_SNAKE_CASE    			=       image_size
												SCREAMING_SNAKE_CASE    			=       num_channels
												SCREAMING_SNAKE_CASE    			=       num_encoder_blocks
												SCREAMING_SNAKE_CASE    			=       sr_ratios
												SCREAMING_SNAKE_CASE    			=       depths
												SCREAMING_SNAKE_CASE    			=       hidden_sizes
												SCREAMING_SNAKE_CASE    			=       downsampling_rates
												SCREAMING_SNAKE_CASE    			=       num_attention_heads
												SCREAMING_SNAKE_CASE    			=       is_training
												SCREAMING_SNAKE_CASE    			=       use_labels
												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




							def 	__snake_case(						self   :					Tuple      )					->				str:



												'''simple docstring'''

												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 	__snake_case(						self   :					Tuple      )					->				Optional[int]:



												'''simple docstring'''

												return SegformerConfig(
												    image_size=self.image_size	,							num_channels=self.num_channels	,							num_encoder_blocks=self.num_encoder_blocks	,							depths=self.depths	,							hidden_sizes=self.hidden_sizes	,							num_attention_heads=self.num_attention_heads	,							hidden_act=self.hidden_act	,							hidden_dropout_prob=self.hidden_dropout_prob	,							attention_probs_dropout_prob=self.attention_probs_dropout_prob	,							initializer_range=self.initializer_range	,							)




							def 	__snake_case(						self   :					List[Any]	,							_UpperCamelCase   :					Dict	,							_UpperCamelCase   :					Optional[Any]	,							_UpperCamelCase   :					int      )					->				Union[str, Any]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       SegformerModel(config=_UpperCamelCase      )
												model.to(_UpperCamelCase      )
												model.eval()
												SCREAMING_SNAKE_CASE    			=       model(_UpperCamelCase      )
												SCREAMING_SNAKE_CASE    			=       SCREAMING_SNAKE_CASE    			=       self.image_size // (self.downsampling_rates[-1] * 2)
												self.parent.assertEqual(
												    result.last_hidden_state.shape	,							(self.batch_size, self.hidden_sizes[-1], expected_height, expected_width)      )




							def 	__snake_case(						self   :					Union[str, Any]	,							_UpperCamelCase   :					List[Any]	,							_UpperCamelCase   :					int	,							_UpperCamelCase   :					Any      )					->				int:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.num_labels
												SCREAMING_SNAKE_CASE    			=       SegformerForSemanticSegmentation(_UpperCamelCase      )
												model.to(_UpperCamelCase      )
												model.eval()
												SCREAMING_SNAKE_CASE    			=       model(_UpperCamelCase      )
												self.parent.assertEqual(
												    result.logits.shape	,							(self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)      )
												SCREAMING_SNAKE_CASE    			=       model(_UpperCamelCase	,							labels=_UpperCamelCase      )
												self.parent.assertEqual(
												    result.logits.shape	,							(self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)      )
												self.parent.assertGreater(result.loss	,							0.0      )




							def 	__snake_case(						self   :					List[str]	,							_UpperCamelCase   :					Tuple	,							_UpperCamelCase   :					Union[str, Any]	,							_UpperCamelCase   :					int      )					->				Dict:



												'''simple docstring'''

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





							def 	__snake_case(						self   :					Tuple      )					->				str:



												'''simple docstring'''

												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    (     a				,       a				,       unittest.TestCase     ):
							lowercase__						:       str								=							(
							    (
							        SegformerModel,
							        SegformerForSemanticSegmentation,
							        SegformerForImageClassification,
							    )
							    if is_torch_available()
							    else ()
							)
							lowercase__						:       Any								=							(
							    {
							        """feature-extraction""": SegformerModel,
							        """image-classification""": SegformerForImageClassification,
							        """image-segmentation""": SegformerForSemanticSegmentation,
							    }
							    if is_torch_available()
							    else {}
							)

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




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



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       SegformerModelTester(self      )
												SCREAMING_SNAKE_CASE    			=       SegformerConfigTester(self	,							config_class=_UpperCamelCase      )




							def 	__snake_case(						self   :					Any      )					->				Any:



												'''simple docstring'''

												self.config_tester.run_common_tests()




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



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*_UpperCamelCase      )




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



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_binary_image_segmentation(*_UpperCamelCase      )




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



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_image_segmentation(*_UpperCamelCase      )




							@unittest.skip("SegFormer does not use inputs_embeds"      )
							def 	__snake_case(						self   :					Any      )					->				List[str]:



												'''simple docstring'''

												pass




							@unittest.skip("SegFormer does not have get_input_embeddings method and get_output_embeddings methods"      )
							def 	__snake_case(						self   :					str      )					->				List[Any]:



												'''simple docstring'''

												pass




							def 	__snake_case(						self   :					str      )					->				Optional[int]:



												'''simple docstring'''

												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(_UpperCamelCase      )
																	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]	,							_UpperCamelCase      )




							def 	__snake_case(						self   :					int      )					->				Dict:



												'''simple docstring'''

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

												for model_class in self.all_model_classes:
																	SCREAMING_SNAKE_CASE    			=       True
																	SCREAMING_SNAKE_CASE    			=       False
																	SCREAMING_SNAKE_CASE    			=       True
																	SCREAMING_SNAKE_CASE    			=       model_class(_UpperCamelCase      )
																	model.to(_UpperCamelCase      )
																	model.eval()
																	with torch.no_grad():
																						SCREAMING_SNAKE_CASE    			=       model(**self._prepare_for_class(_UpperCamelCase	,							_UpperCamelCase      )      )
																	SCREAMING_SNAKE_CASE    			=       outputs.attentions

																	SCREAMING_SNAKE_CASE    			=       sum(self.model_tester.depths      )
																	self.assertEqual(len(_UpperCamelCase      )	,							_UpperCamelCase      )

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

																	self.assertEqual(len(_UpperCamelCase      )	,							_UpperCamelCase      )

																	# verify the first attentions (first block, first layer)
																	SCREAMING_SNAKE_CASE    			=       (self.model_tester.image_size // 4) ** 2
																	SCREAMING_SNAKE_CASE    			=       (self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
																	self.assertListEqual(
																	    list(attentions[0].shape[-3:]      )	,							[self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]	,							)

																	# verify the last attentions (last block, last layer)
																	SCREAMING_SNAKE_CASE    			=       (self.model_tester.image_size // 32) ** 2
																	SCREAMING_SNAKE_CASE    			=       (self.model_tester.image_size // (32 * self.model_tester.sr_ratios[-1])) ** 2
																	self.assertListEqual(
																	    list(attentions[-1].shape[-3:]      )	,							[self.model_tester.num_attention_heads[-1], expected_seq_len, expected_reduced_seq_len]	,							)
																	SCREAMING_SNAKE_CASE    			=       len(_UpperCamelCase      )

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

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

																	SCREAMING_SNAKE_CASE    			=       outputs.attentions

																	self.assertEqual(len(_UpperCamelCase      )	,							_UpperCamelCase      )
																	# verify the first attentions (first block, first layer)
																	SCREAMING_SNAKE_CASE    			=       (self.model_tester.image_size // 4) ** 2
																	SCREAMING_SNAKE_CASE    			=       (self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
																	self.assertListEqual(
																	    list(self_attentions[0].shape[-3:]      )	,							[self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]	,							)




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



												'''simple docstring'''

												def check_hidden_states_output(_UpperCamelCase   :					Dict	,							_UpperCamelCase   :					Optional[Any]	,							_UpperCamelCase   :					Union[str, Any]      ):
																	SCREAMING_SNAKE_CASE    			=       model_class(_UpperCamelCase      )
																	model.to(_UpperCamelCase      )
																	model.eval()

																	with torch.no_grad():
																						SCREAMING_SNAKE_CASE    			=       model(**self._prepare_for_class(_UpperCamelCase	,							_UpperCamelCase      )      )

																	SCREAMING_SNAKE_CASE    			=       outputs.hidden_states

																	SCREAMING_SNAKE_CASE    			=       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,
																	    ]	,							)

												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    			=       True
																	check_hidden_states_output(_UpperCamelCase	,							_UpperCamelCase	,							_UpperCamelCase      )

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

																	check_hidden_states_output(_UpperCamelCase	,							_UpperCamelCase	,							_UpperCamelCase      )




							def 	__snake_case(						self   :					int      )					->				Any:



												'''simple docstring'''

												if not self.model_tester.is_training:
																	return

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

												for model_class in self.all_model_classes:
																	if model_class in get_values(_UpperCamelCase      ):
																						continue

																	SCREAMING_SNAKE_CASE    			=       model_class(_UpperCamelCase      )
																	model.to(_UpperCamelCase      )
																	model.train()
																	SCREAMING_SNAKE_CASE    			=       self._prepare_for_class(_UpperCamelCase	,							_UpperCamelCase	,							return_labels=_UpperCamelCase      )
																	SCREAMING_SNAKE_CASE    			=       model(**_UpperCamelCase      ).loss
																	loss.backward()




							@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."      )
							def 	__snake_case(						self   :					Optional[int]      )					->				int:



												'''simple docstring'''

												pass





							@slow
							def 	__snake_case(						self   :					List[Any]      )					->				Optional[Any]:



												'''simple docstring'''

												for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	SCREAMING_SNAKE_CASE    			=       SegformerModel.from_pretrained(_UpperCamelCase      )
																	self.assertIsNotNone(_UpperCamelCase      )





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


@require_torch
class 						lowercase    (     unittest.TestCase     ):




							@slow
							def 	__snake_case(						self   :					Any      )					->				int:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       SegformerImageProcessor(
												    image_scale=(512, 512)	,							keep_ratio=_UpperCamelCase	,							align=_UpperCamelCase	,							do_random_crop=_UpperCamelCase      )
												SCREAMING_SNAKE_CASE    			=       SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512"      ).to(
												    _UpperCamelCase      )

												SCREAMING_SNAKE_CASE    			=       prepare_img()
												SCREAMING_SNAKE_CASE    			=       image_processor(images=_UpperCamelCase	,							return_tensors="pt"      )
												SCREAMING_SNAKE_CASE    			=       encoded_inputs.pixel_values.to(_UpperCamelCase      )

												with torch.no_grad():
																	SCREAMING_SNAKE_CASE    			=       model(_UpperCamelCase      )

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

												SCREAMING_SNAKE_CASE    			=       torch.tensor(
												    [
												        [[-4.6_3_1_0, -5.5_2_3_2, -6.2_3_5_6], [-5.1_9_2_1, -6.1_4_4_4, -6.5_9_9_6], [-5.4_4_2_4, -6.2_7_9_0, -6.7_5_7_4]],
												        [[-1_2.1_3_9_1, -1_3.3_1_2_2, -1_3.9_5_5_4], [-1_2.8_7_3_2, -1_3.9_3_5_2, -1_4.3_5_6_3], [-1_2.9_4_3_8, -1_3.8_2_2_6, -1_4.2_5_1_3]],
												        [[-1_2.5_1_3_4, -1_3.4_6_8_6, -1_4.4_9_1_5], [-1_2.8_6_6_9, -1_4.4_3_4_3, -1_4.7_7_5_8], [-1_3.2_5_2_3, -1_4.5_8_1_9, -1_5.0_6_9_4]],
												    ]      ).to(_UpperCamelCase      )
												self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]	,							_UpperCamelCase	,							atol=1e-4      )      )




							@slow
							def 	__snake_case(						self   :					int      )					->				Dict:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       SegformerImageProcessor(
												    image_scale=(512, 512)	,							keep_ratio=_UpperCamelCase	,							align=_UpperCamelCase	,							do_random_crop=_UpperCamelCase      )
												SCREAMING_SNAKE_CASE    			=       SegformerForSemanticSegmentation.from_pretrained(
												    "nvidia/segformer-b1-finetuned-cityscapes-1024-1024"      ).to(_UpperCamelCase      )

												SCREAMING_SNAKE_CASE    			=       prepare_img()
												SCREAMING_SNAKE_CASE    			=       image_processor(images=_UpperCamelCase	,							return_tensors="pt"      )
												SCREAMING_SNAKE_CASE    			=       encoded_inputs.pixel_values.to(_UpperCamelCase      )

												with torch.no_grad():
																	SCREAMING_SNAKE_CASE    			=       model(_UpperCamelCase      )

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

												SCREAMING_SNAKE_CASE    			=       torch.tensor(
												    [
												        [[-1_3.5_7_4_8, -1_3.9_1_1_1, -1_2.6_5_0_0], [-1_4.3_5_0_0, -1_5.3_6_8_3, -1_4.2_3_2_8], [-1_4.7_5_3_2, -1_6.0_4_2_4, -1_5.6_0_8_7]],
												        [[-1_7.1_6_5_1, -1_5.8_7_2_5, -1_2.9_6_5_3], [-1_7.2_5_8_0, -1_7.3_7_1_8, -1_4.8_2_2_3], [-1_6.6_0_5_8, -1_6.8_7_8_3, -1_6.7_4_5_2]],
												        [[-3.6_4_5_6, -3.0_2_0_9, -1.4_2_0_3], [-3.0_7_9_7, -3.1_9_5_9, -2.0_0_0_0], [-1.8_7_5_7, -1.9_2_1_7, -1.6_9_9_7]],
												    ]      ).to(_UpperCamelCase      )
												self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]	,							_UpperCamelCase	,							atol=1e-1      )      )





							@slow
							def 	__snake_case(						self   :					Optional[int]      )					->				Optional[Any]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       SegformerImageProcessor(
												    image_scale=(512, 512)	,							keep_ratio=_UpperCamelCase	,							align=_UpperCamelCase	,							do_random_crop=_UpperCamelCase      )
												SCREAMING_SNAKE_CASE    			=       SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512"      ).to(
												    _UpperCamelCase      )

												SCREAMING_SNAKE_CASE    			=       prepare_img()
												SCREAMING_SNAKE_CASE    			=       image_processor(images=_UpperCamelCase	,							return_tensors="pt"      )
												SCREAMING_SNAKE_CASE    			=       encoded_inputs.pixel_values.to(_UpperCamelCase      )

												with torch.no_grad():
																	SCREAMING_SNAKE_CASE    			=       model(_UpperCamelCase      )

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

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

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





import functools





def 	__lowerCamelCase							(UpperCAmelCase__     :							list[int]      , UpperCAmelCase__     :							list[int]  ):

					# Validation
					if not isinstance(UpperCAmelCase__      , UpperCAmelCase__  ) or not all(isinstance(UpperCAmelCase__      , UpperCAmelCase__  ) for day in days  ):
										raise ValueError("The parameter days should be a list of integers"  )

					if len(UpperCAmelCase__  ) != 3 or not all(isinstance(UpperCAmelCase__      , UpperCAmelCase__  ) for cost in costs  ):
										raise ValueError("The parameter costs should be a list of three integers"  )

					if len(UpperCAmelCase__  ) == 0:
										return 0

					if min(UpperCAmelCase__  ) <= 0:
										raise ValueError("All days elements should be greater than 0"  )

					if max(UpperCAmelCase__  ) >= 3_6_6:
										raise ValueError("All days elements should be less than 366"  )

					SCREAMING_SNAKE_CASE    			=       set(UpperCAmelCase__  )

					@functools.cache
					def dynamic_programming(UpperCAmelCase__     :							int  ) -> int:
										if index > 3_6_5:
															return 0

										if index not in days_set:
															return dynamic_programming(index + 1  )

										return min(
										    costs[0] + dynamic_programming(index + 1  )      , costs[1] + dynamic_programming(index + 7  )      , costs[2] + dynamic_programming(index + 3_0  )      , )

					return dynamic_programming(1  )


if __name__ == "__main__":
							import doctest

							doctest.testmod()




