Ë
    S^(hn5  ã                   óÀ   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ d
dlmZ  ej"                  e«      Z G d„ de«      Z G d„ de
«      ZddgZy)zDETR model configurationé    ©ÚOrderedDict)ÚMapping)Úversioné   )ÚPretrainedConfig)Ú
OnnxConfig)Úlogging)Ú verify_backbone_config_argumentsé   )ÚCONFIG_MAPPINGc                   ó¾   ‡ — e Zd ZdZdZdgZdddœZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„	Zede	fd	„«       Z
ede	fd
„«       Zedefd„«       Zˆ xZS )Ú
DetrConfiga  
    This is the configuration class to store the configuration of a [`DetrModel`]. It is used to instantiate a DETR
    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 DETR
    [facebook/detr-resnet-50](https://huggingface.co/facebook/detr-resnet-50) architecture.

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

    Args:
        use_timm_backbone (`bool`, *optional*, defaults to `True`):
            Whether or not to use the `timm` library for the backbone. If set to `False`, will use the [`AutoBackbone`]
            API.
        backbone_config (`PretrainedConfig` or `dict`, *optional*):
            The configuration of the backbone model. Only used in case `use_timm_backbone` is set to `False` in which
            case it will default to `ResNetConfig()`.
        num_channels (`int`, *optional*, defaults to 3):
            The number of input channels.
        num_queries (`int`, *optional*, defaults to 100):
            Number of object queries, i.e. detection slots. This is the maximal number of objects [`DetrModel`] can
            detect in a single image. For COCO, we recommend 100 queries.
        d_model (`int`, *optional*, defaults to 256):
            This parameter is a general dimension parameter, defining dimensions for components such as the encoder layer and projection parameters in the decoder layer, among others.
        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://arxiv.org/abs/1909.11556)
            for more details.
        decoder_layerdrop (`float`, *optional*, defaults to 0.0):
            The LayerDrop probability for the decoder. See the [LayerDrop paper](see https://arxiv.org/abs/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"`.
        backbone (`str`, *optional*, defaults to `"resnet50"`):
            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*, `True`):
            Whether to use pretrained weights for the backbone.
        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.
        dilation (`bool`, *optional*, defaults to `False`):
            Whether to replace stride with dilation in the last convolutional block (DC5). Only supported when
            `use_timm_backbone` = `True`.
        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.

    Examples:

    ```python
    >>> from transformers import DetrConfig, DetrModel

    >>> # Initializing a DETR facebook/detr-resnet-50 style configuration
    >>> configuration = DetrConfig()

    >>> # Initializing a model (with random weights) from the facebook/detr-resnet-50 style configuration
    >>> model = DetrModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```ÚdetrÚpast_key_valuesÚd_modelÚencoder_attention_heads)Úhidden_sizeÚnum_attention_headsc#                 ó2  •— |r|€i }|rd|d<   g d¢|d<   ||d<   nm|sk|dv rg|€&t         j                  d«       t        d   d	g¬
«      }n;t        |t        «      r+|j                  d«      }$t        |$   }%|%j                  |«      }d }d }t        |||||¬«       || _        || _	        || _
        || _        || _        || _        || _        || _        |	| _        || _        |
