Ë
    Fêñië|  ã                  ó  — d Z ddlmZ ddlZddlZddlmZ ddlmc mZ	 ddl
mZmZ ddlmZ ddlmZ ddlmZmZmZ d	Z G d
„ dej,                  «      Z G d„ de«      Z G d„ dej,                  «      Z G d„ dej,                  «      Z G d„ dej,                  «      Z G d„ dej,                  «      Z G d„ dej,                  «      Z G d„ dej,                  «      Z G d„ dej,                  «      Z G d„ dej,                  «      Z y)zTransformer modules.é    )ÚannotationsN)Ú	constant_Úxavier_uniform_)Ú
TORCH_1_11é   )ÚConv)Ú_get_clonesÚinverse_sigmoidÚ#multi_scale_deformable_attn_pytorch)
ÚAIFIÚMLPÚDeformableTransformerDecoderÚ!DeformableTransformerDecoderLayerÚLayerNorm2dÚMLPBlockÚMSDeformAttnÚTransformerBlockÚTransformerEncoderLayerÚTransformerLayerc                  óÞ   ‡ — e Zd ZdZddd ej
                  «       df	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zeddd„«       Z	 	 	 d	 	 	 	 	 	 	 	 	 dd„Z		 	 	 d	 	 	 	 	 	 	 	 	 dd	„Z
	 	 	 d	 	 	 	 	 	 	 	 	 dd
„Zˆ xZS )r   aÁ  A single layer of the transformer encoder.

    This class implements a standard transformer encoder layer with multi-head attention and feedforward network,
    supporting both pre-normalization and post-normalization configurations.

    Attributes:
        ma (nn.MultiheadAttention): Multi-head attention module.
        fc1 (nn.Linear): First linear layer in the feedforward network.
        fc2 (nn.Linear): Second linear layer in the feedforward network.
        norm1 (nn.LayerNorm): Layer normalization after attention.
        norm2 (nn.LayerNorm): Layer normalization after feedforward network.
        dropout (nn.Dropout): Dropout layer for the feedforward network.
        dropout1 (nn.Dropout): Dropout layer after attention.
        dropout2 (nn.Dropout): Dropout layer after feedforward network.
        act (nn.Module): Activation function.
        normalize_before (bool): Whether to apply normalization before attention and feedforward.
    é   é   ç        Fc                ó  •— t         ‰| �  «        ddlm} |st	        d«      ‚t        j                  |||d¬«      | _        t        j                  ||«      | _	        t        j                  ||«      | _
        t        j                  |«      | _        t        j                  |«      | _        t        j                  |«      | _        t        j                  |«      | _        t        j                  |«      | _        || _        || _        y)aÅ  Initialize the TransformerEncoderLayer with specified parameters.

        Args:
            c1 (int): Input dimension.
            cm (int): Hidden dimension in the feedforward network.
            num_heads (int): Number of attention heads.
            dropout (float): Dropout probability.
            act (nn.Module): Activation function.
            normalize_before (bool): Whether to apply normalization before attention and feedforward.
        é   )Ú	TORCH_1_9z]TransformerEncoderLayer() requires torch>=1.9 to use nn.MultiheadAttention(batch_first=True).T)ÚdropoutÚbatch_firstN)ÚsuperÚ__init__Úutils.torch_utilsr   ÚModuleNotFoundErrorÚnnÚMultiheadAttentionÚmaÚLinearÚfc1Úfc2Ú	LayerNormÚnorm1Únorm2ÚDropoutr   Údropout1Údropout2ÚactÚnormalize_before)	ÚselfÚc1ÚcmÚ	num_headsr   r/   r0   r   Ú	__class__s	           €úd/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/ultralytics/nn/modules/transformer.pyr    z TransformerEncoderLayer.__init__3   sÄ   ø€ ô& 	‰ÑÔÝ2áÜ%Øoóð ô ×'Ñ'¨¨I¸wÐTXÔYˆŒä—9‘9˜R Ó$ˆŒÜ—9‘9˜R Ó$ˆŒä—\‘\ "Ó%ˆŒ
Ü—\‘\ "Ó%ˆŒ
Ü—z‘z 'Ó*ˆŒÜŸ
™
 7Ó+ˆŒÜŸ
™
 7Ó+ˆŒàˆŒØ 0ˆÕó    c                ó   — |€| S | |z   S )z2Add position embeddings to the tensor if provided.© ©ÚtensorÚposs     r6   Úwith_pos_embedz&TransformerEncoderLayer.with_pos_embed[   ó   € ð ˜ˆvÐ6¨&°3©,Ð6r7   c           	     ól  — | j                  ||«      x}}| j                  |||||¬«      d   }|| j                  |«      z   }| j                  |«      }| j	                  | j                  | j                  | j                  |«      «      «      «      }|| j                  |«      z   }| j                  |«      S )aµ  Perform forward pass with post-normalization.

        Args:
            src (torch.Tensor): Input tensor.
            src_mask (torch.Tensor, optional): Mask for the src sequence.
            src_key_padding_mask (torch.Tensor, optional): Mask for the src keys per batch.
            pos (torch.Tensor, optional): Positional encoding.

        Returns:
            (torch.Tensor): Output tensor after attention and feedforward.
        ©ÚvalueÚ	attn_maskÚkey_padding_maskr   )
r=   r%   r-   r*   r(   r   r/   r'   r.   r+   )r1   ÚsrcÚsrc_maskÚsrc_key_padding_maskr<   ÚqÚkÚsrc2s           r6   Úforward_postz$TransformerEncoderLayer.forward_post`   s£   € ð$ ×#Ñ# C¨Ó-Ð-ˆˆAØ�w‰w�q˜! 3°(ÐMaˆwÓbÐcdÑeˆØ�D—M‘M $Ó'Ñ'ˆØ�j‰j˜‹oˆØ�x‰x˜Ÿ™ T§X¡X¨d¯h©h°s«mÓ%<Ó=Ó>ˆØ�D—M‘M $Ó'Ñ'ˆØ�z‰z˜#‹Ðr7   c           	     ól  — | j                  |«      }| j                  ||«      x}}| j                  |||||¬«      d   }|| j                  |«      z   }| j	                  |«      }| j                  | j                  | j                  | j                  |«      «      «      «      }|| j                  |«      z   S )a´  Perform forward pass with pre-normalization.

        Args:
            src (torch.Tensor): Input tensor.
            src_mask (torch.Tensor, optional): Mask for the src sequence.
            src_key_padding_mask (torch.Tensor, optional): Mask for the src keys per batch.
            pos (torch.Tensor, optional): Positional encoding.

        Returns:
            (torch.Tensor): Output tensor after attention and feedforward.
        r@   r   )
