





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 				a			(      __lowercase			):






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				int           =   self.config_class(**self.inputs_dict					)
										self.parent.assertTrue(hasattr(_lowerCAmelCase			, '''hidden_sizes'''					)					)
										self.parent.assertTrue(hasattr(_lowerCAmelCase			, '''num_attention_heads'''					)					)
										self.parent.assertTrue(hasattr(_lowerCAmelCase			, '''num_encoder_blocks'''					)					)





class 				a			:






				def __init__(  self			, _lowerCAmelCase			, _lowerCAmelCase=13			, _lowerCAmelCase=64			, _lowerCAmelCase=3			, _lowerCAmelCase=4			, _lowerCAmelCase=[2, 2, 2, 2]			, _lowerCAmelCase=[8, 4, 2, 1]			, _lowerCAmelCase=[16, 32, 64, 128]			, _lowerCAmelCase=[1, 4, 8, 16]			, _lowerCAmelCase=[1, 2, 4, 8]			, _lowerCAmelCase=True			, _lowerCAmelCase=True			, _lowerCAmelCase="gelu"			, _lowerCAmelCase=0.1			, _lowerCAmelCase=0.1			, _lowerCAmelCase=0.02			, _lowerCAmelCase=3			, _lowerCAmelCase=None			, ):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				int           =   parent
										__SCREAMING_SNAKE_CASE:				Any           =   batch_size
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   image_size
										__SCREAMING_SNAKE_CASE:				str           =   num_channels
										__SCREAMING_SNAKE_CASE:				List[Any]           =   num_encoder_blocks
										__SCREAMING_SNAKE_CASE:				Dict           =   sr_ratios
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   depths
										__SCREAMING_SNAKE_CASE:				List[Any]           =   hidden_sizes
										__SCREAMING_SNAKE_CASE:				List[str]           =   downsampling_rates
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   num_attention_heads
										__SCREAMING_SNAKE_CASE:				List[str]           =   is_training
										__SCREAMING_SNAKE_CASE:				str           =   use_labels
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   hidden_act
										__SCREAMING_SNAKE_CASE:				Tuple           =   hidden_dropout_prob
										__SCREAMING_SNAKE_CASE:				Any           =   attention_probs_dropout_prob
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   initializer_range
										__SCREAMING_SNAKE_CASE:				Tuple           =   num_labels
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   scope






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[str]           =   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

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

										__SCREAMING_SNAKE_CASE:				int           =   self.get_config()
										return config, pixel_values, labels






				def 			snake_case_    (  self					):

										"""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			, _lowerCAmelCase			, _lowerCAmelCase			, _lowerCAmelCase					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				int           =   SegformerModel(config=_lowerCAmelCase					)
										model.to(_lowerCAmelCase					)
										model.eval()
										__SCREAMING_SNAKE_CASE:				Dict           =   model(_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				List[Any]           =   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			, _lowerCAmelCase			, _lowerCAmelCase			, _lowerCAmelCase					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[str]           =   self.num_labels
										__SCREAMING_SNAKE_CASE:				List[str]           =   SegformerForSemanticSegmentation(_lowerCAmelCase					)
										model.to(_lowerCAmelCase					)
										model.eval()
										__SCREAMING_SNAKE_CASE:				int           =   model(_lowerCAmelCase					)
										self.parent.assertEqual(
										    result.logits.shape			, (self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)					)
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   model(_lowerCAmelCase			, labels=_lowerCAmelCase					)
										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			, _lowerCAmelCase			, _lowerCAmelCase			, _lowerCAmelCase					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Any           =   1
										__SCREAMING_SNAKE_CASE:				Any           =   SegformerForSemanticSegmentation(config=_lowerCAmelCase					)
										model.to(_lowerCAmelCase					)
										model.eval()
										__SCREAMING_SNAKE_CASE:				Any           =   torch.randint(0			, 1			, (self.batch_size, self.image_size, self.image_size)					).to(_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				List[Any]           =   model(_lowerCAmelCase			, labels=_lowerCAmelCase					)
										self.parent.assertGreater(result.loss			, 0.0					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				int           =   self.prepare_config_and_inputs()
										__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE:				str           =   config_and_inputs
										__SCREAMING_SNAKE_CASE:				Any           =   {'''pixel_values''': pixel_values}
										return config, inputs_dict





@require_torch
class 				a			(      __lowercase   ,__lowercase   ,unittest.TestCase			):
				SCREAMING_SNAKE_CASE__     :   Optional[int]		      =     (
				    (
				        SegformerModel,
				        SegformerForSemanticSegmentation,
				        SegformerForImageClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE__     :   Any		      =     (
				    {
				        '''feature-extraction''': SegformerModel,
				        '''image-classification''': SegformerForImageClassification,
				        '''image-segmentation''': SegformerForSemanticSegmentation,
				    }
				    if is_torch_available()
				    else {}
				)

				SCREAMING_SNAKE_CASE__     :   List[Any]		      =     True
				SCREAMING_SNAKE_CASE__     :   int		      =     False
				SCREAMING_SNAKE_CASE__     :   Optional[int]		      =     False
				SCREAMING_SNAKE_CASE__     :   List[str]		      =     False






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Optional[int]           =   SegformerModelTester(self					)
										__SCREAMING_SNAKE_CASE:				List[Any]           =   SegformerConfigTester(self			, config_class=_lowerCAmelCase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										self.config_tester.run_common_tests()






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Tuple           =   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*_lowerCAmelCase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				int           =   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_binary_image_segmentation(*_lowerCAmelCase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Any           =   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_segmentation(*_lowerCAmelCase					)






				@unittest.skip('''SegFormer does not use inputs_embeds'''					)
				def 			snake_case_    (  self					):

										"""simple docstring"""




										pass






				@unittest.skip('''SegFormer does not have get_input_embeddings method and get_output_embeddings methods'''					)
				def 			snake_case_    (  self					):

										"""simple docstring"""




										pass






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE:				Any           =   self.model_tester.prepare_config_and_inputs_for_common()

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

																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   ['''pixel_values''']
																self.assertListEqual(arg_names[:1]			, _lowerCAmelCase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




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

										for model_class in self.all_model_classes:
																__SCREAMING_SNAKE_CASE:				Dict           =   True
																__SCREAMING_SNAKE_CASE:				Dict           =   False
																__SCREAMING_SNAKE_CASE:				List[str]           =   True
																__SCREAMING_SNAKE_CASE:				Any           =   model_class(_lowerCAmelCase					)
																model.to(_lowerCAmelCase					)
																model.eval()
																with torch.no_grad():
																						__SCREAMING_SNAKE_CASE:				Optional[Any]           =   model(**self._prepare_for_class(_lowerCAmelCase			, _lowerCAmelCase					)					)
																__SCREAMING_SNAKE_CASE:				Tuple           =   outputs.attentions

																__SCREAMING_SNAKE_CASE:				Any           =   sum(self.model_tester.depths					)
																self.assertEqual(len(_lowerCAmelCase					)			, _lowerCAmelCase					)

																# check that output_attentions also work using config
																del inputs_dict["output_attentions"]
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   True
																__SCREAMING_SNAKE_CASE:				Optional[int]           =   model_class(_lowerCAmelCase					)
																model.to(_lowerCAmelCase					)
																model.eval()
																with torch.no_grad():
																						__SCREAMING_SNAKE_CASE:				Tuple           =   model(**self._prepare_for_class(_lowerCAmelCase			, _lowerCAmelCase					)					)
																__SCREAMING_SNAKE_CASE:				List[Any]           =   outputs.attentions

																self.assertEqual(len(_lowerCAmelCase					)			, _lowerCAmelCase					)

																# verify the first attentions (first block, first layer)
																__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   (self.model_tester.image_size // 4) ** 2
																__SCREAMING_SNAKE_CASE:				str           =   (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:				List[str]           =   (self.model_tester.image_size // 32) ** 2
																__SCREAMING_SNAKE_CASE:				Dict           =   (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:				Union[str, Any]           =   len(_lowerCAmelCase					)

																# Check attention is always last and order is fine
																__SCREAMING_SNAKE_CASE:				Any           =   True
																__SCREAMING_SNAKE_CASE:				int           =   True
																__SCREAMING_SNAKE_CASE:				List[Any]           =   model_class(_lowerCAmelCase					)
																model.to(_lowerCAmelCase					)
																model.eval()
																with torch.no_grad():
																						__SCREAMING_SNAKE_CASE:				Any           =   model(**self._prepare_for_class(_lowerCAmelCase			, _lowerCAmelCase					)					)

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

																__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   outputs.attentions

																self.assertEqual(len(_lowerCAmelCase					)			, _lowerCAmelCase					)
																# verify the first attentions (first block, first layer)
																__SCREAMING_SNAKE_CASE:				Dict           =   (self.model_tester.image_size // 4) ** 2
																__SCREAMING_SNAKE_CASE:				str           =   (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					):

										"""simple docstring"""




										def check_hidden_states_output(_lowerCAmelCase			, _lowerCAmelCase			, _lowerCAmelCase					):
																__SCREAMING_SNAKE_CASE:				Optional[int]           =   model_class(_lowerCAmelCase					)
																model.to(_lowerCAmelCase					)
																model.eval()

																with torch.no_grad():
																						__SCREAMING_SNAKE_CASE:				Tuple           =   model(**self._prepare_for_class(_lowerCAmelCase			, _lowerCAmelCase					)					)

																__SCREAMING_SNAKE_CASE:				Tuple           =   outputs.hidden_states

																__SCREAMING_SNAKE_CASE:				Tuple           =   self.model_tester.num_encoder_blocks
																self.assertEqual(len(_lowerCAmelCase					)			, _lowerCAmelCase					)

																# 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:				List[str]           =   self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																__SCREAMING_SNAKE_CASE:				str           =   True
																check_hidden_states_output(_lowerCAmelCase			, _lowerCAmelCase			, _lowerCAmelCase					)

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

																check_hidden_states_output(_lowerCAmelCase			, _lowerCAmelCase			, _lowerCAmelCase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										if not self.model_tester.is_training:
																return

										__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE:				str           =   self.model_tester.prepare_config_and_inputs_for_common()
										__SCREAMING_SNAKE_CASE:				int           =   True

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

																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   model_class(_lowerCAmelCase					)
																model.to(_lowerCAmelCase					)
																model.train()
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   self._prepare_for_class(_lowerCAmelCase			, _lowerCAmelCase			, return_labels=_lowerCAmelCase					)
																__SCREAMING_SNAKE_CASE:				List[Any]           =   model(**_lowerCAmelCase					).loss
																loss.backward()






				@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''					)
				def 			snake_case_    (  self					):

										"""simple docstring"""




										pass






				@slow
				def 			snake_case_    (  self					):

										"""simple docstring"""




										for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																__SCREAMING_SNAKE_CASE:				List[str]           =   SegformerModel.from_pretrained(_lowerCAmelCase					)
																self.assertIsNotNone(_lowerCAmelCase					)






def 		lowerCAmelCase  (	)      ->    Dict:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''					)
						return image





@require_torch
class 				a			(      unittest.TestCase			):






				@slow
				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   SegformerImageProcessor(
										    image_scale=(512, 512)			, keep_ratio=_lowerCAmelCase			, align=_lowerCAmelCase			, do_random_crop=_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Dict           =   SegformerForSemanticSegmentation.from_pretrained('''nvidia/segformer-b0-finetuned-ade-512-512'''					).to(
										    _lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   prepare_img()
										__SCREAMING_SNAKE_CASE:				Tuple           =   image_processor(images=_lowerCAmelCase			, return_tensors='''pt'''					)
										__SCREAMING_SNAKE_CASE:				List[Any]           =   encoded_inputs.pixel_values.to(_lowerCAmelCase					)

										with torch.no_grad():
																__SCREAMING_SNAKE_CASE:				List[Any]           =   model(_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				int           =   torch.Size((1, model.config.num_labels, 128, 128)					)
										self.assertEqual(outputs.logits.shape			, _lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   torch.tensor(
										    [
										        [[-4.6310, -5.5232, -6.2356], [-5.1921, -6.1444, -6.5996], [-5.4424, -6.2790, -6.7574]],
										        [[-12.1391, -13.3122, -13.9554], [-12.8732, -13.9352, -14.3563], [-12.9438, -13.8226, -14.2513]],
										        [[-12.5134, -13.4686, -14.4915], [-12.8669, -14.4343, -14.7758], [-13.2523, -14.5819, -15.0694]],
										    ]					).to(_lowerCAmelCase					)
										self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]			, _lowerCAmelCase			, atol=1e-4					)					)






				@slow
				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[str]           =   SegformerImageProcessor(
										    image_scale=(512, 512)			, keep_ratio=_lowerCAmelCase			, align=_lowerCAmelCase			, do_random_crop=_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				List[Any]           =   SegformerForSemanticSegmentation.from_pretrained(
										    '''nvidia/segformer-b1-finetuned-cityscapes-1024-1024'''					).to(_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Tuple           =   prepare_img()
										__SCREAMING_SNAKE_CASE:				str           =   image_processor(images=_lowerCAmelCase			, return_tensors='''pt'''					)
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   encoded_inputs.pixel_values.to(_lowerCAmelCase					)

										with torch.no_grad():
																__SCREAMING_SNAKE_CASE:				Dict           =   model(_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				int           =   torch.Size((1, model.config.num_labels, 128, 128)					)
										self.assertEqual(outputs.logits.shape			, _lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				List[str]           =   torch.tensor(
										    [
										        [[-13.5748, -13.9111, -12.6500], [-14.3500, -15.3683, -14.2328], [-14.7532, -16.0424, -15.6087]],
										        [[-17.1651, -15.8725, -12.9653], [-17.2580, -17.3718, -14.8223], [-16.6058, -16.8783, -16.7452]],
										        [[-3.6456, -3.0209, -1.4203], [-3.0797, -3.1959, -2.0000], [-1.8757, -1.9217, -1.6997]],
										    ]					).to(_lowerCAmelCase					)
										self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]			, _lowerCAmelCase			, atol=1e-1					)					)






				@slow
				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[Any]           =   SegformerImageProcessor(
										    image_scale=(512, 512)			, keep_ratio=_lowerCAmelCase			, align=_lowerCAmelCase			, do_random_crop=_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Tuple           =   SegformerForSemanticSegmentation.from_pretrained('''nvidia/segformer-b0-finetuned-ade-512-512'''					).to(
										    _lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				str           =   prepare_img()
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   image_processor(images=_lowerCAmelCase			, return_tensors='''pt'''					)
										__SCREAMING_SNAKE_CASE:				Any           =   encoded_inputs.pixel_values.to(_lowerCAmelCase					)

										with torch.no_grad():
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   model(_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   outputs.logits.detach().cpu()

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

										__SCREAMING_SNAKE_CASE:				Optional[int]           =   image_processor.post_process_semantic_segmentation(outputs=_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				int           =   torch.Size((128, 128)					)
										self.assertEqual(segmentation[0].shape			, _lowerCAmelCase					)










from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCAmelCase							:       Optional[int]					 =	logging.get_logger(__name__)

lowerCAmelCase							:       Tuple					 =	{
    """facebook/data2vec-vision-base-ft""": (
        """https://huggingface.co/facebook/data2vec-vision-base-ft/resolve/main/config.json"""
    ),
}