| _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _         || _!        || _"        || _#        || _$        || _%        || _&        | | _'        |!| _(        |"| _)        tU        ‰&| �¬  dd|i|#¤Ž y )Né   Úoutput_stride)é   r   r   é   Úout_indicesÚin_chans)NÚresnet50zX`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.ÚresnetÚstage4)Úout_featuresÚ
model_type)Úuse_timm_backboneÚuse_pretrained_backboneÚbackboneÚbackbone_configÚbackbone_kwargsÚis_encoder_decoder© ),ÚloggerÚinfor   Ú
isinstanceÚdictÚgetÚ	from_dictr   r"   r%   Únum_channelsÚnum_queriesr   Ú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Údecoder_layerdropÚnum_hidden_layersÚauxiliary_lossÚposition_embedding_typer$   r#   r&   ÚdilationÚ
class_costÚ	bbox_costÚ	giou_costÚmask_loss_coefficientÚdice_loss_coefficientÚbbox_loss_coefficientÚgiou_loss_coefficientÚeos_coefficientÚsuperÚ__init__)'Úselfr"   r%   r/   r0   r2   r1   r   r4   r3   r5   r<   r=   r'   r9   r   r6   r7   r8   r:   r;   r?   r@   r$   r#   r&   rA   rB   rC   rD   rE   rF   rG   rH   rI   ÚkwargsÚbackbone_model_typeÚconfig_classÚ	__class__s'                                         €úi/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/detr/configuration_detr.pyrK   zDetrConfig.__init__Ž   sÚ  ø€ ñP  Ð!8Ø ˆOÙØ35� Ñ0Ú-9ˆO˜MÑ*Ø*6ˆO˜JÒ'á" xÐ3EÑ'EØÐ&Ü—‘ÐvÔwÜ"0°Ñ":ÈÈ
Ô"S‘Ü˜O¬TÔ2Ø&5×&9Ñ&9¸,Ó&GÐ#Ü-Ð.AÑB�Ø".×"8Ñ"8¸Ó"I�ØˆHàˆHä(Ø/Ø$;ØØ+Ø+õ	
ð "3ˆÔØ.ˆÔØ(ˆÔØ&ˆÔØˆŒØ.ˆÔØ,ˆÔØ'>ˆÔ$Ø.ˆÔØ,ˆÔØ'>ˆÔ$ØˆŒØ!2ˆÔØ"4ˆÔØ#6ˆÔ Ø ˆŒØ.ˆÔØ!2ˆÔØ!2ˆÔØ!/ˆÔØ,ˆÔØ'>ˆÔ$Ø ˆŒØ'>ˆÔ$Ø.ˆÔØ ˆŒà$ˆŒØ"ˆŒØ"ˆŒà%:ˆÔ"Ø%:ˆÔ"Ø%:ˆÔ"Ø%:ˆÔ"Ø.ˆÔÜ‰ÑÑIÐ,>ÐIÀ&ÓIó    Úreturnc                 ó   — | j                   S ©N)r   ©rL   s    rQ   r   zDetrConfig.num_attention_heads÷   s   € à×+Ñ+Ð+rR   c                 ó   — | j                   S rU   )r   rV   s    rQ   r   zDetrConfig.hidden_sizeû   s   € à�|‰|ÐrR   r%   c                 ó   —  | dd|i|¤ŽS )a-  Instantiate a [`DetrConfig`] (or a derived class) from a pre-trained backbone model configuration.

        Args:
            backbone_config ([`PretrainedConfig`]):
                The backbone configuration.
        Returns:
            [`DetrConfig`]: An instance of a configuration object
        r%   r(   r(   )Úclsr%   rM   s      rQ   Úfrom_backbone_configzDetrConfig.from_backbone_configÿ   s   € ñ Ñ= ?Ð=°fÑ=Ð=rR   )"TNr   éd   é   é   é   r\   r]   r^   ç        r_   TÚrelué   çš™™™™™¹?r_   r_   g{®Gáz”?g      ð?FÚsiner   TNFr   é   r   r   r   rd   r   rb   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   Úkeys_to_ignore_at_inferenceÚattribute_maprK   ÚpropertyÚintr   r   Úclassmethodr   rZ   Ú__classcell__)rP   s   @rQ   r   r       sê   ø„ ñdðL €JØ#4Ð"5Ðà Ø8ñ€Mð ØØØØØØ !ØØØ !ØØØØ"ØØØØØØØØ &ØØ $ØØØØØØØØØØõGgJðR ð, Sò ,ó ð,ð ð˜Sò ó ðð ð	>Ð3Cò 	>ó ô	>rR   r   c                   ó†   — e Zd Z ej                  d«      Zedeeee	ef   f   fd„«       Z
edefd„«       Zede	fd„«       Zy)ÚDetrOnnxConfigz1.11rS   c                 ó2   — t        ddddddœfdddifg«      S )	NÚpixel_valuesÚbatchr/   ÚheightÚwidth)r   r   r   r   Ú
pixel_maskr   r   rV   s    rQ   ÚinputszDetrOnnxConfig.inputs  s2   € äà W°ÀHÐQXÑ!YÐZØ  7˜|Ð,ðó
ð 	
rR   c                  ó   — y)Ngñhãˆµøä>r(   rV   s    rQ   Úatol_for_validationz"DetrOnnxConfig.atol_for_validation  s   € àrR   c                  ó   — y)Né   r(   rV   s    rQ   Údefault_onnx_opsetz!DetrOnnxConfig.default_onnx_opset  s   € àrR   N)re   rf   rg   r   ÚparseÚtorch_onnx_minimum_versionrk   r   Ústrrl   rw   Úfloatry   r|   r(   rR   rQ   rp   rp     su   „ Ø!. §¡¨vÓ!6Ðàð
˜  W¨S°#¨XÑ%6Ð 6Ñ7ò 
ó ð
ð ð Uò ó ðð ð Cò ó ñrR   rp   N)rh   Úcollectionsr   Útypingr   Ú	packagingr   Úconfiguration_utilsr   Úonnxr	   Úutilsr
   Úutils.backbone_utilsr   Úautor   Ú
get_loggerre   r)   r   rp   Ú__all__r(   rR   rQ   ú<module>r‹      s_   ðñ å #Ý å å 3Ý Ý Ý DÝ !ð 
ˆ×	Ñ	˜HÓ	%€ôi>Ð!ô i>ôX�Zô ð* Ð)Ð
*�rR   