r*   r=   r%   r-   r+   r(   r   r/   r'   r.   )r1   rD   rE   rF   r<   rI   rG   rH   s           r6   Úforward_prez#TransformerEncoderLayer.forward_prez   s£   € ð$ �z‰z˜#‹ˆØ×#Ñ# D¨#Ó.Ð.ˆˆAØ�w‰w�q˜! 4°8ÐNbˆwÓcÐdeÑfˆØ�D—M‘M $Ó'Ñ'ˆØ�z‰z˜#‹ˆØ�x‰x˜Ÿ™ T§X¡X¨d¯h©h°t«nÓ%=Ó>Ó?ˆØ�T—]‘] 4Ó(Ñ(Ð(r7   c                ój   — | j                   r| j                  ||||«      S | j                  ||||«      S )a¿  Forward propagate the input through the encoder module.

        Args:
            src (torch.Tensor): Input tensor.
            src_mask (torch.Tensor, optional): Mask for the src sequence.
            src_key_padding_mask (torch.Tensor, optional): Mask for the src keys per batch.
            pos (torch.Tensor, optional): Positional encoding.

        Returns:
            (torch.Tensor): Output tensor after transformer encoder layer.
        )r0   rL   rJ   )r1   rD   rE   rF   r<   s        r6   ÚforwardzTransformerEncoderLayer.forward”   s=   € ð$ × Ò Ø×#Ñ# C¨Ð3GÈÓMÐMØ× Ñ   hÐ0DÀcÓJÐJr7   ©r2   Úintr3   rP   r4   rP   r   Úfloatr/   ú	nn.Moduler0   Úbool©N©r;   útorch.Tensorr<   útorch.Tensor | NoneÚreturnrV   ©NNN)
rD   rV   rE   rW   rF   rW   r<   rW   rX   rV   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   ÚGELUr    Ústaticmethodr=   rJ   rL   rN   Ú__classcell__©r5   s   @r6   r   r       s;  ø„ ñð* ØØØ ˜Ÿ™›Ø!&ð&1àð&1ð ð&1ð ð	&1ð
 ð&1ð ð&1ð õ&1ðP ó7ó ð7ð )-Ø48Ø#'ðàðð &ðð 2ð	ð
 !ðð 
óð: )-Ø48Ø#'ð)àð)ð &ð)ð 2ð	)ð
 !ð)ð 
ó)ð: )-Ø48Ø#'ðKàðKð &ðKð 2ð	Kð
 !ðKð 
÷Kr7   r   c                  ó˜   ‡ — e Zd ZdZddd ej
                  «       df	 	 	 	 	 	 	 	 	 	 	 d	ˆ fd„Zd
ˆ fd„Ze	 d	 	 	 	 	 	 	 	 	 dd„«       Z	ˆ xZ
S )r   zöAIFI transformer layer for 2D data with positional embeddings.

    This class extends TransformerEncoderLayer to work with 2D feature maps by adding 2D sine-cosine positional
    embeddings and handling the spatial dimensions appropriately.
    r   r   r   Fc                ó.   •— t         ‰| �  ||||||«       y)a»  Initialize the AIFI instance with specified parameters.

        Args:
            c1 (int): Input dimension.
            cm (int): Hidden dimension in the feedforward network.
            num_heads (int): Number of attention heads.
            dropout (float): Dropout probability.
            act (nn.Module): Activation function.
            normalize_before (bool): Whether to apply normalization before attention and feedforward.
        N)r   r    )r1   r2   r3   r4   r   r/   r0   r5   s          €r6   r    zAIFI.__init__²   s   ø€ ô& 	‰Ñ˜˜R ¨G°SÐ:JÕKr7   c                ód  •— |j                   dd \  }}}| j                  |||«      }t        ‰| �  |j	                  d«      j                  ddd«      |j                  |j                  |j                  ¬«      ¬«      }|j                  ddd«      j                  d|||g«      j                  «       S )zÝForward pass for the AIFI transformer layer.

        Args:
            x (torch.Tensor): Input tensor with shape [B, C, H, W].

        Returns:
            (torch.Tensor): Output tensor with shape [B, C, H, W].
        r   Né   r   )ÚdeviceÚdtype)r<   éÿÿÿÿ)ÚshapeÚ"build_2d_sincos_position_embeddingr   rN   ÚflattenÚpermuteÚtorf   rg   ÚviewÚ
contiguous)r1   ÚxÚcÚhÚwÚ	pos_embedr5   s         €r6   rN   zAIFI.forwardÇ   s¡   ø€ ð —'‘'˜!˜"�+‰ˆˆ1ˆaØ×;Ñ;¸A¸qÀ!ÓDˆ	ä‰G‰O˜AŸI™I a›L×0Ñ0°°A°qÓ9¸y¿|¹|ÐST×S[ÑS[Ðcd×cjÑcj¸|Ó?kˆOÓlˆØ�y‰y˜˜A˜qÓ!×&Ñ&¨¨A¨q°! }Ó5×@Ñ@ÓBÐBr7   c                óÂ  — |dz  dk(  sJ d«       ‚t        j                  | t         j                  ¬«      }t        j                  |t         j                  ¬«      }t        rt        j                  ||d¬«      nt        j                  ||«      \  }}|dz  }t        j                  |t         j                  ¬«      |z  }d||z  z  }|j                  «       d   |d	   z  }|j                  «       d   |d	   z  }	t        j                  t        j                  |«      t        j                  |«      t        j                  |	«      t        j                  |	«      gd
«      d	   S )a~  Build 2D sine-cosine position embedding.

        Args:
            w (int): Width of the feature map.
            h (int): Height of the feature map.
            embed_dim (int): Embedding dimension.
            temperature (float): Temperature for the sine/cosine functions.

        Returns:
            (torch.Tensor): Position embedding with shape [1, h*w, embed_dim].
        é   r   zHEmbed dimension must be divisible by 4 for 2D sin-cos position embedding©rg   Úij)Úindexingg      ð?©.NNr   )	ÚtorchÚarangeÚfloat32r   Úmeshgridrk   ÚcatÚsinÚcos)
