



"""simple docstring"""






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
from ..auto import CONFIG_MAPPING


lowerCAmelCase__              =							logging.get_logger(__name__)

lowerCAmelCase__              =							{
    '''microsoft/table-transformer-detection''': (
        '''https://huggingface.co/microsoft/table-transformer-detection/resolve/main/config.json'''
    ),
}






class 			__snake_case			(      _lowercase):
  snake_case__							:  List[Any]         =		"table-transformer"
  snake_case__							:  Dict         =		["past_key_values"]
  snake_case__							:  Tuple         =		{
      "hidden_size": "d_model",
      "num_attention_heads": "encoder_attention_heads",
  }




  def __init__(					self	:		List[Any]		,   __lowerCAmelCase	:		Optional[int]=True		,   __lowerCAmelCase	:		List[Any]=None		,   __lowerCAmelCase	:		List[Any]=3		,   __lowerCAmelCase	:		Any=1_0_0		,   __lowerCAmelCase	:		Optional[Any]=6		,   __lowerCAmelCase	:		Optional[Any]=2_0_4_8		,   __lowerCAmelCase	:		Any=8		,   __lowerCAmelCase	:		List[str]=6		,   __lowerCAmelCase	:		int=2_0_4_8		,   __lowerCAmelCase	:		Optional[int]=8		,   __lowerCAmelCase	:		Any=0.0		,   __lowerCAmelCase	:		str=0.0		,   __lowerCAmelCase	:		List[Any]=True		,   __lowerCAmelCase	:		List[str]="relu"		,   __lowerCAmelCase	:		List[str]=2_5_6		,   __lowerCAmelCase	:		int=0.1		,   __lowerCAmelCase	:		Tuple=0.0		,   __lowerCAmelCase	:		Optional[int]=0.0		,   __lowerCAmelCase	:		Optional[int]=0.02		,   __lowerCAmelCase	:		List[Any]=1.0		,   __lowerCAmelCase	:		Tuple=False		,   __lowerCAmelCase	:		List[str]="sine"		,   __lowerCAmelCase	:		Any="resnet50"		,   __lowerCAmelCase	:		Optional[Any]=True		,   __lowerCAmelCase	:		Union[str, Any]=False		,   __lowerCAmelCase	:		Any=1		,   __lowerCAmelCase	:		Any=5		,   __lowerCAmelCase	:		Optional[int]=2		,   __lowerCAmelCase	:		List[Any]=1		,   __lowerCAmelCase	:		Tuple=1		,   __lowerCAmelCase	:		List[Any]=5		,   __lowerCAmelCase	:		int=2		,   __lowerCAmelCase	:		Dict=0.1		,   **__lowerCAmelCase	:		Tuple		,   ):






         """simple docstring"""






         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		:							Tuple            =					CONFIG_MAPPING['''resnet'''](out_features=['''stage4''']						)
                elif isinstance(__lowerCAmelCase		,   __lowerCAmelCase						):
                       _lowerCamelCase		:							Optional[int]            =					backbone_config.get('''model_type'''						)
                       _lowerCamelCase		:							Dict            =					CONFIG_MAPPING[backbone_model_type]
                       _lowerCamelCase		:							Tuple            =					config_class.from_dict(__lowerCAmelCase						)
                # set timm attributes to None
                _lowerCamelCase     ,       _lowerCamelCase     ,       _lowerCamelCase		:							Dict            =					None, None, None

         _lowerCamelCase		:							Dict            =					use_timm_backbone
         _lowerCamelCase		:							List[str]            =					backbone_config
         _lowerCamelCase		:							Optional[int]            =					num_channels
         _lowerCamelCase		:							Optional[int]            =					num_queries
         _lowerCamelCase		:							Union[str, Any]            =					d_model
         _lowerCamelCase		:							str            =					encoder_ffn_dim
         _lowerCamelCase		:							Dict            =					encoder_layers
         _lowerCamelCase		:							List[Any]            =					encoder_attention_heads
         _lowerCamelCase		:							List[Any]            =					decoder_ffn_dim
         _lowerCamelCase		:							Any            =					decoder_layers
         _lowerCamelCase		:							List[str]            =					decoder_attention_heads
         _lowerCamelCase		:							Optional[Any]            =					dropout
         _lowerCamelCase		:							Tuple            =					attention_dropout
         _lowerCamelCase		:							Tuple            =					activation_dropout
         _lowerCamelCase		:							int            =					activation_function
         _lowerCamelCase		:							Dict            =					init_std
         _lowerCamelCase		:							List[Any]            =					init_xavier_std
         _lowerCamelCase		:							Any            =					encoder_layerdrop
         _lowerCamelCase		:							List[str]            =					decoder_layerdrop
         _lowerCamelCase		:							str            =					encoder_layers
         _lowerCamelCase		:							List[str]            =					auxiliary_loss
         _lowerCamelCase		:							Optional[Any]            =					position_embedding_type
         _lowerCamelCase		:							List[str]            =					backbone
         _lowerCamelCase		:							Union[str, Any]            =					use_pretrained_backbone
         _lowerCamelCase		:							Any            =					dilation
         # Hungarian matcher
         _lowerCamelCase		:							Optional[Any]            =					class_cost
         _lowerCamelCase		:							Tuple            =					bbox_cost
         _lowerCamelCase		:							Union[str, Any]            =					giou_cost
         # Loss coefficients
         _lowerCamelCase		:							List[str]            =					mask_loss_coefficient
         _lowerCamelCase		:							List[str]            =					dice_loss_coefficient
         _lowerCamelCase		:							List[str]            =					bbox_loss_coefficient
         _lowerCamelCase		:							Tuple            =					giou_loss_coefficient
         _lowerCamelCase		:							Optional[int]            =					eos_coefficient
         super().__init__(is_encoder_decoder=__lowerCAmelCase		,   **__lowerCAmelCase						)




  @property
  def 		SCREAMING_SNAKE_CASE							(					self	:		Tuple						):






         """simple docstring"""






         return self.encoder_attention_heads




  @property
  def 		SCREAMING_SNAKE_CASE							(					self	:		Tuple						):






         """simple docstring"""






         return self.d_model






