






'''simple docstring'''







import math

import tensorflow as tf
from packaging import version





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	Dict:
							lowerCamelCase__ :     Union[str, Any]	  =	tf.convert_to_tensor(UpperCamelCase				)
							lowerCamelCase__ :     List[str]	  =	0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0				)    ,      x.dtype				)				))

							return x * cdf





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	int:
							lowerCamelCase__ :     Tuple	  =	tf.convert_to_tensor(UpperCamelCase				)
							lowerCamelCase__ :     int	  =	tf.cast(math.pi    ,      x.dtype				)
							lowerCamelCase__ :     Optional[Any]	  =	tf.cast(0.04_4715    ,      x.dtype				)
							lowerCamelCase__ :     str	  =	0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi				) * (x + coeff * tf.pow(UpperCamelCase    ,      3				))				))

							return x * cdf





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	Union[str, Any]:
							lowerCamelCase__ :     str	  =	tf.convert_to_tensor(UpperCamelCase				)

							return x * tf.tanh(tf.math.softplus(UpperCamelCase				)				)





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	Optional[int]:
							lowerCamelCase__ :     Optional[int]	  =	tf.convert_to_tensor(UpperCamelCase				)
							lowerCamelCase__ :     Union[str, Any]	  =	tf.cast(0.04_4715    ,      x.dtype				)
							lowerCamelCase__ :     Dict	  =	tf.cast(0.79_7884_5608    ,      x.dtype				)

							return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)				))





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	Tuple:
							lowerCamelCase__ :     Optional[Any]	  =	tf.convert_to_tensor(UpperCamelCase				)
							lowerCamelCase__ :     Any	  =	tf.cast(1.702    ,      x.dtype				)
							return x * tf.math.sigmoid(coeff * x				)





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	Any:
							return tf.clip_by_value(_gelu(UpperCamelCase				)    ,      -10    ,      10				)





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase=-1				)				->	Optional[int]:
							lowerCamelCase__ :     Union[str, Any]	  =	tf.split(UpperCamelCase    ,      2    ,      axis=UpperCamelCase				)
							return a * tf.math.sigmoid(UpperCamelCase				)


if version.parse(tf.version.VERSION) >= version.parse('''2.4'''):





			def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	str:
										return tf.keras.activations.gelu(UpperCamelCase    ,      approximate=UpperCamelCase				)

			_A     :      Any   					=tf.keras.activations.gelu



			_A     :      str   					=approximate_gelu_wrap
else:
			_A     :      List[str]   					=_gelu
			_A     :      Union[str, Any]   					=_gelu_new


_A     :      int   					={
    '''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 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	Dict:
							if activation_string in ACTaFN:
														return ACTaFN[activation_string]
							else:
														raise KeyError(f'''function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()				)}'''				)











'''simple docstring'''







import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


_A     :      Union[str, Any]   					=logging.get_logger(__name__)

_A     :      List[Any]   					={
    '''SenseTime/deformable-detr''': '''https://huggingface.co/sensetime/deformable-detr/resolve/main/config.json''',
    # See all Deformable DETR models at https://huggingface.co/models?filter=deformable-detr
}