rs   rr   Ú	embed_dimÚtemperatureÚgrid_wÚgrid_hÚpos_dimÚomegaÚout_wÚout_hs
             r6   rj   z'AIFI.build_2d_sincos_position_embeddingÖ   s  € ð ˜1‰} Ò!ÐmÐ#mÓmÐ!Ü—‘˜a¤u§}¡}Ô5ˆÜ—‘˜a¤u§}¡}Ô5ˆÝJTœŸ™¨°ÀÕFÔZ_×ZhÑZhÐioÐqwÓZx‰ˆ�Ø˜q‘.ˆÜ—‘˜W¬E¯M©MÔ:¸WÑDˆØ�{ EÑ)Ñ*ˆà—‘Ó  Ñ+¨e°D©kÑ9ˆØ—‘Ó  Ñ+¨e°D©kÑ9ˆä�y‰yœ%Ÿ)™) EÓ*¬E¯I©I°eÓ,<¼e¿i¹iÈÓ>NÔPU×PYÑPYÐZ_ÓP`ÐaÐcdÓeÐfjÑkÐkr7   rO   ©rp   rV   rX   rV   )é   g     ˆÃ@)
rs   rP   rr   rP   r‚   rP   rƒ   rQ   rX   rV   )rZ   r[   r\   r]   r#   r^   r    rN   r_   rj   r`   ra   s   @r6   r   r   «   s³   ø„ ñð ØØØ ˜Ÿ™›Ø!&ðLàðLð ðLð ð	Lð
 ðLð ðLð õLõ*Cð àCJðlØðlØðlØ#&ðlØ;@ðlà	òló ôlr7   r   c                  ó,   ‡ — e Zd ZdZdˆ fd„Zdd„Zˆ xZS )r   zeTransformer layer https://arxiv.org/abs/2010.11929 (LayerNorm layers removed for better performance).c                ó|  •— t         ‰| �  «        t        j                  ||d¬«      | _        t        j                  ||d¬«      | _        t        j                  ||d¬«      | _        t        j                  ||¬«      | _        t        j                  ||d¬«      | _	        t        j                  ||d¬«      | _
        y)zåInitialize a self-attention mechanism using linear transformations and multi-head attention.

        Args:
            c (int): Input and output channel dimension.
            num_heads (int): Number of attention heads.
        F)Úbias)r‚   r4   N)r   r    r#   r&   rG   rH   Úvr$   r%   r'   r(   )r1   rq   r4   r5   s      €r6   r    zTransformerLayer.__init__ö   sˆ   ø€ ô 	‰ÑÔÜ—‘˜1˜a eÔ,ˆŒÜ—‘˜1˜a eÔ,ˆŒÜ—‘˜1˜a eÔ,ˆŒÜ×'Ñ'°!¸yÔIˆŒÜ—9‘9˜Q ¨Ô.ˆŒÜ—9‘9˜Q ¨Ô.ˆ�r7   c                óÔ   — | j                  | j                  |«      | j                  |«      | j                  |«      «      d   |z   }| j	                  | j                  |«      «      |z   S )zØApply a transformer block to the input x and return the output.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor after transformer layer.
        r   )r%   rG   rH   r�   r(   r'   ©r1   rp   s     r6   rN   zTransformerLayer.forward  sT   € ð �G‰G�D—F‘F˜1“I˜tŸv™v a›y¨$¯&©&°«)Ó4°QÑ7¸!Ñ;ˆØ�x‰x˜Ÿ™ ›Ó$ qÑ(Ð(r7   )rq   rP   r4   rP   rŠ   ©rZ   r[   r\   r]   r    rN   r`   ra   s   @r6   r   r   ó   s   ø„ Ùoõ/÷
)r7   r   c                  ó,   ‡ — e Zd ZdZdˆ fd„Zdd„Zˆ xZS )r   a  Vision Transformer block based on https://arxiv.org/abs/2010.11929.

    This class implements a complete transformer block with optional convolution layer for channel adjustment, learnable
    position embedding, and multiple transformer layers.

    Attributes:
        conv (Conv, optional): Convolution layer if input and output channels differ.
        linear (nn.Linear): Learnable position embedding.
        tr (nn.Sequential): Sequential container of transformer layers.
        c2 (int): Output channel dimension.
    c                óø   •‡‡— t         ‰| �  «        d| _        |‰k7  rt        |‰«      | _        t	        j
                  ‰‰«      | _        t	        j                  ˆˆfd„t        |«      D «       Ž | _	        ‰| _
        y)aL  Initialize a Transformer module with position embedding and specified number of heads and layers.

        Args:
            c1 (int): Input channel dimension.
            c2 (int): Output channel dimension.
            num_heads (int): Number of attention heads.
            num_layers (int): Number of transformer layers.
        Nc              3  ó6   •K  — | ]  }t        ‰‰«      –— Œ y ­wrT   )r   )Ú.0Ú_Úc2r4   s     €€r6   ú	<genexpr>z,TransformerBlock.__init__.<locals>.<genexpr>-  s   øè ø€ Ò!]ÀaÔ"2°2°y×"AÑ!]ùs   ƒ)r   r    Úconvr   r#   r&   ÚlinearÚ
