



import warnings
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       :					Tuple      					=					logging.get_logger(__name__)

__lowerCAmelCase       :					int      					=					{
    '''nvidia/segformer-b0-finetuned-ade-512-512''': (
        '''https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json'''
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}



class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase			  =       '''segformer'''





		def __init__(					self							,    _lowercase=3							,    _lowercase=4							,    _lowercase=[2, 2, 2, 2]							,    _lowercase=[8, 4, 2, 1]							,    _lowercase=[3_2, 6_4, 1_6_0, 2_5_6]							,    _lowercase=[7, 3, 3, 3]							,    _lowercase=[4, 2, 2, 2]							,    _lowercase=[1, 2, 5, 8]							,    _lowercase=[4, 4, 4, 4]							,    _lowercase="gelu"							,    _lowercase=0.0							,    _lowercase=0.0							,    _lowercase=0.1							,    _lowercase=0.02							,    _lowercase=0.1							,    _lowercase=1E-6							,    _lowercase=2_5_6							,    _lowercase=2_5_5							,    **_lowercase							,    ) ->						Optional[Any]:







								'''simple docstring'''

								super().__init__(**_lowercase   )

								if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
														warnings.warn(
														    """Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be"""
														    """ removed, as the behaviour will default to that of reshape_last_stage = True."""							,    _lowercase							,    )

								snake_case_   : Union[str, Any]						=			num_channels
								snake_case_   : Optional[int]						=			num_encoder_blocks
								snake_case_   : Union[str, Any]						=			depths
								snake_case_   : Optional[int]						=			sr_ratios
								snake_case_   : Dict						=			hidden_sizes
								snake_case_   : str						=			patch_sizes
								snake_case_   : Optional[int]						=			strides
								snake_case_   : Union[str, Any]						=			mlp_ratios
								snake_case_   : Optional[Any]						=			num_attention_heads
								snake_case_   : Optional[Any]						=			hidden_act
								snake_case_   : Dict						=			hidden_dropout_prob
								snake_case_   : Any						=			attention_probs_dropout_prob
								snake_case_   : Union[str, Any]						=			classifier_dropout_prob
								snake_case_   : str						=			initializer_range
								snake_case_   : Optional[int]						=			drop_path_rate
								snake_case_   : Tuple						=			layer_norm_eps
								snake_case_   : List[str]						=			decoder_hidden_size
								snake_case_   : Optional[Any]						=			kwargs.get("""reshape_last_stage"""							,    _lowercase   )
								snake_case_   : List[str]						=			semantic_loss_ignore_index




class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase			  =       version.parse('''1.11'''		)





		@property
		def    UpperCAmelCase__							(					self   ) ->						Mapping[str, Mapping[int, str]]:







								'''simple docstring'''

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





		@property
		def    UpperCAmelCase__							(					self   ) ->						float:







								'''simple docstring'''

								return 1E-4





		@property
		def    UpperCAmelCase__							(					self   ) ->						int:







								'''simple docstring'''

								return 1_2






"""simple docstring"""





import math

import tensorflow as tf
from packaging import version
def 	__lowerCAmelCase						(		__UpperCamelCase      :			List[Any]    ):


						'''simple docstring'''






						snake_case_   : int						=			tf.convert_to_tensor(__UpperCamelCase    )
						snake_case_   : int						=			0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0    )					, x.dtype    )    ))

						return x * cdf
def 	__lowerCAmelCase						(		__UpperCamelCase      :			List[str]    ):


						'''simple docstring'''






						snake_case_   : int						=			tf.convert_to_tensor(__UpperCamelCase    )
						snake_case_   : List[Any]						=			tf.cast(math.pi					, x.dtype    )
						snake_case_   : int						=			tf.cast(0.044_715					, x.dtype    )
						snake_case_   : Optional[int]						=			0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi    ) * (x + coeff * tf.pow(__UpperCamelCase					, 3    ))    ))

						return x * cdf
def 	__lowerCAmelCase						(		__UpperCamelCase      :			str    ):


						'''simple docstring'''






						snake_case_   : Optional[Any]						=			tf.convert_to_tensor(__UpperCamelCase    )

						return x * tf.tanh(tf.math.softplus(__UpperCamelCase    )    )
def 	__lowerCAmelCase						(		__UpperCamelCase      :			Any    ):


						'''simple docstring'''






						snake_case_   : str						=			tf.convert_to_tensor(__UpperCamelCase    )
						snake_case_   : int						=			tf.cast(0.044_715					, x.dtype    )
						snake_case_   : Optional[int]						=			tf.cast(0.7_978_845_608					, x.dtype    )

						return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)    ))
def 	__lowerCAmelCase						(		__UpperCamelCase      :			List[str]    ):


						'''simple docstring'''






						snake_case_   : Tuple						=			tf.convert_to_tensor(__UpperCamelCase    )
						snake_case_   : str						=			tf.cast(1.702					, x.dtype    )
						return x * tf.math.sigmoid(coeff * x    )
def 	__lowerCAmelCase						(		__UpperCamelCase      :			int    ):


						'''simple docstring'''






						return tf.clip_by_value(_gelu(__UpperCamelCase    )					, -1_0					, 1_0    )
def 	__lowerCAmelCase						(		__UpperCamelCase      :			Optional[int]					, __UpperCamelCase      :			List[str]=-1    ):


						'''simple docstring'''






						snake_case_			,		snake_case_   : List[Any]						=			tf.split(__UpperCamelCase					, 2					, axis=__UpperCamelCase    )
						return a * tf.math.sigmoid(__UpperCamelCase    )


if version.parse(tf.version.VERSION) >= version.parse('''2.4'''):
					def 	__lowerCAmelCase						(		__UpperCamelCase      :			List[Any]    ):


											'''simple docstring'''






											return tf.keras.activations.gelu(__UpperCamelCase					, approximate=__UpperCamelCase    )

					__lowerCAmelCase       :					int      					=					tf.keras.activations.gelu






					__lowerCAmelCase       :					Optional[Any]      					=					approximate_gelu_wrap
else:
					__lowerCAmelCase       :					List[Any]      					=					_gelu
					__lowerCAmelCase       :					Any      					=					_gelu_new


__lowerCAmelCase       :					Dict      					=					{
    '''gelu''': gelu,
    '''gelu_10''': gelu_aa,
    '''gelu_fast''': gelu_fast,
    '''gelu_new''': gelu_new,
    '''glu''': glu,
    '''mish''': mish,
    '''quick_gelu''': quick_gelu,
    '''relu''': tf.keras.activations.relu,
    '''sigmoid''': tf.keras.activations.sigmoid,
    '''silu''': tf.keras.activations.swish,
    '''swish''': tf.keras.activations.swish,
    '''tanh''': tf.keras.activations.tanh,
}






def 	__lowerCAmelCase						(		__UpperCamelCase      :			Any    ):


						'''simple docstring'''






						if activation_string in ACTaFN:
												return ACTaFN[activation_string]
						else:
												raise KeyError(F'function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()    )}'    )

