
    bCiv7                     l    S r SSKJr  SSKJr  SSKJr  \R                  " \5      r	 " S S\5      r
S/rg)	zDETA model configuration   )PretrainedConfig)logging   )CONFIG_MAPPINGc                      ^  \ rS rSrSrSrSSS.r                                           SU 4S jjr\S\	4S	 j5       r
\S\	4S
 j5       r\S 5       rSrU =r$ )
DetaConfig   a  
This is the configuration class to store the configuration of a [`DetaModel`]. It is used to instantiate a DETA
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the DETA
[SenseTime/deformable-detr](https://huggingface.co/SenseTime/deformable-detr) architecture.

Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
documentation from [`PretrainedConfig`] for more information.

Args:
    backbone_config (`PretrainedConfig` or `dict`, *optional*, defaults to `ResNetConfig()`):
        The configuration of the backbone model.
    backbone (`str`, *optional*):
        Name of backbone to use when `backbone_config` is `None`. If `use_pretrained_backbone` is `True`, this
        will load the corresponding pretrained weights from the timm or transformers library. If `use_pretrained_backbone`
        is `False`, this loads the backbone's config and uses that to initialize the backbone with random weights.
    use_pretrained_backbone (`bool`, *optional*, `False`):
        Whether to use pretrained weights for the backbone.
    use_timm_backbone (`bool`, *optional*, `False`):
        Whether to load `backbone` from the timm library. If `False`, the backbone is loaded from the transformers
        library.
    backbone_kwargs (`dict`, *optional*):
        Keyword arguments to be passed to AutoBackbone when loading from a checkpoint
        e.g. `{'out_indices': (0, 1, 2, 3)}`. Cannot be specified if `backbone_config` is set.
    num_queries (`int`, *optional*, defaults to 900):
        Number of object queries, i.e. detection slots. This is the maximal number of objects [`DetaModel`] can
        detect in a single image. In case `two_stage` is set to `True`, we use `two_stage_num_proposals` instead.
    d_model (`int`, *optional*, defaults to 256):
        Dimension of the layers.
    encoder_layers (`int`, *optional*, defaults to 6):
        Number of encoder layers.
    decoder_layers (`int`, *optional*, defaults to 6):
        Number of decoder layers.
    encoder_attention_heads (`int`, *optional*, defaults to 8):
        Number of attention heads for each attention layer in the Transformer encoder.
    decoder_attention_heads (`int`, *optional*, defaults to 8):
        Number of attention heads for each attention layer in the Transformer decoder.
    decoder_ffn_dim (`int`, *optional*, defaults to 2048):
        Dimension of the "intermediate" (often named feed-forward) layer in decoder.
    encoder_ffn_dim (`int`, *optional*, defaults to 2048):
        Dimension of the "intermediate" (often named feed-forward) layer in decoder.
    activation_function (`str` or `function`, *optional*, defaults to `"relu"`):
        The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
        `"relu"`, `"silu"` and `"gelu_new"` are supported.
    dropout (`float`, *optional*, defaults to 0.1):
        The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
    attention_dropout (`float`, *optional*, defaults to 0.0):
        The dropout ratio for the attention probabilities.
    activation_dropout (`float`, *optional*, defaults to 0.0):
        The dropout ratio for activations inside the fully connected layer.
    init_std (`float`, *optional*, defaults to 0.02):
        The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
    init_xavier_std (`float`, *optional*, defaults to 1):
        The scaling factor used for the Xavier initialization gain in the HM Attention map module.
    encoder_layerdrop (`float`, *optional*, defaults to 0.0):
        The LayerDrop probability for the encoder. See the [LayerDrop paper](see https://huggingface.co/papers/1909.11556)
        for more details.
    auxiliary_loss (`bool`, *optional*, defaults to `False`):
        Whether auxiliary decoding losses (loss at each decoder layer) are to be used.
    position_embedding_type (`str`, *optional*, defaults to `"sine"`):
        Type of position embeddings to be used on top of the image features. One of `"sine"` or `"learned"`.
    class_cost (`float`, *optional*, defaults to 1):
        Relative weight of the classification error in the Hungarian matching cost.
    bbox_cost (`float`, *optional*, defaults to 5):
        Relative weight of the L1 error of the bounding box coordinates in the Hungarian matching cost.
    giou_cost (`float`, *optional*, defaults to 2):
        Relative weight of the generalized IoU loss of the bounding box in the Hungarian matching cost.
    mask_loss_coefficient (`float`, *optional*, defaults to 1):
        Relative weight of the Focal loss in the panoptic segmentation loss.
    dice_loss_coefficient (`float`, *optional*, defaults to 1):
        Relative weight of the DICE/F-1 loss in the panoptic segmentation loss.
    bbox_loss_coefficient (`float`, *optional*, defaults to 5):
        Relative weight of the L1 bounding box loss in the object detection loss.
    giou_loss_coefficient (`float`, *optional*, defaults to 2):
        Relative weight of the generalized IoU loss in the object detection loss.
    eos_coefficient (`float`, *optional*, defaults to 0.1):
        Relative classification weight of the 'no-object' class in the object detection loss.
    num_feature_levels (`int`, *optional*, defaults to 5):
        The number of input feature levels.
    encoder_n_points (`int`, *optional*, defaults to 4):
        The number of sampled keys in each feature level for each attention head in the encoder.
    decoder_n_points (`int`, *optional*, defaults to 4):
        The number of sampled keys in each feature level for each attention head in the decoder.
    two_stage (`bool`, *optional*, defaults to `True`):
        Whether to apply a two-stage deformable DETR, where the region proposals are also generated by a variant of
        DETA, which are further fed into the decoder for iterative bounding box refinement.
    two_stage_num_proposals (`int`, *optional*, defaults to 300):
        The number of region proposals to be generated, in case `two_stage` is set to `True`.
    with_box_refine (`bool`, *optional*, defaults to `True`):
        Whether to apply iterative bounding box refinement, where each decoder layer refines the bounding boxes
        based on the predictions from the previous layer.
    focal_alpha (`float`, *optional*, defaults to 0.25):
        Alpha parameter in the focal loss.
    assign_first_stage (`bool`, *optional*, defaults to `True`):
        Whether to assign each prediction i to the highest overlapping ground truth object if the overlap is larger than a threshold 0.7.
    assign_second_stage (`bool`, *optional*, defaults to `True`):
        Whether to assign second assignment procedure in the second stage closely follows the first stage assignment procedure.
    disable_custom_kernels (`bool`, *optional*, defaults to `True`):
        Disable the use of custom CUDA and CPU kernels. This option is necessary for the ONNX export, as custom
        kernels are not supported by PyTorch ONNX export.

Examples:

```python
>>> from transformers import DetaConfig, DetaModel

>>> # Initializing a DETA SenseTime/deformable-detr style configuration
>>> configuration = DetaConfig()

>>> # Initializing a model (with random weights) from the SenseTime/deformable-detr style configuration
>>> model = DetaModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
```detad_modelencoder_attention_heads)hidden_sizenum_attention_headsc,                   > U(       a  [        S5      eUb  Ub  [        S5      eUc(  Uc%  [        R                  S5        [        S   " / SQS9nO@[	        U[
        5      (       a+  UR                  S5      n-[        U-   n.U.R                  U5      nUb  U(       a  Ub  [        S5      eXl        X l	        X0l
        X@l        XPl        X`l        Xpl        UU l        Xl        Xl        Xl        Xl        Xl        Xl        UU l        UU l        UU l        UU l        UU l        UU l        Xl        UU l        UU l        UU l        UU l         UU l!        UU l"        UU l#        UU l$        U U l%        U!U l&        US	L a  US
L a  [        S5      eU"U l'        U#U l(        U$U l)        U%U l*        U&U l+        U'U l,        U(U l-        U)U l.        U*U l/        U+U l0        [b        T/U ]  " SSU0U,D6  g )Nz+Pretrained backbones are not supported yet.z8You can't specify both `backbone` and `backbone_config`.zX`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.resnet)stage2stage3stage4)out_features
model_typez?You can't specify both `backbone_kwargs` and `backbone_config`.TFz3If two_stage is True, with_box_refine must be True.is_encoder_decoder )3
ValueErrorloggerinfor   
isinstancedictpop	from_dictbackbone_configbackboneuse_pretrained_backboneuse_timm_backbonebackbone_kwargsnum_queriesmax_position_embeddingsr   encoder_ffn_dimencoder_layersr   decoder_ffn_dimdecoder_layersdecoder_attention_headsdropoutattention_dropoutactivation_dropoutactivation_functioninit_stdinit_xavier_stdencoder_layerdropauxiliary_lossposition_embedding_typenum_feature_levelsencoder_n_pointsdecoder_n_points	two_stagetwo_stage_num_proposalswith_box_refineassign_first_stageassign_second_stage
class_cost	bbox_cost	giou_costmask_loss_coefficientdice_loss_coefficientbbox_loss_coefficientgiou_loss_coefficienteos_coefficientfocal_alphadisable_custom_kernelssuper__init__)0selfr   r    r!   r"   r#   r$   r%   r'   r&   r   r)   r(   r*   r1   r   r.   r   r+   r,   r-   r/   r0   return_intermediater2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   kwargsbackbone_model_typeconfig_class	__class__s0                                                  p/home/james-whalen/.local/lib/python3.13/site-packages/transformers/models/deprecated/deta/configuration_deta.pyrG   DetaConfig.__init__   s   ^ #JKK&8+?WXX"x'7KKrs,X6DbcO/400&5&9&9,&G#-.AB"."8"8"I&??Z^__. '>$!2.&'>$.,'>$.,'>$!2"4#6  .!2,'>$"4 0 0"'>$."4#6 E!9RSS$""%:"%:"%:"%:".&&<#I,>I&I    returnc                     U R                   $ N)r   rH   s    rN   r   DetaConfig.num_attention_heads  s    +++rP   c                     U R                   $ rS   )r   rT   s    rN   r   DetaConfig.hidden_size	  s    ||rP   c                 P    [        U SS 5      b  S[        U R                  5      0$ 0 $ )Nr   )getattrtyper   rT   s    rN   sub_configsDetaConfig.sub_configs  s8     t.5A T%9%9 :;	
 	
rP   ))r-   r.   r:   r;   r,   r2   r    r   r#   r=   rA   r<   r   r*   r(   r)   r6   r@   rE   r+   r   r&   r1   r'   r5   rC   rD   r>   rB   r/   r0   r?   r%   r4   r$   r3   r7   r8   r!   r"   r9   )+NNFFNi        r]      r^   i   r_           Trelu   皙?r`   r`   g{Gz?g      ?TFsine   r   r   Ti,  TTT   re      rf   rf   re   rg   rc   g      ?T)__name__
__module____qualname____firstlineno____doc__r   attribute_maprG   propertyintr   r   r[   __static_attributes____classcell__)rM   s   @rN   r   r      s    rh J 8M  % $ ! !"  & # #YoJb ,S , , S   
 
rP   r   N)rl   configuration_utilsr   utilsr   autor   
get_loggerrh   r   r   __all__r   rP   rN   <module>rw      s>     4  " 
		H	%z
! z
z .rP   