SequentialÚrangeÚtrr˜   )r1   r2   r˜   r4   Ú
num_layersr5   s     `` €r6   r    zTransformerBlock.__init__  s`   ú€ ô 	‰ÑÔØˆŒ	Ø�Š8Ü˜R ›ˆDŒIÜ—i‘i  BÓ'ˆŒÜ—-‘-Ô!]Ì5ÐQ[ÓK\Ô!]Ð^ˆŒØˆ�r7   c                óB  — | j                   �| j                  |«      }|j                  \  }}}}|j                  d«      j                  ddd«      }| j	                  || j                  |«      z   «      j                  ddd«      j                  || j                  ||«      S )zíForward propagate the input through the transformer block.

        Args:
            x (torch.Tensor): Input tensor with shape [b, c1, h, w].

        Returns:
            (torch.Tensor): Output tensor with shape [b, c2, h, w].
        re   r   r   )rš   ri   rk   rl   rž   r›   Úreshaper˜   )r1   rp   Úbr—   rr   rs   Úps          r6   rN   zTransformerBlock.forward0  sŠ   € ð �9‰9Ð Ø—	‘	˜!“ˆAØ—W‘W‰
ˆˆ1ˆa�Ø�I‰I�a‹L× Ñ   A qÓ)ˆØ�w‰w�q˜4Ÿ;™; q›>Ñ)Ó*×2Ñ2°1°a¸Ó;×CÑCÀAÀtÇwÁwÐPQÐSTÓUÐUr7   )r2   rP   r˜   rP   r4   rP   rŸ   rP   rŠ   r’   ra   s   @r6   r   r     s   ø„ ñ
õ÷"Vr7   r   c                  óD   ‡ — e Zd ZdZej
                  fdˆ fd„Zdd„Zˆ xZS )r   z+A single block of a multi-layer perceptron.c                ó¦   •— t         ‰| �  «        t        j                  ||«      | _        t        j                  ||«      | _         |«       | _        y)a  Initialize the MLPBlock with specified embedding dimension, MLP dimension, and activation function.

        Args:
            embedding_dim (int): Input and output dimension.
            mlp_dim (int): Hidden dimension.
            act (type): Activation function class.
        N)r   r    r#   r&   Úlin1Úlin2r/   )r1   Úembedding_dimÚmlp_dimr/   r5   s       €r6   r    zMLPBlock.__init__C  s=   ø€ ô 	‰ÑÔÜ—I‘I˜m¨WÓ5ˆŒ	Ü—I‘I˜g }Ó5ˆŒ	Ù“5ˆ�r7   c                ó`   — | j                  | j                  | j                  |«      «      «      S )z¯Forward pass for the MLPBlock.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor after MLP block.
        )r§   r/   r¦   r‘   s     r6   rN   zMLPBlock.forwardP  s$   € ð �y‰y˜Ÿ™ $§)¡)¨A£,Ó/Ó0Ð0r7   )r¨   rP   r©   rP   rŠ   )	rZ   r[   r\   r]   r#   r^   r    rN   r`   ra   s   @r6   r   r   @  s   ø„ Ù5à=?¿W¹Wö ÷	1r7   r   c                  ód   ‡ — e Zd ZdZej
                  dddf	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Zˆ xZS )r   a±  A simple multi-layer perceptron (also called FFN).

    This class implements a configurable MLP with multiple linear layers, activation functions, and optional sigmoid
    output activation.

    Attributes:
        num_layers (int): Number of layers in the MLP.
        layers (nn.ModuleList): List of linear layers.
        sigmoid (bool): Whether to apply sigmoid to the output.
        act (nn.Module): Activation function.
    FNc	                ót  •— t         ‰
| �  «        || _        |g|dz
  z  }	t        j                  d„ t        |g|	¢g |	¢|‘«      D «       «      | _        || _         |«       | _        |r||k7  rt        d«      ‚|| _
        t        |t        j                  «      s|�J ‚|xs t        j                  «       | _        y)a7  Initialize the MLP with specified input, hidden, output dimensions and number of layers.

        Args:
            input_dim (int): Input dimension.
            hidden_dim (int): Hidden dimension.
            output_dim (int): Output dimension.
            num_layers (int): Number of layers.
            act (type): Activation function class.
            sigmoid (bool): Whether to apply sigmoid to the output.
            residual (bool): Whether to use residual connections.
            out_norm (nn.Module, optional): Normalization layer for the output.
        r   c              3  óN   K  — | ]  \  }}t        j                  ||«      –— Œ y ­wrT   )r#   r&   )r–   ÚnrH   s      r6   r™   zMLP.__init__.<locals>.<genexpr>ƒ  s   è ø€ Ò#g¹¸¸1¤B§I¡I¨a°§OÑ#gùs   ‚#%z5residual is only supported if input_dim == output_dimN)r   r    rŸ   r#   Ú
ModuleListÚzipÚlayersÚsigmoidr/   Ú
ValueErrorÚresidualÚ
isinstanceÚModuleÚIdentityÚout_norm)r1   Ú	input_dimÚ
hidden_dimÚ
output_dimrŸ   r/   r²   r´   r¸   rr   r5   s             €r6   r    zMLP.__init__i  s°   ø€ ô. 	‰ÑÔØ$ˆŒØˆL˜J¨™NÑ+ˆÜ—m‘mÑ#gÄÀYÀOÐQRÀOÐUeÐWXÐUeÐZdÐUeÓ@fÔ#gÓgˆŒØˆŒÙ“5ˆŒÙ˜	 ZÒ/ÜÐTÓUÐUØ ˆŒä˜(¤B§I¡IÔ.°(Ð2BÐBÐBØ Ò1¤B§K¡K£Mˆ�r7   c                óv  — |}t        | j                  «      D ]J  \  }}|| j                  dz
  k  r+ t        | dt	        j
                  «       «       ||«      «      n ||«      }ŒL t        | dd«      r||z   } t        | dt	        j                  «       «      |«      }t        | dd«      r|j                  «       S |S )z«Forward pass for the entire MLP.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor after MLP.
        r   r/   r´   Fr¸   r²   )Ú	enumerater±   rŸ   Úgetattrr#   ÚReLUr·   r²   )r1   rp   Úorig_xÚiÚlayers        r6   rN   zMLP.forward�  s­   € ð ˆÜ! $§+¡+Ó.ò 	c‰HˆAˆuØ=>ÀÇÁÐSTÑATÒ=TÐ/”˜˜e¤R§W¡W£YÓ/±°a³Ô9ÑZ_Ð`aÓZb‰Að	cä�4˜ UÔ+Ø�F‘