class 			__snake_case			(      _lowercase):
  snake_case__							:  Optional[int]         =		version.parse("1.11")




  @property
  def 		SCREAMING_SNAKE_CASE							(					self	:		str						):






         """simple docstring"""






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




  @property
  def 		SCREAMING_SNAKE_CASE							(					self	:		Optional[int]						):






         """simple docstring"""






         return 1E-5




  @property
  def 		SCREAMING_SNAKE_CASE							(					self	:		Tuple						):






         """simple docstring"""






         return 1_2









'''simple docstring'''






import math

import tensorflow as tf
from packaging import version






def   __A    (				a_    :	List[Any]						):
		lowerCAmelCase  :     Any       						= tf.convert_to_tensor(a_						)
		lowerCAmelCase  :     List[Any]       						= 0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0						)   ,x.dtype						)						))

		return x * cdf






def   __A    (				a_    :	int						):
		lowerCAmelCase  :     Dict       						= tf.convert_to_tensor(a_						)
		lowerCAmelCase  :     int       						= tf.cast(math.pi   ,x.dtype						)
		lowerCAmelCase  :     Dict       						= tf.cast(0.0_4_4_7_1_5   ,x.dtype						)
		lowerCAmelCase  :     Dict       						= 0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi						) * (x + coeff * tf.pow(a_   ,3						))						))

		return x * cdf






def   __A    (				a_    :	Union[str, Any]						):
		lowerCAmelCase  :     Any       						= tf.convert_to_tensor(a_						)

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






def   __A    (				a_    :	List[str]						):
		lowerCAmelCase  :     Dict       						= tf.convert_to_tensor(a_						)
		lowerCAmelCase  :     Any       						= tf.cast(0.0_4_4_7_1_5   ,x.dtype						)
		lowerCAmelCase  :     Optional[int]       						= tf.cast(0.7_9_7_8_8_4_5_6_0_8   ,x.dtype						)

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






def   __A    (				a_    :	Union[str, Any]						):
		lowerCAmelCase  :     Optional[int]       						= tf.convert_to_tensor(a_						)
		lowerCAmelCase  :     List[Any]       						= tf.cast(1.7_0_2   ,x.dtype						)
		return x * tf.math.sigmoid(coeff * x						)






def   __A    (				a_    :	List[Any]						):
		return tf.clip_by_value(_gelu(a_						)   ,-1_0   ,1_0						)






def   __A    (				a_    :	List[Any]   ,a_    :	List[Any]=-1						):
		lowerCAmelCase						,		lowerCAmelCase  :     Optional[int]       						= tf.split(a_   ,2   ,axis=a_						)
		return a * tf.math.sigmoid(a_						)


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






					def   __A    (				a_    :	Optional[Any]						):
							return tf.keras.activations.gelu(a_   ,approximate=a_						)

					lowerCAmelCase									=   tf.keras.activations.gelu

					lowerCAmelCase									=   approximate_gelu_wrap
else:
					lowerCAmelCase									=   _gelu
					lowerCAmelCase									=   _gelu_new


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