class _lowercase     (    _lowercase		):
							a    				=	"""deformable_detr"""
							a    				=	{
							    """hidden_size""": """d_model""",
							    """num_attention_heads""": """encoder_attention_heads""",
							}




							def __init__(							self:    Optional[int]      ,							UpperCamelCase__:    Tuple=True      ,							UpperCamelCase__:    Tuple=None      ,							UpperCamelCase__:    List[str]=3      ,							UpperCamelCase__:    Any=300      ,							UpperCamelCase__:    Optional[int]=1_024      ,							UpperCamelCase__:    int=6      ,							UpperCamelCase__:    str=1_024      ,							UpperCamelCase__:    Optional[Any]=8      ,							UpperCamelCase__:    Optional[Any]=6      ,							UpperCamelCase__:    Union[str, Any]=1_024      ,							UpperCamelCase__:    Tuple=8      ,							UpperCamelCase__:    str=0.0      ,							UpperCamelCase__:    Tuple=True      ,							UpperCamelCase__:    Any="relu"      ,							UpperCamelCase__:    Any=256      ,							UpperCamelCase__:    List[Any]=0.1      ,							UpperCamelCase__:    Optional[int]=0.0      ,							UpperCamelCase__:    Any=0.0      ,							UpperCamelCase__:    List[str]=0.02      ,							UpperCamelCase__:    str=1.0      ,							UpperCamelCase__:    Any=True      ,							UpperCamelCase__:    List[Any]=False      ,							UpperCamelCase__:    str="sine"      ,							UpperCamelCase__:    Optional[Any]="resnet50"      ,							UpperCamelCase__:    Optional[int]=True      ,							UpperCamelCase__:    Optional[int]=False      ,							UpperCamelCase__:    List[Any]=4      ,							UpperCamelCase__:    Any=4      ,							UpperCamelCase__:    int=4      ,							UpperCamelCase__:    int=False      ,							UpperCamelCase__:    Optional[Any]=300      ,							UpperCamelCase__:    str=False      ,							UpperCamelCase__:    int=1      ,							UpperCamelCase__:    Tuple=5      ,							UpperCamelCase__:    List[Any]=2      ,							UpperCamelCase__:    Optional[int]=1      ,							UpperCamelCase__:    int=1      ,							UpperCamelCase__:    Tuple=5      ,							UpperCamelCase__:    str=2      ,							UpperCamelCase__:    str=0.1      ,							UpperCamelCase__:    List[str]=0.25      ,							UpperCamelCase__:    Any=False      ,							**UpperCamelCase__:    Optional[Any]      ,							):
														if backbone_config is not None and use_timm_backbone:
																					raise ValueError("""You can't specify both `backbone_config` and `use_timm_backbone`."""					)

														if not use_timm_backbone:
																					if backbone_config is None:
																												logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""					)
																												lowerCamelCase__ :     Union[str, Any]	  =	CONFIG_MAPPING["""resnet"""](out_features=["""stage4"""]					)
																					elif isinstance(UpperCamelCase__      ,							UpperCamelCase__					):
																												lowerCamelCase__ :     Tuple	  =	backbone_config.get("""model_type"""					)
																												lowerCamelCase__ :     Dict	  =	CONFIG_MAPPING[backbone_model_type]
																												lowerCamelCase__ :     Optional[Any]	  =	config_class.from_dict(UpperCamelCase__					)
														lowerCamelCase__ :     Tuple	  =	use_timm_backbone
														lowerCamelCase__ :     Tuple	  =	backbone_config
														lowerCamelCase__ :     Union[str, Any]	  =	num_channels
														lowerCamelCase__ :     str	  =	num_queries
														lowerCamelCase__ :     int	  =	max_position_embeddings
														lowerCamelCase__ :     str	  =	d_model
														lowerCamelCase__ :     Dict	  =	encoder_ffn_dim
														lowerCamelCase__ :     Union[str, Any]	  =	encoder_layers
														lowerCamelCase__ :     int	  =	encoder_attention_heads
														lowerCamelCase__ :     str	  =	decoder_ffn_dim
														lowerCamelCase__ :     Optional[Any]	  =	decoder_layers
														lowerCamelCase__ :     Optional[int]	  =	decoder_attention_heads
														lowerCamelCase__ :     int	  =	dropout
														lowerCamelCase__ :     Optional[Any]	  =	attention_dropout
														lowerCamelCase__ :     List[Any]	  =	activation_dropout
														lowerCamelCase__ :     List[Any]	  =	activation_function
														lowerCamelCase__ :     int	  =	init_std
														lowerCamelCase__ :     Dict	  =	init_xavier_std
														lowerCamelCase__ :     Tuple	  =	encoder_layerdrop
														lowerCamelCase__ :     str	  =	auxiliary_loss
														lowerCamelCase__ :     int	  =	position_embedding_type
														lowerCamelCase__ :     Tuple	  =	backbone
														lowerCamelCase__ :     Tuple	  =	use_pretrained_backbone
														lowerCamelCase__ :     Optional[int]	  =	dilation
														# deformable attributes
														lowerCamelCase__ :     Optional[int]	  =	num_feature_levels
														lowerCamelCase__ :     Tuple	  =	encoder_n_points
														lowerCamelCase__ :     Tuple	  =	decoder_n_points
														lowerCamelCase__ :     Dict	  =	two_stage
														lowerCamelCase__ :     int	  =	two_stage_num_proposals
														lowerCamelCase__ :     Any	  =	with_box_refine
														if two_stage is True and with_box_refine is False:
																					raise ValueError("""If two_stage is True, with_box_refine must be True."""					)
														# Hungarian matcher
														lowerCamelCase__ :     Optional[int]	  =	class_cost
														lowerCamelCase__ :     List[str]	  =	bbox_cost
														lowerCamelCase__ :     Any	  =	giou_cost
														# Loss coefficients
														lowerCamelCase__ :     Union[str, Any]	  =	mask_loss_coefficient
														lowerCamelCase__ :     Tuple	  =	dice_loss_coefficient
														lowerCamelCase__ :     int	  =	bbox_loss_coefficient
														lowerCamelCase__ :     Optional[Any]	  =	giou_loss_coefficient
														lowerCamelCase__ :     Dict	  =	eos_coefficient
														lowerCamelCase__ :     Any	  =	focal_alpha
														lowerCamelCase__ :     Optional[Any]	  =	disable_custom_kernels
														super().__init__(is_encoder_decoder=UpperCamelCase__      ,							**UpperCamelCase__					)




							@property
							def 		lowerCamelCase_    (							self:    Dict					):
														return self.encoder_attention_heads




							@property
							def 		lowerCamelCase_    (							self:    Any					):
														return self.d_model




							def 		lowerCamelCase_    (							self:    List[str]					):
														lowerCamelCase__ :     Optional[int]	  =	copy.deepcopy(self.__dict__					)
														if self.backbone_config is not None:
																					lowerCamelCase__ :     int	  =	self.backbone_config.to_dict()
														lowerCamelCase__ :     int	  =	self.__class__.model_type
														return output