ˆAØ4ŒG�D˜*¤b§k¡k£mÓ4°QÓ7ˆÜ% d¨I°uÔ=ˆq�y‰y‹{ÐDÀ1ÐDr7   )r¹   rP   rº   rP   r»   rP   rŸ   rP   r²   rS   r´   rS   r¸   rR   rŠ   )	rZ   r[   r\   r]   r#   r¿   r    rN   r`   ra   s   @r6   r   r   \  sj   ø„ ñ
ð$ �G‰GØØØ"ð"2àð"2ð ð"2ð ð	"2ð
 ð"2ð ð"2ð ð"2ð õ"2÷HEr7   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   ap  2D Layer Normalization module inspired by Detectron2 and ConvNeXt implementations.

    This class implements layer normalization for 2D feature maps, normalizing across the channel dimension while
    preserving spatial dimensions.

    Attributes:
        weight (nn.Parameter): Learnable scale parameter.
        bias (nn.Parameter): Learnable bias parameter.
        eps (float): Small constant for numerical stability.

    References:
        https://github.com/facebookresearch/detectron2/blob/main/detectron2/layers/batch_norm.py
        https://github.com/facebookresearch/ConvNeXt/blob/main/models/convnext.py
    c                óä   •— t         ‰| �  «        t        j                  t	        j
                  |«      «      | _        t        j                  t	        j                  |«      «      | _        || _	        y)zËInitialize LayerNorm2d with the given parameters.

        Args:
            num_channels (int): Number of channels in the input.
            eps (float): Small constant for numerical stability.
        N)
r   r    r#   Ú	Parameterr{   ÚonesÚweightÚzerosrŽ   Úeps)r1   Únum_channelsrÉ   r5   s      €r6   r    zLayerNorm2d.__init__¯  sI   ø€ ô 	‰ÑÔÜ—l‘l¤5§:¡:¨lÓ#;Ó<ˆŒÜ—L‘L¤§¡¨\Ó!:Ó;ˆŒ	Øˆ�r7   c                ó  — |j                  dd¬«      }||z
  j                  d«      j                  dd¬«      }||z
  t        j                  || j                  z   «      z  }| j
                  dd…ddf   |z  | j                  dd…ddf   z   S )z¼Perform forward pass for 2D layer normalization.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Normalized output tensor.
        r   T©Úkeepdimre   N)ÚmeanÚpowr{   ÚsqrtrÉ   rÇ   rŽ   )r1   rp   ÚuÚss       r6   rN   zLayerNorm2d.forward»  s„   € ð �F‰F�1˜dˆFÓ#ˆØ�‰U�K‰K˜‹N×Ñ ¨4ÐÓ0ˆØ�‰U”e—j‘j  T§X¡X¡Ó.Ñ.ˆØ�{‰{š1˜d D˜=Ñ)¨AÑ-°·	±	º!¸TÀ4¸-Ñ0HÑHÐHr7   )g�íµ ÷Æ°>)rÊ   rP   rÉ   rQ   rŠ   r’   ra   s   @r6   r   r   Ÿ  s   ø„ ñö
÷Ir7   r   c                  óN   ‡ — e Zd ZdZddˆ fd„Zd„ Z	 d	 	 	 	 	 	 	 	 	 	 	 dd„Zˆ xZS )	r   aò  Multiscale Deformable Attention Module based on Deformable-DETR and PaddleDetection implementations.

    This module implements multiscale deformable attention that can attend to features at multiple scales with learnable
    sampling locations and attention weights.

    Attributes:
        im2col_step (int): Step size for im2col operations.
        d_model (int): Model dimension.
        n_levels (int): Number of feature levels.
        n_heads (int): Number of attention heads.
        n_points (int): Number of sampling points per attention head per feature level.
        sampling_offsets (nn.Linear): Linear layer for generating sampling offsets.
        attention_weights (nn.Linear): Linear layer for generating attention weights.
        value_proj (nn.Linear): Linear layer for projecting values.
        output_proj (nn.Linear): Linear layer for projecting output.

    References:
        https://github.com/fundamentalvision/Deformable-DETR/blob/main/models/ops/modules/ms_deform_attn.py
    c                óØ  •— t         ‰| �  «        ||z  dk7  rt        d|› d|› �«      ‚||z  }||z  |k(  sJ d«       ‚d| _        || _        || _        || _        || _        t        j                  |||z  |z  dz  «      | _
        t        j                  |||z  |z  «      | _        t        j                  ||«      | _        t        j                  ||«      | _        | j                  «        y)a>  Initialize MSDeformAttn with the given parameters.

        Args:
            d_model (int): Model dimension.
            n_levels (int): Number of feature levels.
            n_heads (int): Number of attention heads.
            n_points (int): Number of sampling points per attention head per feature level.
        r   z.d_model must be divisible by n_heads, but got z and z(`d_model` must be divisible by `n_heads`é@   re   N)r   r    r³   Úim2col_stepÚd_modelÚn_levelsÚn_headsÚn_pointsr#   r&   Úsampling_offsetsÚattention_weightsÚ
value_projÚoutput_projÚ_reset_parameters)r1   r×   rØ   rÙ   rÚ   Ú_d_per_headr5   s         €r6   r    zMSDeformAttn.__init__ß  sñ   ø€ ô 	‰ÑÔØ�WÑ Ò!ÜÐMÈgÈYÐV[Ð\cÐ[dÐeÓfÐfØ Ñ(ˆà˜WÑ$¨Ò/Ð[Ð1[Ó[Ð/àˆÔàˆŒØ ˆŒØˆŒØ ˆŒä "§	¡	¨'°7¸XÑ3EÈÑ3PÐSTÑ3TÓ UˆÔÜ!#§¡¨7°G¸hÑ4FÈÑ4QÓ!RˆÔÜŸ)™) G¨WÓ5ˆŒÜŸ9™9 W¨gÓ6ˆÔà×ÑÕ r7   c                óH  — t        | j                  j                  j                  d«       t	        j
                  | j                  t        j                  ¬«      dt        j                  z  | j                  z  z  }t	        j                  |j                  «       |j                  «       gd«      }||j                  «       j                  dd¬«      d   z  j                  | j                  ddd	«      j!                  d| j"                  | j$                  d«      }t'        | j$                  «      D ]  }|d
d
…d
d
…|d
d
…fxx   |dz   z  cc<   Œ t	        j(                  «       5  t+        j,                  |j                  d«      «      | j                  _        d
d
d
«       t        | j0                  j                  j                  d«       t        | j0                  j.                  j                  d«       t3        | j4                  j                  j                  «       t        | j4                  j.                  j                  d«       t3        | j6                  j                  j                  «       t        | j6                  j.                  j                  d«       y
# 1 sw Y   �ŒxY w)zReset module parameters.r   rw   g       @rh   TrÌ   r   r   re   N)r   rÛ   rÇ   Údatar{   r|   rÙ   r}   ÚmathÚpiÚstackr�   r€   ÚabsÚmaxrn   ÚrepeatrØ   rÚ   r�   Úno_gradr#   rÅ   rŽ   rÜ   r   rÝ   rÞ   )r1   ÚthetasÚ	grid_initrÁ   s       r6   rß   zMSDeformAttn._reset_parametersý  sÜ  € ä�$×'Ñ'×.Ñ.×3Ñ3°SÔ9Ü—‘˜dŸl™l´%·-±-Ô@ÀCÌ$Ï'É'ÁMÐTX×T`ÑT`ÑD`ÑaˆÜ—K‘K §¡£¨v¯z©z«|Ð <¸bÓAˆ	à˜Ÿ™›×,Ñ,¨R¸Ð,Ó>¸qÑAÑAß‰T�$—,‘,  1 aÓ(ß‰V�A�t—}‘} d§m¡m°QÓ7ð 	ô
 �t—}‘}Ó%ò 	+ˆAØ’aš˜Ašq�jÓ! Q¨¡UÑ*Ô!ð	+ä�]‰]‹_ñ 	JÜ)+¯©°i·n±nÀRÓ6HÓ)IˆD×!Ñ!Ô&÷	Jä�$×(Ñ(×/Ñ/×4Ñ4°cÔ:Ü�$×(Ñ(×-Ñ-×2Ñ2°CÔ8Ü˜Ÿ™×.Ñ.×3Ñ3Ô4Ü�$—/‘/×&Ñ&×+Ñ+¨SÔ1Ü˜×(Ñ(×/Ñ/×4Ñ4Ô5Ü�$×"Ñ"×'Ñ'×,Ñ,¨cÕ2÷	Jñ 	Jús   Å 4JÊJ!c           	     óª  — |j                   dd \  }}|j                   d   }t        d„ |D «       «      |k(  sJ ‚| j                  |«      }|�|j                  |d   t	        d«      «      }|j                  ||| j                  | j                  | j                  z  «      }| j                  |«      j                  ||| j                  | j                  | j                  d«      }	| j                  |«      j                  ||| j                  | j                  | j                  z  «      }