class 				a			(      __lowercase			):
				SCREAMING_SNAKE_CASE__     :   Union[str, Any]		      =     '''data2vec-vision'''






				def __init__(  self			, _lowerCAmelCase=768			, _lowerCAmelCase=12			, _lowerCAmelCase=12			, _lowerCAmelCase=3072			, _lowerCAmelCase="gelu"			, _lowerCAmelCase=0.0			, _lowerCAmelCase=0.0			, _lowerCAmelCase=0.02			, _lowerCAmelCase=1e-12			, _lowerCAmelCase=224			, _lowerCAmelCase=16			, _lowerCAmelCase=3			, _lowerCAmelCase=False			, _lowerCAmelCase=False			, _lowerCAmelCase=False			, _lowerCAmelCase=False			, _lowerCAmelCase=0.1			, _lowerCAmelCase=0.1			, _lowerCAmelCase=True			, _lowerCAmelCase=[3, 5, 7, 11]			, _lowerCAmelCase=[1, 2, 3, 6]			, _lowerCAmelCase=True			, _lowerCAmelCase=0.4			, _lowerCAmelCase=256			, _lowerCAmelCase=1			, _lowerCAmelCase=False			, _lowerCAmelCase=255			, **_lowerCAmelCase			, ):

										"""simple docstring"""




										super().__init__(**_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				str           =   hidden_size
										__SCREAMING_SNAKE_CASE:				Tuple           =   num_hidden_layers
										__SCREAMING_SNAKE_CASE:				Tuple           =   num_attention_heads
										__SCREAMING_SNAKE_CASE:				int           =   intermediate_size
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   hidden_act
										__SCREAMING_SNAKE_CASE:				int           =   hidden_dropout_prob
										__SCREAMING_SNAKE_CASE:				str           =   attention_probs_dropout_prob
										__SCREAMING_SNAKE_CASE:				Any           =   initializer_range
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   layer_norm_eps

										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   image_size
										__SCREAMING_SNAKE_CASE:				List[str]           =   patch_size
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   num_channels
										__SCREAMING_SNAKE_CASE:				List[Any]           =   use_mask_token
										__SCREAMING_SNAKE_CASE:				Tuple           =   use_absolute_position_embeddings
										__SCREAMING_SNAKE_CASE:				Any           =   use_relative_position_bias
										__SCREAMING_SNAKE_CASE:				Dict           =   use_shared_relative_position_bias
										__SCREAMING_SNAKE_CASE:				Any           =   layer_scale_init_value
										__SCREAMING_SNAKE_CASE:				List[Any]           =   drop_path_rate
										__SCREAMING_SNAKE_CASE:				int           =   use_mean_pooling
										# decode head attributes (semantic segmentation)
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   out_indices
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   pool_scales
										# auxiliary head attributes (semantic segmentation)
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   use_auxiliary_head
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   auxiliary_loss_weight
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   auxiliary_channels
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   auxiliary_num_convs
										__SCREAMING_SNAKE_CASE:				Any           =   auxiliary_concat_input
										__SCREAMING_SNAKE_CASE:				List[str]           =   semantic_loss_ignore_index





class 				a			(      __lowercase			):
				SCREAMING_SNAKE_CASE__     :   List[Any]		      =     version.parse('''1.11'''			)






				@property
				def 			snake_case_    (  self					):

										"""simple docstring"""




										return OrderedDict(
										    [
										        ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
										    ]					)






				@property
				def 			snake_case_    (  self					):

										"""simple docstring"""




										return 1e-4