t        j                  |
d«      j                  ||| j                  | j                  | j                  «      }
|j                   d   }|dk(  rdt        j                  ||j                   |j"                  ¬«      j%                  d«      }|	|ddddd…ddd…f   z  }|dd…dd…ddd…ddd…f   |z   }nQ|d	k(  r=|	| j                  z  |dd…dd…ddd…ddd…f   z  d
z  }|dd…dd…ddd…ddd…f   |z   }nt'        d|› d�«      ‚t)        ||||
«      }| j+                  |«      S )aÐ  Perform forward pass for multiscale deformable attention.

        Args:
            query (torch.Tensor): Query tensor with shape [bs, query_length, C].
            refer_bbox (torch.Tensor): Reference bounding boxes with shape [bs, query_length, n_levels, 2 or 4], range
                in [0, 1], top-left (0,0), bottom-right (1, 1), including padding area.
            value (torch.Tensor): Value tensor with shape [bs, value_length, C].
            value_shapes (list): List with shape [n_levels, 2], [(H_0, W_0), (H_1, W_1), ..., (H_{L-1}, W_{L-1})].
            value_mask (torch.Tensor, optional): Mask tensor with shape [bs, value_length], True for padding elements,
                False for non-padding elements.

        Returns:
            (torch.Tensor): Output tensor with shape [bs, Length_{query}, C].

        References:
            https://github.com/PaddlePaddle/PaddleDetection/blob/develop/ppdet/modeling/transformers/deformable_transformer.py
        Nre   r   c              3  ó2   K  — | ]  }|d    |d   z  –— Œ y­w)r   r   Nr9   )r–   rÒ   s     r6   r™   z'MSDeformAttn.forward.<locals>.<genexpr>-  s   è ø€ Ò5 1�1�Q‘4˜!˜A™$•;Ñ5ùs   ‚rz   r   rh   )rg   rf   rv   g      à?z5Last dim of reference_points must be 2 or 4, but got ú.)ri   ÚsumrÝ   Úmasked_fillrQ   rn   rÙ   r×   rÛ   rØ   rÚ   rÜ   ÚFÚsoftmaxr{   Ú	as_tensorrg   rf   Úflipr³   r   rÞ   )r1   ÚqueryÚ
refer_bboxrA   Úvalue_shapesÚ
value_maskÚbsÚlen_qÚlen_vrÛ   rÜ   Ú
num_pointsÚoffset_normalizerÚaddÚsampling_locationsÚoutputs                   r6   rN   zMSDeformAttn.forward  sH  € ð2 —K‘K  �O‰	ˆˆEØ—‘˜A‘ˆÜÑ5¨Ô5Ó5¸Ò>Ð>Ð>à—‘ Ó&ˆØÐ!Ø×%Ñ% j°Ñ&;¼UÀ1»XÓFˆEØ—
‘
˜2˜u d§l¡l°D·L±LÀDÇLÁLÑ4PÓQˆØ×0Ñ0°Ó7×<Ñ<¸RÀÈÏÉÐVZ×VcÑVcÐei×erÑerÐtuÓvÐØ ×2Ñ2°5Ó9×>Ñ>¸rÀ5È$Ï,É,ÐX\×XeÑXeÐhl×huÑhuÑXuÓvÐÜŸI™IÐ&7¸Ó<×AÑAÀ"ÀeÈTÏ\É\Ð[_×[hÑ[hÐjn×jwÑjwÓxÐà×%Ñ% bÑ)ˆ
Ø˜Š?Ü %§¡°ÀEÇKÁKÐX]×XdÑXdÔ e× jÑ jÐkmÓ nÐØ"Ð%6°t¸TÀ4ÊÈDÒRSÐ7SÑ%TÑTˆCØ!+ªAªq°$º¸4ÂÐ,BÑ!CÀcÑ!IÑØ˜1Š_Ø" T§]¡]Ñ2°ZÂÂ1ÀdÊAÈtÐUVÑUWÐ@WÑ5XÑXÐ[^Ñ^ˆCØ!+ªAªq°$º¸4ÀÀ!ÀÐ,CÑ!DÀsÑ!JÑäÐTÐU_ÐT`Ð`aÐbÓcÐcÜ4°U¸LÐJ\Ð^oÓpˆØ×Ñ Ó'Ð'r7   )r‹   rv   r   rv   )r×   rP   rØ   rP   rÙ   rP   rÚ   rP   rT   )rõ   rV   rö   rV   rA   rV   r÷   Úlistrø   rW   rX   rV   )rZ   r[   r\   r]   r    rß   rN   r`   ra   s   @r6   r   r   Ê  sV   ø„ ñö(!ò<3ð6 +/ð0(àð0(ð !ð0(ð ð	0(ð
 ð0(ð (ð0(ð 
÷0(r7   r   c                  ó´   ‡ — e Zd ZdZdddd ej
                  «       ddf	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zedd„«       Zdd	„Z		 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
„Z
ˆ xZS )r   a6  Deformable Transformer Decoder Layer inspired by PaddleDetection and Deformable-DETR implementations.

    This class implements a single decoder layer with self-attention, cross-attention using multiscale deformable
    attention, and a feedforward network.

    Attributes:
        self_attn (nn.MultiheadAttention): Self-attention module.
        dropout1 (nn.Dropout): Dropout after self-attention.
        norm1 (nn.LayerNorm): Layer normalization after self-attention.
        cross_attn (MSDeformAttn): Cross-attention module.
        dropout2 (nn.Dropout): Dropout after cross-attention.
        norm2 (nn.LayerNorm): Layer normalization after cross-attention.
        linear1 (nn.Linear): First linear layer in the feedforward network.
        act (nn.Module): Activation function.
        dropout3 (nn.Dropout): Dropout in the feedforward network.
        linear2 (nn.Linear): Second linear layer in the feedforward network.
        dropout4 (nn.Dropout): Dropout after the feedforward network.
        norm3 (nn.LayerNorm): Layer normalization after the feedforward network.

    References:
        https://github.com/PaddlePaddle/PaddleDetection/blob/develop/ppdet/modeling/transformers/deformable_transformer.py
        https://github.com/fundamentalvision/Deformable-DETR/blob/main/models/deformable_transformer.py
    r‹   r   i   r   rv   c                óh  •— t         ‰| �  «        t        j                  |||¬«      | _        t        j
                  |«      | _        t        j                  |«      | _        t        ||||«      | _
        t        j
                  |«      | _        t        j                  |«      | _        t        j                  ||«      | _        || _        t        j
                  |«      | _        t        j                  ||«      | _        t        j
                  |«      | _        t        j                  |«      | _        y)aÕ  Initialize the DeformableTransformerDecoderLayer with the given parameters.

        Args:
            d_model (int): Model dimension.
            n_heads (int): Number of attention heads.
            d_ffn (int): Dimension of the feedforward network.
            dropout (float): Dropout probability.
            act (nn.Module): Activation function.
            n_levels (int): Number of feature levels.
            n_points (int): Number of sampling points.
        )r   N)r   r    r#   r$   Ú	self_attnr,   r-   r)   r*   r   Ú
cross_attnr.   r+   r&   Úlinear1r/   Údropout3Úlinear2Údropout4Únorm3)	r1   r×   rÙ   Úd_ffnr   r/   rØ   rÚ   r5   s	           €r6   r    z*DeformableTransformerDecoderLayer.__init__^  sÙ   ø€ ô* 	‰ÑÔô ×.Ñ.¨w¸ÈÔQˆŒÜŸ
™
 7Ó+ˆŒÜ—\‘\ 'Ó*ˆŒ
ô ' w°¸'À8ÓLˆŒÜŸ
™
 7Ó+ˆŒÜ—\‘\ 'Ó*ˆŒ
ô —y‘y ¨%Ó0ˆŒØˆŒÜŸ
™
 7Ó+ˆŒÜ—y‘y ¨Ó0ˆŒÜŸ
™
 7Ó+ˆŒÜ—\‘\ 'Ó*ˆ�
r7   c                ó   — |€| S | |z   S )z;Add positional embeddings to the input tensor, if provided.r9   r:   s     r6   r=   z0DeformableTransformerDecoderLayer.with_pos_embed‡  r>   r7   c           	     óÈ   — | j                  | j                  | j                  | j                  |«      «      «      «      }|| j	                  |«      z   }| j                  |«      S )zÕPerform forward pass through the Feed-Forward Network part of the layer.

        Args:
            tgt (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor after FFN.
        )r  r  r/   r  r	  r
  )r1   ÚtgtÚtgt2s      r6   Úforward_ffnz-DeformableTransformerDecoderLayer.forward_ffnŒ  sN   € ð �|‰|˜DŸM™M¨$¯(©(°4·<±<ÀÓ3DÓ*EÓFÓGˆØ�D—M‘M $Ó'Ñ'ˆØ�z‰z˜#‹Ðr7   c                óø  — | j                  ||«      x}}	| j                  |j                  dd«      |	j                  dd«      |j                  dd«      |¬«      d   j                  dd«      }
|| j                  |
«      z   }| j	                  |«      }| j                  | j                  ||«      |j                  d«      |||«      }
|| j                  |
«      z   }| j                  |«      }| j                  |«      S )a?  Perform the forward pass through the entire decoder layer.

        Args:
            embed (torch.Tensor): Input embeddings.
            refer_bbox (torch.Tensor): Reference bounding boxes.
            feats (torch.Tensor): Feature maps.
            shapes (list): Feature shapes.
            padding_mask (torch.Tensor, optional): Padding mask.
            attn_mask (torch.Tensor, optional): Attention mask.
            query_pos (torch.Tensor, optional): Query position embeddings.

        Returns:
            (torch.Tensor): Output tensor after decoder layer.
        r   r   )rB   re   )
r=   r  Ú	transposer-   r*   r  Ú	unsqueezer.   r+   r  )r1   Úembedrö   ÚfeatsÚshapesÚpadding_maskrB   Ú	query_posrG   rH   r  s              r6   rN   z)DeformableTransformerDecoderLayer.forward™  sù   € ð2 ×#Ñ# E¨9Ó5Ð5ˆˆAØ�n‰n˜QŸ[™[¨¨AÓ.°·±¸A¸qÓ0AÀ5Ç?Á?ÐSTÐVWÓCXÐdmˆnÓnØñ
ç
‰)�A�q‹/ð 	ð ˜Ÿ™ cÓ*Ñ*ˆØ—
‘
˜5Ó!ˆð �o‰oØ×Ñ  yÓ1°:×3GÑ3GÈÓ3JÈEÐSYÐ[gó
ˆð ˜Ÿ™ cÓ*Ñ*ˆØ—
‘
˜5Ó!ˆð ×Ñ Ó&Ð&r7   )r×   rP   rÙ   rP   r  rP   r   rQ   r/   rR   rØ   rP   rÚ   rP   rU   )r  rV   rX   rV   rY   )r  rV   rö   rV   r  rV   r  r  r  rW   rB   rW   r  rW   rX   rV   )rZ   r[   r\   r]   r#   r¿   r    r_   r=   r  rN   r`   ra   s   @r6   r   r   E  sè   ø„ ñð4 ØØØØ ˜Ÿ™›ØØð'+àð'+ð ð'+ð ð	'+ð
 ð'+ð ð'+ð ð'+ð õ'+ðR ò7ó ð7óð& -1Ø)-Ø)-ð('àð('ð !ð('ð ð	('ð
 ð('ð *ð('ð 'ð('ð 'ð('ð 
÷('r7   r   c                  óV   ‡ — e Zd ZdZddˆ fd„Z	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zˆ xZS )r   aq  Deformable Transformer Decoder based on PaddleDetection implementation.

    This class implements a complete deformable transformer decoder with multiple decoder layers and prediction heads
    for bounding box regression and classification.

    Attributes:
        layers (nn.ModuleList): List of decoder layers.
        num_layers (int): Number of decoder layers.
        hidden_dim (int): Hidden dimension.
        eval_idx (int): Index of the layer to use during evaluation.

    References:
        https://github.com/PaddlePaddle/PaddleDetection/blob/develop/ppdet/modeling/transformers/deformable_transformer.py
    c                óŽ   •— t         ‰| �  «        t        ||«      | _        || _        || _        |dk\  r|| _        y||z   | _        y)aL  Initialize the DeformableTransformerDecoder with the given parameters.

        Args:
            hidden_dim (int): Hidden dimension.
            decoder_layer (nn.Module): Decoder layer module.
            num_layers (int): Number of decoder layers.
            eval_idx (int): Index of the layer to use during evaluation.
        r   N)r   r    r	   r±   rŸ   rº   Úeval_idx)r1   rº   Údecoder_layerrŸ   r  r5   s        €r6   r    z%DeformableTransformerDecoder.__init__Ô  sD   ø€ ô 	‰ÑÔÜ! -°Ó<ˆŒØ$ˆŒØ$ˆŒØ$,°¢M˜ˆ�°zÀHÑ7Lˆ�r7   c
                óØ  — |}
g }g }d}|j                  «       }t        | j                  «      D �]  \  }} ||
||||	| ||«      «      }
 ||   |
«      }t        j                   |t	        |«      z   «      }| j
                  rb|j                   ||   |
«      «       |dk(  r|j                  |«       nm|j                  t        j                   |t	        |«      z   «      «       n<|| j                  k(  r-|j                   ||   |
«      «       |j                  |«        n#|}| j
                  r|j                  «       n|}�Œ t        j                  |«      t        j                  |«      fS )aà  Perform the forward pass through the entire decoder.

        Args:
            embed (torch.Tensor): Decoder embeddings.
            refer_bbox (torch.Tensor): Reference bounding boxes.
            feats (torch.Tensor): Image features.
            shapes (list): Feature shapes.
            bbox_head (nn.Module): Bounding box prediction head.
            score_head (nn.Module): Score prediction head.
            pos_mlp (nn.Module): Position MLP.
            attn_mask (torch.Tensor, optional): Attention mask.
            padding_mask (torch.Tensor, optional): Padding mask.

        Returns:
            dec_bboxes (torch.Tensor): Decoded bounding boxes.
            dec_cls (torch.Tensor): Decoded classification scores.
        Nr   )
r²   r½   r±   r{   r
   ÚtrainingÚappendr  Údetachrå   )r1   r  rö   r  r  Ú	bbox_headÚ
score_headÚpos_mlprB   r  r   Ú
dec_bboxesÚdec_clsÚlast_refined_bboxrÁ   rÂ   ÚbboxÚrefined_bboxs                     r6   rN   z$DeformableTransformerDecoder.forwardã  sN  € ð: ˆØˆ
ØˆØ ÐØ×'Ñ'Ó)ˆ
Ü! $§+¡+Ó.ó 	R‰HˆAˆuÙ˜6 :¨u°f¸lÈIÑW^Ð_iÓWjÓkˆFà�9˜Q‘< Ó'ˆDÜ Ÿ=™=¨´À
Ó0KÑ)KÓLˆLà�}Š}Ø—‘˜}˜z¨!™}¨VÓ4Ô5Ø˜’6Ø×%Ñ% lÕ3à×%Ñ%¤e§m¡m°D¼?ÐK\Ó;]Ñ4]Ó&^Õ_Ø�d—m‘mÒ#Ø—‘˜}˜z¨!™}¨VÓ4Ô5Ø×!Ñ! ,Ô/Ùà ,ÐØ26·-²-˜×,Ñ,Ô.À\ŠJð%	Rô( �{‰{˜:Ó&¬¯©°GÓ(<Ð<Ð<r7   )rh   )rº   rP   r  rR   rŸ   rP   r  rP   )NN)r  rV   rö   rV   r  rV   r  r  r!  rR   r"  rR   r#  rR   rB   rW   r  rW   r’   ra   s   @r6   r   r   Ä  ss   ø„ ñöMð0 *.Ø,0ð6=àð6=ð !ð6=ð ð	6=ð
 ð6=ð ð6=ð ð6=ð ð6=ð 'ð6=ð *÷6=r7   r   )!r]   Ú
__future__r   rã   r{   Útorch.nnr#   Útorch.nn.functionalÚ
functionalrñ   Útorch.nn.initr   r   Úultralytics.utils.torch_utilsr   rš   r   Úutilsr	   r
   r   Ú__all__r¶   r   r   r   r   r   r   r   r   r   r   r9   r7   r6   ú<module>r1     sê   ðá å "ã ã Ý ß Ð ß 4å 4å ß TÑ Tð€ôHK˜bŸi™iô HKôVElÐ"ô ElôP)�r—y‘yô )ô>+V�r—y‘yô +Vô\1ˆr�y‰yô 1ô8@Eˆ"�)‰)ô @EôF(I�"—)‘)ô (IôVx(�2—9‘9ô x(ôv|'¨¯	©	ô |'ô~U= 2§9¡9õ U=r7   