Ë
    Fêñi�$ ã                  óŠ  — d Z ddlmZ ddlZddlmZ ddlmc mZ ddl	m
Z
 ddlmZmZmZmZmZmZ ddlmZ d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 G d„ dej*                  «      Z G d„ dej*                  «      Z G d„ de«      Z  G d„ d ej*                  «      Z! G d!„ d"e«      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/„ d0ej*                  «      Z) G d1„ d2ej*                  «      Z* G d3„ d4ej*                  «      Z+ G d5„ d6ej*                  «      Z, G d7„ d8ej*                  «      Z- G d9„ d:e%«      Z. G d;„ d<e«      Z/ G d=„ d>ej*                  «      Z0 G d?„ d@e0«      Z1 G dA„ dBej*                  «      Z2 G dC„ dDej*                  «      Z3 G dE„ dFej*                  «      Z4 G dG„ dHej*                  «      Z5 G dI„ dJej*                  «      Z6 G dK„ dLej*                  «      Z7 G dM„ dNe«      Z8 G dO„ dPe«      Z9 G dQ„ dRej
                  j*                  «      Z: G dS„ dTej*                  «      Z; G dU„ dVe«      Z< G dW„ dXej*                  «      Z= G dY„ dZej*                  «      Z> G d[„ d\ej*                  «      Z? G d]„ d^ej*                  «      Z@ G d_„ d`e«      ZA G da„ dbej*                  «      ZB G dc„ ddej*                  «      ZC G de„ dfej*                  «      ZD G dg„ dhej*                  «      ZE G di„ djej*                  «      ZF G dk„ dlej*                  «      ZG G dm„ dnej*                  «      ZH G do„ dpej*                  «      ZI G dq„ dre«      ZJ G ds„ dtej*                  «      ZKy)uzBlock modules.é    )ÚannotationsN)Úfuse_conv_and_bné   )ÚConvÚDWConvÚ	GhostConvÚ	LightConvÚRepConvÚautopad)ÚTransformerBlock)'ÚC1ÚC2ÚC2PSAÚC3ÚC3TRÚCIBÚDFLÚELAN1ÚPSAÚSPPÚSPPELANÚSPPFÚAConvÚADownÚ	AttentionÚBNContrastiveHeadÚ
BottleneckÚBottleneckCSPÚC2fÚC2fAttnÚC2fCIBÚC2fPSAÚC3GhostÚC3k2ÚC3xÚCBFuseÚCBLinearÚContrastiveHeadÚGhostBottleneckÚHGBlockÚHGStemÚImagePoolingAttnÚProtoÚRepC3ÚRepNCSPELAN4ÚRepVGGDWÚResNetLayerÚSCDownÚTorchVisionc                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   z‹Integral module of Distribution Focal Loss (DFL).

    Proposed in Generalized Focal Loss https://ieeexplore.ieee.org/document/9792391
    c                ód  •— t         ‰| �  «        t        j                  |ddd¬«      j	                  d«      | _        t        j                  |t        j                  ¬«      }t        j                  |j                  d|dd«      «      | j
                  j                  j                  dd || _        y)z�Initialize a convolutional layer with a given number of input channels.

        Args:
            c1 (int): Number of input channels.
        r   F©Úbias©ÚdtypeN)ÚsuperÚ__init__ÚnnÚConv2dÚrequires_grad_ÚconvÚtorchÚarangeÚfloatÚ	ParameterÚviewÚweightÚdataÚc1)ÚselfrG   ÚxÚ	__class__s      €ú^/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/ultralytics/nn/modules/block.pyr;   zDFL.__init__@   s~   ø€ ô 	‰ÑÔÜ—I‘I˜b ! Q¨UÔ3×BÑBÀ5ÓIˆŒ	Ü�L‰L˜¤5§;¡;Ô/ˆÜ#%§<¡<°·±°q¸"¸aÀÓ0CÓ#Dˆ�	‰	×Ñ×Ñ™aÐ Øˆ�ó    c                óÜ   — |j                   \  }}}| j                  |j                  |d| j                  |«      j	                  dd«      j                  d«      «      j                  |d|«      S )zCApply the DFL module to input tensor and return transformed output.é   é   r   )Úshaper?   rD   rG   Ú	transposeÚsoftmax)rH   rI   ÚbÚ_Úas        rK   ÚforwardzDFL.forwardL   s]   € à—'‘'‰ˆˆ1ˆaØ�y‰y˜Ÿ™  1 d§g¡g¨qÓ1×;Ñ;¸A¸qÓA×IÑIÈ!ÓLÓM×RÑRÐSTÐVWÐYZÓ[Ð[rL   )é   )rG   Úint©rI   útorch.TensorÚreturnrZ   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r;   rV   Ú__classcell__©rJ   s   @rK   r   r   :   s   ø„ ñö

÷\rL   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r-   zBUltralytics YOLO models mask Proto module for segmentation models.c                óÐ   •— t         ‰| �  «        t        ||d¬«      | _        t	        j
                  ||dddd¬«      | _        t        ||d¬«      | _        t        ||«      | _        y)a  Initialize the Ultralytics YOLO models mask Proto module with specified number of protos and masks.

        Args:
            c1 (int): Input channels.
            c_ (int): Intermediate channels.
            c2 (int): Output channels (number of protos).
        é   ©ÚkrO   r   Tr6   N)	r:   r;   r   Úcv1r<   ÚConvTranspose2dÚupsampleÚcv2Úcv3)rH   rG   Úc_Úc2rJ   s       €rK   r;   zProto.__init__V   sY   ø€ ô 	‰ÑÔÜ˜˜B !Ô$ˆŒÜ×*Ñ*¨2¨r°1°a¸ÀÔFˆŒÜ˜˜B !Ô$ˆŒÜ˜˜B“<ˆ�rL   c           	     ó~   — | j                  | j                  | j                  | j                  |«      «      «      «      S )zEPerform a forward pass through layers using an upsampled input image.)rl   rk   rj   rh   ©rH   rI   s     rK   rV   zProto.forwardd   s+   € à�x‰x˜Ÿ™ §¡¨t¯x©x¸«{Ó!;Ó<Ó=Ð=rL   )é   é    )rG   rX   rm   rX   rn   rX   rY   r\   rb   s   @rK   r-   r-   S   s   ø„ ÙLö ÷>rL   r-   c                  ó,   ‡ — e Zd ZdZdˆ fd„Zdd„Zˆ xZS )r+   z©StemBlock of PPHGNetV2 with 5 convolutions and one maxpool2d.

    https://github.com/PaddlePaddle/PaddleDetection/blob/develop/ppdet/modeling/backbones/hgnet_v2.py
    c           	     óú  •— t         ‰| �  «        t        ||ddt        j                  «       ¬«      | _        t        ||dz  dddt        j                  «       ¬«      | _        t        |dz  |dddt        j                  «       ¬«      | _        t        |dz  |ddt        j                  «       ¬«      | _        t        ||ddt        j                  «       ¬«      | _	        t        j                  dddd¬«      | _        y)	z²Initialize the StemBlock of PPHGNetV2.

        Args:
            c1 (int): Input channels.
            cm (int): Middle channels.
            c2 (int): Output channels.
        re   rO   ©Úactr   r   T)Úkernel_sizeÚstrideÚpaddingÚ	ceil_modeN)r:   r;   r   r<   ÚReLUÚstem1Ústem2aÚstem2bÚstem3Ústem4Ú	MaxPool2dÚpool)rH   rG   Úcmrn   rJ   s       €rK   r;   zHGStem.__init__o   s¸   ø€ ô 	‰ÑÔÜ˜"˜b ! Q¬B¯G©G«IÔ6ˆŒ
Ü˜2˜r Q™w¨¨1¨a´R·W±W³YÔ?ˆŒÜ˜2 ™7 B¨¨1¨a´R·W±W³YÔ?ˆŒÜ˜"˜q™& " a¨´·±³	Ô:ˆŒ
Ü˜"˜b ! Q¬B¯G©G«IÔ6ˆŒ
Ü—L‘L¨Q°qÀ!ÈtÔTˆ�	rL   c                ód  — | j                  |«      }t        j                  |g d¢«      }| j                  |«      }t        j                  |g d¢«      }| j	                  |«      }| j                  |«      }t        j                  ||gd¬«      }| j                  |«      }| j                  |«      }|S )ú+Forward pass of a PPHGNetV2 backbone layer.)r   r   r   r   r   ©Údim)
r|   ÚFÚpadr}   r~   r‚   r@   Úcatr   r€   )rH   rI   Úx2Úx1s       rK   rV   zHGStem.forward   s‰   € à�J‰J�q‹MˆÜ�E‰E�!’\Ó"ˆØ�[‰[˜‹^ˆÜ�U‰U�2’|Ó$ˆØ�[‰[˜‹_ˆØ�Y‰Y�q‹\ˆÜ�I‰I�r˜2�h AÔ&ˆØ�J‰J�q‹MˆØ�J‰J�q‹MˆØˆrL   )rG   rX   rƒ   rX   rn   rX   rY   r\   rb   s   @rK   r+   r+   i   s   ø„ ñõ
U÷ rL   r+   c                  ót   ‡ — e Zd ZdZdddd ej
                  «       f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Zˆ xZS )	r*   z¤HG_Block of PPHGNetV2 with 2 convolutions and LightConv.

    https://github.com/PaddlePaddle/PaddleDetection/blob/develop/ppdet/modeling/backbones/hgnet_v2.py
    re   é   Fc	                ó0  •‡‡‡‡‡	— t         ‰
| �  «        |rt        nt        Š	t	        j
                  ˆˆ	ˆˆˆfd„t        |«      D «       «      | _        t        ‰|‰z  z   |dz  dd‰¬«      | _        t        |dz  |dd‰¬«      | _	        |xr ‰|k(  | _
        y)a¿  Initialize HGBlock with specified parameters.

        Args:
            c1 (int): Input channels.
            cm (int): Middle channels.
            c2 (int): Output channels.
            k (int): Kernel size.
            n (int): Number of LightConv or Conv blocks.
            lightconv (bool): Whether to use LightConv.
            shortcut (bool): Whether to use shortcut connection.
            act (nn.Module): Activation function.
        c              3  óD   •K  — | ]  } ‰|d k(  r‰n‰‰‰‰¬«      –— Œ y­w)r   ©rg   rv   N© )Ú.0Úirv   ÚblockrG   rƒ   rg   s     €€€€€rK   ú	<genexpr>z#HGBlock.__init__.<locals>.<genexpr>¬   s(   øè ø€ Ò_ÐQR™u¨1°ª6¡R°r¸2ÀÈ×LÐLÑ_ùó   ƒ rO   r   ru   N)r:   r;   r	   r   r<   Ú
ModuleListÚrangeÚmÚscÚecÚadd)rH   rG   rƒ   rn   rg   ÚnÚ	lightconvÚshortcutrv   r•   rJ   s    `` `   `@€rK   r;   zHGBlock.__init__“   s~   ý€ ô. 	‰ÑÔÙ&•	¬DˆÜ—‘×_ÔV[Ð\]ÓV^Ô_Ó_ˆŒÜ�r˜A ™F‘{ B¨!¡G¨Q°°sÔ;ˆŒÜ�r˜Q‘w  A q¨cÔ2ˆŒØÒ(  b¡ˆ�rL   c                óà   ‡— |gŠ‰j                  ˆfd„| j                  D «       «       | j                  | j                  t	        j
                  ‰d«      «      «      Š| j                  r‰|z   S ‰S )r…   c              3  ó4   •K  — | ]  } |‰d    «      –— Œ y­w©éÿÿÿÿNr’   ©r“   rš   Úys     €rK   r–   z"HGBlock.forward.<locals>.<genexpr>´   ó   øè ø€ Ò*˜a‘�1�R‘5—Ñ*ùó   ƒr   )Úextendrš   rœ   r›   r@   rŠ   r�   ©rH   rI   r¦   s     @rK   rV   zHGBlock.forward±   sV   ø€ àˆCˆØ	�‰Ó* 4§6¡6Ô*Ô*Ø�G‰G�D—G‘GœEŸI™I a¨›OÓ,Ó-ˆØŸšˆq�1‰uÐ' aÐ'rL   )rG   rX   rƒ   rX   rn   rX   rg   rX   rž   rX   rŸ   Úboolr    r«   rv   ú	nn.ModulerY   )	r]   r^   r_   r`   r<   r{   r;   rV   ra   rb   s   @rK   r*   r*   �   sy   ø„ ñð ØØØØ ˜Ÿ™›ð)àð)ð ð)ð ð	)ð
 ð)ð ð)ð ð)ð ð)ð õ)÷<(rL   r*   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   zDSpatial Pyramid Pooling (SPP) layer https://arxiv.org/abs/1406.4729.c                ó"  •— t         ‰| �  «        |dz  }t        ||dd«      | _        t        |t	        |«      dz   z  |dd«      | _        t        j                  |D �cg c]  }t        j                  |d|dz  ¬«      ‘Œ c}«      | _	        yc c}w )zçInitialize the SPP layer with input/output channels and pooling kernel sizes.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            k (tuple): Kernel sizes for max pooling.
        rO   r   ©rw   rx   ry   N)
r:   r;   r   rh   Úlenrk   r<   r˜   r�   rš   )rH   rG   rn   rg   rm   rI   rJ   s         €rK   r;   zSPP.__init__¼   s|   ø€ ô 	‰ÑÔØ�1‰WˆÜ˜˜B  1Ó%ˆŒÜ˜œc !›f q™jÑ)¨2¨q°!Ó4ˆŒÜ—‘Ð_`ÖaÐZ[¤§¡¸À1ÈaÐSTÉfÖ UÒaÓbˆ�ùÒas   Á"Bc                ó¼   — | j                  |«      }| j                  t        j                  |g| j                  D �cg c]
  } ||«      ‘Œ c}z   d«      «      S c c}w )zBForward pass of the SPP layer, performing spatial pyramid pooling.r   )rh   rk   r@   rŠ   rš   )rH   rI   rš   s      rK   rV   zSPP.forwardÊ   sF   € à�H‰H�Q‹KˆØ�x‰xœŸ	™	 1 #°t·v±vÖ(>°!©¨1­Ò(>Ñ">ÀÓBÓCÐCùÒ(>s   ¼A))é   é	   é   )rG   rX   rn   rX   rg   útuple[int, ...]rY   r\   rb   s   @rK   r   r   ¹   s   ø„ ÙNöc÷DrL   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   zGSpatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher.c                óò   •— t         ‰| �  «        |dz  }t        ||ddd¬«      | _        t        ||dz   z  |dd«      | _        t        j                  |d|dz  ¬«      | _        || _        |xr ||k(  | _	        y)a’  Initialize the SPPF layer with given input/output channels and kernel size.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            k (int): Kernel size.
            n (int): Number of pooling iterations.
            shortcut (bool): Whether to use shortcut connection.

        Notes:
            This module is equivalent to SPP(k=(5, 9, 13)).
        rO   r   Fru   r¯   N)
r:   r;   r   rh   rk   r<   r�   rš   rž   r�   )rH   rG   rn   rg   rž   r    rm   rJ   s          €rK   r;   zSPPF.__init__Ó   sv   ø€ ô 	‰ÑÔØ�1‰WˆÜ˜˜B  1¨%Ô0ˆŒÜ˜˜a !™e™ b¨!¨QÓ/ˆŒÜ—‘¨!°A¸qÀA¹vÔFˆŒØˆŒØÒ(  b¡ˆ�rL   c           
     óú   ‡ ‡— ‰ j                  |«      gŠ‰j                  ˆ ˆfd„t        t        ‰ dd«      «      D «       «       ‰ j	                  t        j                  ‰d«      «      Št        ‰ dd«      r‰|z   S ‰S )zRApply sequential pooling operations to input and return concatenated feature maps.c              3  óF   •K  — | ]  }‰j                  ‰d    «      –— Œ y­wr£   ©rš   )r“   rT   rH   r¦   s     €€rK   r–   zSPPF.forward.<locals>.<genexpr>ë   s   øè ø€ ÒE 1�—‘˜˜"™—ÑEùs   ƒ!rž   re   r   r�   F)rh   r©   r™   Úgetattrrk   r@   rŠ   rª   s   ` @rK   rV   zSPPF.forwardè   sd   ù€ à�X‰X�a‹[ˆMˆØ	�‰ÔE¬¬g°d¸CÀÓ.CÓ(DÔEÔEØ�H‰H”U—Y‘Y˜q !“_Ó%ˆÜ  e¨UÔ3ˆq�1‰uÐ:¸Ð:rL   )r²   re   F)
rG   rX   rn   rX   rg   rX   rž   rX   r    r«   rY   r\   rb   s   @rK   r   r   Ð   s   ø„ ÙQö)÷*;rL   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   z"CSP Bottleneck with 1 convolution.c                óœ   •‡— t         ‰| �  «        t        |‰dd«      | _        t	        j
                  ˆfd„t        |«      D «       Ž | _        y)zÃInitialize the CSP Bottleneck with 1 convolution.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of convolutions.
        r   c              3  ó8   •K  — | ]  }t        ‰‰d «      –— Œ y­w)re   N©r   )r“   rT   rn   s     €rK   r–   zC1.__init__.<locals>.<genexpr>ý   s   øè ø€ Ò C°Q¤ b¨"¨a§Ñ Cùs   ƒN)r:   r;   r   rh   r<   Ú
Sequentialr™   rš   )rH   rG   rn   rž   rJ   s     ` €rK   r;   zC1.__init__ó   s<   ù€ ô 	‰ÑÔÜ˜˜B  1Ó%ˆŒÜ—‘Ó C¼%À»(Ô CÐDˆ�rL   c                óL   — | j                  |«      }| j                  |«      |z   S )z:Apply convolution and residual connection to input tensor.)rh   rš   rª   s      rK   rV   z
C1.forwardÿ   s!   € à�H‰H�Q‹KˆØ�v‰v�a‹y˜1‰}ÐrL   ©r   )rG   rX   rn   rX   rž   rX   rY   r\   rb   s   @rK   r   r   ð   s   ø„ Ù,ö
E÷rL   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   z#CSP Bottleneck with 2 convolutions.c                ó"  •‡ ‡‡— t         ‰‰ �  «        t        ||z  «      ‰ _        t	        |d‰ j                  z  dd«      ‰ _        t	        d‰ j                  z  |d«      ‰ _        t        j                  ˆˆ ˆfd„t        |«      D «       Ž ‰ _
        y)a_  Initialize a CSP Bottleneck with 2 convolutions.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of Bottleneck blocks.
            shortcut (bool): Whether to use shortcut connections.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
        rO   r   c           	   3  óh   •K  — | ])  }t        ‰j                  ‰j                  ‰‰d d¬«      –— Œ+ y­w©)©re   re   rÇ   ç      ð?©rg   ÚeN©r   Úc©r“   rT   ÚgrH   r    s     €€€rK   r–   zC2.__init__.<locals>.<genexpr>  s.   øè ø€ Ò vÐhi¤¨D¯F©F°D·F±F¸HÀaÐK[Ð_b×!cÐ!cÑ vùó   ƒ/2N©r:   r;   rX   rÌ   r   rh   rk   r<   rÀ   r™   rš   ©rH   rG   rn   rž   r    rÎ   rÊ   rJ   s   `   `` €rK   r;   zC2.__init__  sn   û€ ô 	‰ÑÔÜ�R˜!‘V“ˆŒÜ˜˜A §¡™J¨¨1Ó-ˆŒÜ˜˜DŸF™F™
 B¨Ó*ˆŒä—‘Õ vÔmrÐstÓmuÔ vÐwˆ�rL   c                ó¶   — | j                  |«      j                  dd«      \  }}| j                  t        j                  | j                  |«      |fd«      «      S )z<Forward pass through the CSP bottleneck with 2 convolutions.rO   r   )rh   Úchunkrk   r@   rŠ   rš   ©rH   rI   rU   rS   s       rK   rV   z
C2.forward  sF   € à�x‰x˜‹{× Ñ   AÓ&‰ˆˆ1Ø�x‰xœŸ	™	 4§6¡6¨!£9¨a .°!Ó4Ó5Ð5rL   ©r   Tr   ç      à?©rG   rX   rn   rX   rž   rX   r    r«   rÎ   rX   rÊ   rB   rY   r\   rb   s   @rK   r   r     s   ø„ Ù-öx÷$6rL   r   c                  ó6   ‡ — e Zd ZdZddˆ fd„Zdd„Zdd„Zˆ xZS )r   ú<Faster Implementation of CSP Bottleneck with 2 convolutions.c                ó.  •‡ ‡‡— t         ‰‰ �  «        t        ||z  «      ‰ _        t	        |d‰ j                  z  dd«      ‰ _        t	        d|z   ‰ j                  z  |d«      ‰ _        t        j                  ˆˆ ˆfd„t        |«      D «       «      ‰ _
        y)a_  Initialize a CSP bottleneck with 2 convolutions.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of Bottleneck blocks.
            shortcut (bool): Whether to use shortcut connections.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
        rO   r   c           	   3  óh   •K  — | ])  }t        ‰j                  ‰j                  ‰‰d d¬«      –— Œ+ y­wrÆ   rË   rÍ   s     €€€rK   r–   zC2f.__init__.<locals>.<genexpr>2  ó.   øè ø€ ÒtÐfgœz¨$¯&©&°$·&±&¸(ÀAÐIYÐ]`×aÐaÑtùrÏ   N)r:   r;   rX   rÌ   r   rh   rk   r<   r˜   r™   rš   rÑ   s   `   `` €rK   r;   zC2f.__init__#  ss   û€ ô 	‰ÑÔÜ�R˜!‘V“ˆŒÜ˜˜A §¡™J¨¨1Ó-ˆŒÜ˜˜Q™ $§&¡&Ñ(¨"¨aÓ0ˆŒÜ—‘ÕtÔkpÐqrÓksÔtÓtˆ�rL   c                óê   ‡— t        | j                  |«      j                  dd«      «      Š‰j                  ˆfd„| j                  D «       «       | j                  t        j                  ‰d«      «      S )zForward pass through C2f layer.rO   r   c              3  ó4   •K  — | ]  } |‰d    «      –— Œ y­wr£   r’   r¥   s     €rK   r–   zC2f.forward.<locals>.<genexpr>7  r§   r¨   )Úlistrh   rÓ   r©   rš   rk   r@   rŠ   rª   s     @rK   rV   zC2f.forward4  sQ   ø€ ä�—‘˜!“×"Ñ" 1 aÓ(Ó)ˆØ	�‰Ó* 4§6¡6Ô*Ô*Ø�x‰xœŸ	™	 ! Q›Ó(Ð(rL   c                ó  ‡— | j                  |«      j                  | j                  | j                  fd«      Š‰d   ‰d   gŠ‰j                  ˆfd„| j                  D «       «       | j                  t        j                  ‰d«      «      S )ú.Forward pass using split() instead of chunk().r   r   c              3  ó4   •K  — | ]  } |‰d    «      –— Œ y­wr£   r’   r¥   s     €rK   r–   z$C2f.forward_split.<locals>.<genexpr>>  r§   r¨   )rh   ÚsplitrÌ   r©   rš   rk   r@   rŠ   rª   s     @rK   Úforward_splitzC2f.forward_split:  sj   ø€ à�H‰H�Q‹K×Ñ˜tŸv™v t§v¡vÐ.°Ó2ˆØˆq‰T�1�Q‘4ˆLˆØ	�‰Ó* 4§6¡6Ô*Ô*Ø�x‰xœŸ	™	 ! Q›Ó(Ð(rL   ©r   Fr   rÖ   r×   rY   ©r]   r^   r_   r`   r;   rV   rä   ra   rb   s   @rK   r   r      s   ø„ ÙFöuó")÷)rL   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   z#CSP Bottleneck with 3 convolutions.c                ó  •‡‡‡— t         ‰| �  «        t        ||z  «      Št        |‰dd«      | _        t        |‰dd«      | _        t        d‰z  |d«      | _        t        j                  ˆˆˆfd„t        |«      D «       Ž | _
        y)aa  Initialize the CSP Bottleneck with 3 convolutions.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of Bottleneck blocks.
            shortcut (bool): Whether to use shortcut connections.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
        r   rO   c           	   3  ó@   •K  — | ]  }t        ‰‰‰‰d d¬«      –— Œ y­w)))r   r   rÇ   rÈ   rÉ   N©r   ©r“   rT   rm   rÎ   r    s     €€€rK   r–   zC3.__init__.<locals>.<genexpr>U  s&   øè ø€ Ò nÐ`a¤¨B°°H¸aÐCSÐWZ×![Ð![Ñ nùó   ƒN)r:   r;   rX   r   rh   rk   rl   r<   rÀ   r™   rš   ©	rH   rG   rn   rž   r    rÎ   rÊ   rm   rJ   s	       `` @€rK   r;   zC3.__init__E  sr   û€ ô 	‰ÑÔÜ��a‘‹[ˆÜ˜˜B  1Ó%ˆŒÜ˜˜B  1Ó%ˆŒÜ˜˜B™  AÓ&ˆŒÜ—‘Õ nÔejÐklÓemÔ nÐoˆ�rL   c           	     óª   — | j                  t        j                  | j                  | j	                  |«      «      | j                  |«      fd«      «      S )z<Forward pass through the CSP bottleneck with 3 convolutions.r   )rl   r@   rŠ   rš   rh   rk   rp   s     rK   rV   z
C3.forwardW  s:   € à�x‰xœŸ	™	 4§6¡6¨$¯(©(°1«+Ó#6¸¿¹À»Ð"DÀaÓHÓIÐIrL   rÕ   r×   rY   r\   rb   s   @rK   r   r   B  s   ø„ Ù-öp÷$JrL   r   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )r%   z"C3 module with cross-convolutions.c                ó°   •‡ ‡‡— t         ‰‰ �  |||‰‰|«       t        ||z  «      ‰ _        t	        j
                  ˆˆ ˆfd„t        |«      D «       Ž ‰ _        y)a\  Initialize C3 module with cross-convolutions.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of Bottleneck blocks.
            shortcut (bool): Whether to use shortcut connections.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
        c           	   3  óh   •K  — | ])  }t        ‰j                  ‰j                  ‰‰d d¬«      –— Œ+ y­w)))r   re   ©re   r   r   rÉ   N)r   rm   rÍ   s     €€€rK   r–   zC3x.__init__.<locals>.<genexpr>l  s.   øè ø€ Ò vÐhi¤¨D¯G©G°T·W±W¸hÈÐM]Ðab×!cÐ!cÑ vùrÏ   N)r:   r;   rX   rm   r<   rÀ   r™   rš   rÑ   s   `   `` €rK   r;   zC3x.__init___  sH   û€ ô 	‰Ñ˜˜R  H¨a°Ô3Ü�b˜1‘f“+ˆŒÜ—‘Õ vÔmrÐstÓmuÔ vÐwˆ�rL   rÕ   r×   ©r]   r^   r_   r`   r;   ra   rb   s   @rK   r%   r%   \  s   ø„ Ù,÷xò xrL   r%   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r.   zRep C3.c           	     óh  •— t         ‰| �  «        t        ||z  «      }t        ||dd«      | _        t        ||dd«      | _        t        j                  t        |«      D �cg c]  }t        ||«      ‘Œ c}Ž | _
        ||k7  rt        ||dd«      | _        yt        j                  «       | _        yc c}w )zèInitialize RepC3 module with RepConv blocks.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of RepConv blocks.
            e (float): Expansion ratio.
        r   N)r:   r;   rX   r   rh   rk   r<   rÀ   r™   r
   rš   ÚIdentityrl   )rH   rG   rn   rž   rÊ   rm   rT   rJ   s          €rK   r;   zRepC3.__init__r  s�   ø€ ô 	‰ÑÔÜ��a‘‹[ˆÜ˜˜B  1Ó%ˆŒÜ˜˜B  1Ó%ˆŒÜ—‘¼%À»(Ö C°Q¤¨¨R¥Ò CÐDˆŒØ)+¨rª”4˜˜B  1Ó%ˆ�´r·{±{³}ˆ�ùò !Ds   Á B/c                ó„   — | j                  | j                  | j                  |«      «      | j                  |«      z   «      S )zForward pass of RepC3 module.)rl   rš   rh   rk   rp   s     rK   rV   zRepC3.forward‚  s/   € à�x‰x˜Ÿ™˜tŸx™x¨›{Ó+¨d¯h©h°q«kÑ9Ó:Ð:rL   )re   rÈ   ©rG   rX   rn   rX   rž   rX   rÊ   rB   rY   r\   rb   s   @rK   r.   r.   o  s   ø„ ÙöE÷ ;rL   r.   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )r   z"C3 module with TransformerBlock().c                óp   •— t         ‰| �  ||||||«       t        ||z  «      }t        ||d|«      | _        y)a[  Initialize C3 module with TransformerBlock.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of Transformer blocks.
            shortcut (bool): Whether to use shortcut connections.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
        rN   N)r:   r;   rX   r   rš   rí   s	           €rK   r;   zC3TR.__init__Š  s;   ø€ ô 	‰Ñ˜˜R  H¨a°Ô3Ü��a‘‹[ˆÜ! " b¨!¨QÓ/ˆ�rL   rÕ   r×   ró   rb   s   @rK   r   r   ‡  s   ø„ Ù,÷0ò 0rL   r   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )r#   z!C3 module with GhostBottleneck().c                óž   •‡— t         ‰| �  ||||||«       t        ||z  «      Št        j                  ˆfd„t        |«      D «       Ž | _        y)a_  Initialize C3 module with GhostBottleneck.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of Ghost bottleneck blocks.
            shortcut (bool): Whether to use shortcut connections.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
        c              3  ó6   •K  — | ]  }t        ‰‰«      –— Œ y ­w)N)r)   )r“   rT   rm   s     €rK   r–   z#C3Ghost.__init__.<locals>.<genexpr>ª  s   øè ø€ Ò K¸Q¤°°R×!8Ñ Kùs   ƒN©r:   r;   rX   r<   rÀ   r™   rš   rí   s	          @€rK   r;   zC3Ghost.__init__�  sC   ù€ ô 	‰Ñ˜˜R  H¨a°Ô3Ü��a‘‹[ˆÜ—‘Ó KÄ%ÈÃ(Ô KÐLˆ�rL   rÕ   r×   ró   rb   s   @rK   r#   r#   š  s   ø„ Ù+÷Mò MrL   r#   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r)   zGGhost Bottleneck https://github.com/huawei-noah/Efficient-AI-Backbones.c                ó’  •— t         ‰| �  «        |dz  }t        j                  t	        ||dd«      |dk(  rt        ||||d¬«      nt        j                  «       t	        ||ddd¬«      «      | _        |dk(  r8t        j                  t        ||||d¬«      t        ||ddd¬«      «      | _	        yt        j                  «       | _	        y)zÇInitialize Ghost Bottleneck module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            k (int): Kernel size.
            s (int): Stride.
        rO   r   Fru   N)
r:   r;   r<   rÀ   r   r   rö   r?   r   r    )rH   rG   rn   rg   Úsrm   rJ   s         €rK   r;   zGhostBottleneck.__init__°  s´   ø€ ô 	‰ÑÔØ�1‰WˆÜ—M‘MÜ�b˜"˜a Ó#Ø/0°AªvŒF�2�r˜1˜a UÕ+¼2¿;¹;»=Ü�b˜"˜a ¨Ô.ó
ˆŒ	ð ^_ÐbcÒ]cŒB�M‰Mœ&  R¨¨A°5Ô9¼4ÀÀBÈÈ1ÐRWÔ;XÓYð 	�Üik×itÑitÓivð 	�rL   c                óH   — | j                  |«      | j                  |«      z   S )z3Apply skip connection and addition to input tensor.)r?   r    rp   s     rK   rV   zGhostBottleneck.forwardÄ  s   € à�y‰y˜‹|˜dŸm™m¨AÓ.Ñ.Ð.rL   rò   ©rG   rX   rn   rX   rg   rX   r  rX   rY   r\   rb   s   @rK   r)   r)   ­  s   ø„ ÙQö
÷(/rL   r)   c                  óF   ‡ — e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Zˆ xZS )r   zStandard bottleneck.c                ó¶   •— t         ‰| �  «        t        ||z  «      }t        |||d   d«      | _        t        |||d   d|¬«      | _        |xr ||k(  | _        y)aZ  Initialize a standard bottleneck module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            shortcut (bool): Whether to use shortcut connection.
            g (int): Groups for convolutions.
            k (tuple): Kernel sizes for convolutions.
            e (float): Expansion ratio.
        r   r   ©rÎ   N)r:   r;   rX   r   rh   rk   r�   ©	rH   rG   rn   r    rÎ   rg   rÊ   rm   rJ   s	           €rK   r;   zBottleneck.__init__Ì  s[   ø€ ô 	‰ÑÔÜ��a‘‹[ˆÜ˜˜B  !¡ aÓ(ˆŒÜ˜˜B  !¡ a¨1Ô-ˆŒØÒ(  b¡ˆ�rL   c                ó    — | j                   r#|| j                  | j                  |«      «      z   S | j                  | j                  |«      «      S )z3Apply bottleneck with optional shortcut connection.)r�   rk   rh   rp   s     rK   rV   zBottleneck.forwardß  s:   € à,0¯HªHˆq�4—8‘8˜DŸH™H Q›KÓ(Ñ(ÐO¸$¿(¹(À4Ç8Á8ÈAÃ;Ó:OÐOrL   ©Tr   rÇ   rÖ   ©rG   rX   rn   rX   r    r«   rÎ   rX   rg   ztuple[int, int]rÊ   rB   rY   r\   rb   s   @rK   r   r   É  sH   ø„ Ùð loð)Øð)Øð)Ø*.ð)Ø:=ð)ØFUð)Øchõ)÷&PrL   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   zGCSP Bottleneck https://github.com/WongKinYiu/CrossStagePartialNetworks.c                óÔ  •‡‡‡— t         ‰| �  «        t        ||z  «      Št        |‰dd«      | _        t        j                  |‰ddd¬«      | _        t        j                  ‰‰ddd¬«      | _        t        d‰z  |dd«      | _	        t        j                  d‰z  «      | _        t        j                  «       | _        t        j                  ˆˆˆfd„t        |«      D «       Ž | _        y)aI  Initialize CSP Bottleneck.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of Bottleneck blocks.
            shortcut (bool): Whether to use shortcut connections.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
        r   Fr6   rO   c              3  ó>   •K  — | ]  }t        ‰‰‰‰d ¬«      –— Œ y­w©rÈ   ©rÊ   Nrê   rë   s     €€€rK   r–   z)BottleneckCSP.__init__.<locals>.<genexpr>ú  s!   øè ø€ Ò ZÈA¤¨B°°H¸aÀ3×!GÐ!GÑ Zùó   ƒN)r:   r;   rX   r   rh   r<   r=   rk   rl   Úcv4ÚBatchNorm2dÚbnÚSiLUrv   rÀ   r™   rš   rí   s	       `` @€rK   r;   zBottleneckCSP.__init__ç  s³   û€ ô 	‰ÑÔÜ��a‘‹[ˆÜ˜˜B  1Ó%ˆŒÜ—9‘9˜R  Q¨°Ô6ˆŒÜ—9‘9˜R  Q¨°Ô6ˆŒÜ˜˜B™  A qÓ)ˆŒÜ—.‘.  R¡Ó(ˆŒÜ—7‘7“9ˆŒÜ—‘Õ ZÔQVÐWXÓQYÔ ZÐ[ˆ�rL   c           
     ó  — | j                  | j                  | j                  |«      «      «      }| j                  |«      }| j	                  | j                  | j                  t        j                  ||fd«      «      «      «      S )z)Apply CSP bottleneck with 4 convolutions.r   )	rl   rš   rh   rk   r  rv   r  r@   rŠ   )rH   rI   Úy1Úy2s       rK   rV   zBottleneckCSP.forwardü  s^   € à�X‰X�d—f‘f˜TŸX™X a›[Ó)Ó*ˆØ�X‰X�a‹[ˆØ�x‰x˜Ÿ™ §¡¬¯©°B¸°8¸QÓ)?Ó!@ÓAÓBÐBrL   rÕ   r×   rY   r\   rb   s   @rK   r   r   ä  s   ø„ ÙQö\÷*CrL   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )ÚResNetBlockz.ResNet block with standard convolution layers.c           	     óB  •— t         ‰| �  «        ||z  }t        ||ddd¬«      | _        t        ||d|dd¬«      | _        t        ||dd¬«      | _        |dk7  s||k7  r)t        j                  t        ||d|d¬«      «      | _	        yt        j                  «       | _	        y)	zÀInitialize ResNet block.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            s (int): Stride.
            e (int): Expansion ratio.
        r   T©rg   r  rv   re   ©rg   r  Úprv   Fr‘   N)
r:   r;   r   rh   rk   rl   r<   rÀ   rö   r    )rH   rG   rn   r  rÊ   Úc3rJ   s         €rK   r;   zResNetBlock.__init__  s’   ø€ ô 	‰ÑÔØ�‰VˆÜ˜˜B ! q¨dÔ3ˆŒÜ˜˜B ! q¨A°4Ô8ˆŒÜ˜˜B !¨Ô/ˆŒØLMÐQRÊFÐVXÐ\^ÒV^œŸ™¤d¨2¨r°Q¸!ÀÔ&GÓHˆ�Ôdf×doÑdoÓdqˆ�rL   c           	     óª   — t        j                  | j                  | j                  | j	                  |«      «      «      | j                  |«      z   «      S )z&Forward pass through the ResNet block.)rˆ   Úrelurl   rk   rh   r    rp   s     rK   rV   zResNetBlock.forward  s9   € ä�v‰v�d—h‘h˜tŸx™x¨¯©°«Ó4Ó5¸¿¹ÀaÓ8HÑHÓIÐIrL   )r   rN   )rG   rX   rn   rX   r  rX   rÊ   rX   rY   r\   rb   s   @rK   r  r    s   ø„ Ù8ör÷ JrL   r  c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r1   z)ResNet layer with multiple ResNet blocks.c                ó˜  •— t         ‰	| �  «        || _        | j                  rAt        j                  t        ||dddd¬«      t        j                  ddd¬«      «      | _        y	t        ||||¬«      g}|j                  t        |dz
  «      D �cg c]  }t        ||z  |d|¬«      ‘Œ c}«       t        j                  |Ž | _        y	c c}w )
a,  Initialize ResNet layer.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            s (int): Stride.
            is_first (bool): Whether this is the first layer.
            n (int): Number of ResNet blocks.
            e (int): Expansion ratio.
        é   rO   re   Tr  r   r¯   r  N)r:   r;   Úis_firstr<   rÀ   r   r�   Úlayerr  r©   r™   )
rH   rG   rn   r  r$  rž   rÊ   ÚblocksrT   rJ   s
            €rK   r;   zResNetLayer.__init__  s«   ø€ ô 	‰ÑÔØ ˆŒà�=Š=ÜŸ™Ü�R˜˜q A¨°Ô5´r·|±|ÐPQÐZ[ÐefÔ7góˆD�Jô " " b¨!¨qÔ1Ð2ˆFØ�M‰MÄEÈ!ÈaÉ%ÃLÖQ¸qœ; q¨2¡v¨r°1¸Ö:ÒQÔRÜŸ™¨Ð/ˆD�Jùò Rs   ÂCc                ó$   — | j                  |«      S )z&Forward pass through the ResNet layer.)r%  rp   s     rK   rV   zResNetLayer.forward5  s   € à�z‰z˜!‹}ÐrL   )r   Fr   rN   )rG   rX   rn   rX   r  rX   r$  r«   rž   rX   rÊ   rX   rY   r\   rb   s   @rK   r1   r1     s   ø„ Ù3ö0÷.rL   r1   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )ÚMaxSigmoidAttnBlockzMax Sigmoid attention block.c                ó¨  •— t         ‰| �  «        || _        ||z  | _        ||k7  rt	        ||dd¬«      nd| _        t        j                  ||«      | _        t        j                  t        j                  |«      «      | _        t	        ||ddd¬«      | _        |r1t        j                  t        j                  d|dd«      «      | _        yd| _        y)a?  Initialize MaxSigmoidAttnBlock.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            nh (int): Number of heads.
            ec (int): Embedding channels.
            gc (int): Guide channels.
            scale (bool): Whether to use learnable scale parameter.
        r   Fr‘   Nre   r  rÈ   )r:   r;   ÚnhÚhcr   rœ   r<   ÚLinearÚglrC   r@   Úzerosr7   Ú	proj_convÚonesÚscale)rH   rG   rn   r+  rœ   Úgcr2  rJ   s          €rK   r;   zMaxSigmoidAttnBlock.__init__=  s¡   ø€ ô 	‰ÑÔØˆŒØ˜‘(ˆŒØ24¸²(”$�r˜2 ¨Õ.ÀˆŒÜ—)‘)˜B Ó#ˆŒÜ—L‘L¤§¡¨R£Ó1ˆŒ	Ü˜b "¨¨Q°EÔ:ˆŒÙ>C”R—\‘\¤%§*¡*¨Q°°A°qÓ"9Ó:ˆ�
Èˆ�
rL   c                óÖ  — |j                   \  }}}}| j                  |«      }|j                  ||j                   d   | j                  | j                  «      }| j
                  �| j                  |«      n|}|j                  || j                  | j                  ||«      }t        j                  d||«      }|j                  d¬«      d   }|| j                  dz  z  }|| j                  ddd…ddf   z   }|j                  «       | j                  z  }| j                  |«      }|j                  || j                  d||«      }||j                  d«      z  }|j                  |d||«      S )	zåForward pass of MaxSigmoidAttnBlock.

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

        Returns:
            (torch.Tensor): Output tensor after attention.
        r   Nzbmchw,bnmc->bmhwnr¤   r†   r   rÖ   rO   )rP   r.  rD   r+  r,  rœ   r@   ÚeinsumÚmaxr7   Úsigmoidr2  r0  Ú	unsqueeze)	rH   rI   ÚguideÚbsrT   ÚhÚwÚembedÚaws	            rK   rV   zMaxSigmoidAttnBlock.forwardQ  s4  € ð —g‘g‰ˆˆAˆq�!à—‘˜“ˆØ—
‘
˜2˜uŸ{™{¨1™~¨t¯w©w¸¿¹Ó@ˆØ"Ÿg™gÐ1�—‘˜”
°qˆØ—
‘
˜2˜tŸw™w¨¯©°°AÓ6ˆä�\‰\Ð-¨u°eÓ<ˆØ�V‰V˜ˆV‹^˜AÑˆØ�4—7‘7˜C‘<Ñ ˆØ�$—)‘)˜D¢! T¨4Ð/Ñ0Ñ0ˆØ�Z‰Z‹\˜DŸJ™JÑ&ˆà�N‰N˜1ÓˆØ�F‰F�2�t—w‘w  A qÓ)ˆØ�—‘˜Q“ÑˆØ�v‰v�b˜"˜a Ó#Ð#rL   )r   é€   é   F)rG   rX   rn   rX   r+  rX   rœ   rX   r3  rX   r2  r«   ©rI   rZ   r9  rZ   r[   rZ   r\   rb   s   @rK   r)  r)  :  s   ø„ Ù&öM÷($rL   r)  c                  óf   ‡ — e Zd ZdZ	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Zdd„Zˆ xZS )r    z*C2f module with an additional attn module.c
                ó€  •‡ ‡‡— t         ‰
‰ �  «        t        ||	z  «      ‰ _        t	        |d‰ j                  z  dd«      ‰ _        t	        d|z   ‰ j                  z  |d«      ‰ _        t        j                  ˆˆ ˆfd„t        |«      D «       «      ‰ _
        t        ‰ j                  ‰ j                  |||¬«      ‰ _        y)aÿ  Initialize C2f module with attention mechanism.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of Bottleneck blocks.
            ec (int): Embedding channels for attention.
            nh (int): Number of heads for attention.
            gc (int): Guide channels for attention.
            shortcut (bool): Whether to use shortcut connections.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
        rO   r   re   c           	   3  óh   •K  — | ])  }t        ‰j                  ‰j                  ‰‰d d¬«      –— Œ+ y­wrÆ   rË   rÍ   s     €€€rK   r–   z#C2fAttn.__init__.<locals>.<genexpr>Ž  rÜ   rÏ   )r3  rœ   r+  N)r:   r;   rX   rÌ   r   rh   rk   r<   r˜   r™   rš   r)  Úattn)rH   rG   rn   rž   rœ   r+  r3  r    rÎ   rÊ   rJ   s   `      `` €rK   r;   zC2fAttn.__init__q  s�   û€ ô2 	‰ÑÔÜ�R˜!‘V“ˆŒÜ˜˜A §¡™J¨¨1Ó-ˆŒÜ˜˜Q™ $§&¡&Ñ(¨"¨aÓ0ˆŒÜ—‘ÕtÔkpÐqrÓksÔtÓtˆŒÜ'¨¯©°·±¸2À"ÈÔLˆ�	rL   c                ó2  ‡— t        | j                  |«      j                  dd«      «      Š‰j                  ˆfd„| j                  D «       «       ‰j                  | j                  ‰d   |«      «       | j                  t        j                  ‰d«      «      S )zþForward pass through C2f layer with attention.

        Args:
            x (torch.Tensor): Input tensor.
            guide (torch.Tensor): Guide tensor for attention.

        Returns:
            (torch.Tensor): Output tensor after processing.
        rO   r   c              3  ó4   •K  — | ]  } |‰d    «      –— Œ y­wr£   r’   r¥   s     €rK   r–   z"C2fAttn.forward.<locals>.<genexpr>œ  r§   r¨   r¤   )
rß   rh   rÓ   r©   rš   ÚappendrE  rk   r@   rŠ   ©rH   rI   r9  r¦   s      @rK   rV   zC2fAttn.forward‘  sn   ø€ ô �—‘˜!“×"Ñ" 1 aÓ(Ó)ˆØ	�‰Ó* 4§6¡6Ô*Ô*Ø	�‰�—‘˜1˜R™5 %Ó(Ô)Ø�x‰xœŸ	™	 ! Q›Ó(Ð(rL   c                ó^  ‡— t        | j                  |«      j                  | j                  | j                  fd«      «      Š‰j	                  ˆfd„| j
                  D «       «       ‰j                  | j                  ‰d   |«      «       | j                  t        j                  ‰d«      «      S )zþForward pass using split() instead of chunk().

        Args:
            x (torch.Tensor): Input tensor.
            guide (torch.Tensor): Guide tensor for attention.

        Returns:
            (torch.Tensor): Output tensor after processing.
        r   c              3  ó4   •K  — | ]  } |‰d    «      –— Œ y­wr£   r’   r¥   s     €rK   r–   z(C2fAttn.forward_split.<locals>.<genexpr>«  r§   r¨   r¤   )rß   rh   rã   rÌ   r©   rš   rH  rE  rk   r@   rŠ   rI  s      @rK   rä   zC2fAttn.forward_split   s{   ø€ ô �—‘˜!“×"Ñ" D§F¡F¨D¯F©FÐ#3°QÓ7Ó8ˆØ	�‰Ó* 4§6¡6Ô*Ô*Ø	�‰�—‘˜1˜R™5 %Ó(Ô)Ø�x‰xœŸ	™	 ! Q›Ó(Ð(rL   )r   r?  r   r@  Fr   rÖ   )rG   rX   rn   rX   rž   rX   rœ   rX   r+  rX   r3  rX   r    r«   rÎ   rX   rÊ   rB   rA  ræ   rb   s   @rK   r    r    n  s�   ø„ Ù4ð ØØØØØØðMàðMð ðMð ð	Mð
 ðMð ðMð ðMð ðMð ðMð õMó@)÷)rL   r    c                  óF   ‡ — e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Zˆ xZS )r,   zKImagePoolingAttn: Enhance the text embeddings with image-aware information.c           
     óÊ  •— t         ‰
| �  «        t        |«      }t        j                  t        j
                  |«      t        j                  ||«      «      | _        t        j                  t        j
                  |«      t        j                  ||«      «      | _        t        j                  t        j
                  |«      t        j                  ||«      «      | _	        t        j                  ||«      | _
        |r+t        j                  t        j                  dg«      d¬«      nd| _        t        j                  |D �cg c]  }t        j                   ||d¬«      ‘Œ c}«      | _        t        j                  t%        |«      D �	cg c]  }	t        j&                  ||f«      ‘Œ c}	«      | _        || _        || _        || _        ||z  | _        || _        yc c}w c c}	w )a‚  Initialize ImagePoolingAttn module.

        Args:
            ec (int): Embedding channels.
            ch (tuple): Channel dimensions for feature maps.
            ct (int): Channel dimension for text embeddings.
            nh (int): Number of attention heads.
            k (int): Kernel size for pooling.
            scale (bool): Whether to use learnable scale parameter.
        g        T©Úrequires_gradrÈ   r   )rw   N)r:   r;   r°   r<   rÀ   Ú	LayerNormr-  ÚqueryÚkeyÚvalueÚprojrC   r@   Útensorr2  r˜   r=   Úprojectionsr™   ÚAdaptiveMaxPool2dÚim_poolsrœ   r+  Únfr,  rg   )rH   rœ   ÚchÚctr+  rg   r2  rY  Úin_channelsrT   rJ   s             €rK   r;   zImagePoolingAttn.__init__³  sJ  ø€ ô 	‰ÑÔä�‹WˆÜ—]‘]¤2§<¡<°Ó#3´R·Y±Y¸rÀ2Ó5FÓGˆŒ
Ü—=‘=¤§¡¨bÓ!1´2·9±9¸RÀÓ3DÓEˆŒÜ—]‘]¤2§<¡<°Ó#3´R·Y±Y¸rÀ2Ó5FÓGˆŒ
Ü—I‘I˜b "Ó%ˆŒ	ÙNS”R—\‘\¤%§,¡,°¨uÓ"5ÀTÕJÐY\ˆŒ
ÜŸ=™=ÐgiÖ)jÐXc¬"¯)©)°KÀÐQRÖ*SÒ)jÓkˆÔÜŸ™ÌUÐSUËYÖ&WÈ¤r×';Ñ';¸QÀ¸FÕ'CÒ&WÓXˆŒØˆŒØˆŒØˆŒØ˜‘(ˆŒØˆ�ùò *kùÚ&Ws   ÅGÆ
G c           
     óü  — |d   j                   d   }t        |«      | j                  k(  sJ ‚| j                  dz  }t	        || j
                  | j                  «      D ���cg c]%  \  }}} | ||«      «      j                  |d|«      ‘Œ' c}}}}t        j                  |d¬«      j                  dd«      }| j                  |«      }| j                  |«      }| j                  |«      }	|j                  |d| j                  | j                   «      }|j                  |d| j                  | j                   «      }|	j                  |d| j                  | j                   «      }	t        j"                  d||«      }
|
| j                   dz  z  }
t%        j&                  |
d¬«      }
t        j"                  d|
|	«      }| j)                  |j                  |d| j*                  «      «      }|| j,                  z  |z   S c c}}}w )	zóForward pass of ImagePoolingAttn.

        Args:
            x (list[torch.Tensor]): List of input feature maps.
            text (torch.Tensor): Text embeddings.

        Returns:
            (torch.Tensor): Enhanced text embeddings.
        r   rO   r¤   r†   r   zbnmc,bkmc->bmnkrÖ   zbmnk,bkmc->bnmc)rP   r°   rY  rg   ÚziprV  rX  rD   r@   rŠ   rQ   rQ  rR  rS  Úreshaper+  r,  r5  rˆ   rR   rT  rœ   r2  )rH   rI   Útextr:  Únum_patchesrT  r‚   Úqrg   Úvr>  s              rK   rV   zImagePoolingAttn.forwardÐ  s›  € ð ˆq‰T�Z‰Z˜‰]ˆÜ�1‹v˜Ÿ™Ò Ð Ð Ø—f‘f˜a‘iˆÜLOÐPQÐSW×ScÑScÐei×erÑerÓLs×tÐt¹¸!¸TÀ4‰T‘$�q“'‹]×Ñ  B¨Õ4ÔtˆÜ�I‰I�a˜RÔ ×*Ñ*¨1¨aÓ0ˆØ�J‰J�tÓˆØ�H‰H�Q‹KˆØ�J‰J�q‹Mˆð �I‰I�b˜"˜dŸg™g t§w¡wÓ/ˆØ�I‰I�b˜"˜dŸg™g t§w¡wÓ/ˆØ�I‰I�b˜"˜dŸg™g t§w¡wÓ/ˆä�\‰\Ð+¨Q°Ó2ˆØ�4—7‘7˜C‘<Ñ ˆÜ�Y‰Y�r˜rÔ"ˆä�L‰LÐ*¨B°Ó2ˆØ�I‰I�a—i‘i  B¨¯©Ó0Ó1ˆØ�4—:‘:‰~ Ñ$Ð$ùô# us   Á!*G7)rq   r’   r@  é   re   F)rœ   rX   rZ  rµ   r[  rX   r+  rX   rg   rX   r2  r«   )rI   úlist[torch.Tensor]r`  rZ   r[   rZ   r\   rb   s   @rK   r,   r,   °  sG   ø„ ÙUð nsðØðØ!0ðØ;>ðØJMðØVYðØfjõ÷:%rL   r,   c                  ó*   ‡ — e Zd ZdZˆ fd„Zdd„Zˆ xZS )r(   zZImplements contrastive learning head for region-text similarity in vision-language models.c                ó   •— t         ‰| �  «        t        j                  t	        j
                  dg«      «      | _        t        j                  t	        j                  g «      t	        j
                  d«      j                  «       z  «      | _	        y)zBInitialize ContrastiveHead with region-text similarity parameters.ç      $Àg$I’$I’,@N)
r:   r;   r<   rC   r@   rU  r7   r1  ÚlogÚlogit_scale)rH   rJ   s    €rK   r;   zContrastiveHead.__init__ô  sY   ø€ ä‰ÑÔä—L‘L¤§¡¨u¨gÓ!6Ó7ˆŒ	ÜŸ<™<¬¯
©
°2«¼¿¹ÀhÓ9O×9SÑ9SÓ9UÑ(UÓVˆÕrL   c                óä   — t        j                  |dd¬«      }t        j                  |dd¬«      }t        j                  d||«      }|| j                  j                  «       z  | j                  z   S )zÝForward function of contrastive learning.

        Args:
            x (torch.Tensor): Image features.
            w (torch.Tensor): Text features.

        Returns:
            (torch.Tensor): Similarity scores.
        r   rO   ©r‡   r  r¤   úbchw,bkc->bkhw)rˆ   Ú	normalizer@   r5  rj  Úexpr7   ©rH   rI   r<  s      rK   rV   zContrastiveHead.forwardû  s^   € ô �K‰K˜˜q AÔ&ˆÜ�K‰K˜˜r QÔ'ˆÜ�L‰LÐ)¨1¨aÓ0ˆØ�4×#Ñ#×'Ñ'Ó)Ñ)¨D¯I©IÑ5Ð5rL   ©rI   rZ   r<  rZ   r[   rZ   r\   rb   s   @rK   r(   r(   ñ  s   ø„ ÙdôW÷6rL   r(   c                  óD   ‡ — e Zd ZdZdˆ fd„Zd„ Zedd„«       Zdd„Zˆ xZ	S )r   z Batch Norm Contrastive Head using batch norm instead of l2-normalization.

    Args:
        embed_dims (int): Embed dimensions of text and image features.
    c                ó  •— t         ‰| �  «        t        j                  |«      | _        t        j
                  t        j                  dg«      «      | _        t        j
                  dt        j                  g «      z  «      | _
        y)zvInitialize BNContrastiveHead.

        Args:
            embed_dims (int): Embedding dimensions for features.
        rh  g      ð¿N)r:   r;   r<   r  ÚnormrC   r@   rU  r7   r1  rj  )rH   Ú
embed_dimsrJ   s     €rK   r;   zBNContrastiveHead.__init__  sY   ø€ ô 	‰ÑÔÜ—N‘N :Ó.ˆŒ	ä—L‘L¤§¡¨u¨gÓ!6Ó7ˆŒ	äŸ<™<¨¬u¯z©z¸"«~Ñ(=Ó>ˆÕrL   c                ó2   — | ` | `| `| j                  | _        y)zCFuse the batch normalization layer in the BNContrastiveHead module.N)rt  r7   rj  Úforward_fuserV   ©rH   s    rK   ÚfusezBNContrastiveHead.fuse  s   € àˆIØˆIØÐØ×(Ñ(ˆ�rL   c                ó   — | S )z5Passes image features through unchanged after fusing.r’   )rI   r<  s     rK   rw  zBNContrastiveHead.forward_fuse&  s	   € ð ˆrL   c                óÖ   — | j                  |«      }t        j                  |dd¬«      }t        j                  d||«      }|| j
                  j                  «       z  | j                  z   S )zöForward function of contrastive learning with batch normalization.

        Args:
            x (torch.Tensor): Image features.
            w (torch.Tensor): Text features.

        Returns:
            (torch.Tensor): Similarity scores.
        r¤   rO   rl  rm  )rt  rˆ   rn  r@   r5  rj  ro  r7   rp  s      rK   rV   zBNContrastiveHead.forward+  sY   € ð �I‰I�a‹LˆÜ�K‰K˜˜r QÔ'ˆä�L‰LÐ)¨1¨aÓ0ˆØ�4×#Ñ#×'Ñ'Ó)Ñ)¨D¯I©IÑ5Ð5rL   )ru  rX   rq  )
r]   r^   r_   r`   r;   ry  Ústaticmethodrw  rV   ra   rb   s   @rK   r   r     s+   ø„ ñõ?ò)ð òó ð÷6rL   r   c                  ó>   ‡ — e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zˆ xZS )ÚRepBottleneckzRep bottleneck.c                óv   •— t         ‰| �  ||||||«       t        ||z  «      }t        |||d   d«      | _        y)aK  Initialize RepBottleneck.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            shortcut (bool): Whether to use shortcut connection.
            g (int): Groups for convolutions.
            k (tuple): Kernel sizes for convolutions.
            e (float): Expansion ratio.
        r   r   N)r:   r;   rX   r
   rh   r  s	           €rK   r;   zRepBottleneck.__init__?  s?   ø€ ô 	‰Ñ˜˜R ¨1¨a°Ô3Ü��a‘‹[ˆÜ˜2˜r 1 Q¡4¨Ó+ˆ�rL   r	  r
  ró   rb   s   @rK   r~  r~  <  sG   ø„ Ùð loð,Øð,Øð,Ø*.ð,Ø:=ð,ØFUð,Øch÷,ñ ,rL   r~  c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )ÚRepCSPzXRepeatable Cross Stage Partial Network (RepCSP) module for efficient feature extraction.c                ó¦   •‡‡‡— t         ‰| �  |||‰‰|«       t        ||z  «      Št        j                  ˆˆˆfd„t        |«      D «       Ž | _        y)aJ  Initialize RepCSP layer.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of RepBottleneck blocks.
            shortcut (bool): Whether to use shortcut connections.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
        c              3  ó>   •K  — | ]  }t        ‰‰‰‰d ¬«      –— Œ y­wr  )r~  rë   s     €€€rK   r–   z"RepCSP.__init__.<locals>.<genexpr>a  s!   øè ø€ Ò ]Èq¤¨r°2°xÀÀc×!JÐ!JÑ ]ùr  Nrþ   rí   s	       `` @€rK   r;   zRepCSP.__init__T  sF   û€ ô 	‰Ñ˜˜R  H¨a°Ô3Ü��a‘‹[ˆÜ—‘Õ ]ÔTYÐZ[ÓT\Ô ]Ð^ˆ�rL   rÕ   r×   ró   rb   s   @rK   r�  r�  Q  s   ø„ Ùb÷_ò _rL   r�  c                  ó6   ‡ — e Zd ZdZddˆ fd„Zdd„Zdd„Zˆ xZS )r/   z	CSP-ELAN.c           	     ó\  •— t         ‰| �  «        |dz  | _        t        ||dd«      | _        t        j                  t        |dz  ||«      t        ||dd«      «      | _        t        j                  t        |||«      t        ||dd«      «      | _	        t        |d|z  z   |dd«      | _
        y)a  Initialize CSP-ELAN layer.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            c3 (int): Intermediate channels.
            c4 (int): Intermediate channels for RepCSP.
            n (int): Number of RepCSP blocks.
        rO   r   re   N)r:   r;   rÌ   r   rh   r<   rÀ   r�  rk   rl   r  )rH   rG   rn   r  Úc4rž   rJ   s         €rK   r;   zRepNCSPELAN4.__init__g  s—   ø€ ô 	‰ÑÔØ�q‘ˆŒÜ˜˜B  1Ó%ˆŒÜ—=‘=¤¨¨a©°°QÓ!7¼¸bÀ"ÀaÈÓ9KÓLˆŒÜ—=‘=¤¨¨B°Ó!2´D¸¸RÀÀAÓ4FÓGˆŒÜ˜˜a "™f™ r¨1¨aÓ0ˆ�rL   c                ó  ‡— t        | j                  |«      j                  dd«      «      Š‰j                  ˆfd„| j                  | j
                  fD «       «       | j                  t        j                  ‰d«      «      S )z(Forward pass through RepNCSPELAN4 layer.rO   r   c              3  ó4   •K  — | ]  } |‰d    «      –— Œ y­wr£   r’   r¥   s     €rK   r–   z'RepNCSPELAN4.forward.<locals>.<genexpr>{  s   øè ø€ Ò: ‘!�A�b‘E—(Ñ:ùr¨   )	rß   rh   rÓ   r©   rk   rl   r  r@   rŠ   rª   s     @rK   rV   zRepNCSPELAN4.forwardx  sZ   ø€ ä�—‘˜!“×"Ñ" 1 aÓ(Ó)ˆØ	�‰Ó: d§h¡h°·±Ð%9Ô:Ô:Ø�x‰xœŸ	™	 ! Q›Ó(Ð(rL   c                ó.  ‡— t        | j                  |«      j                  | j                  | j                  fd«      «      Š‰j	                  ˆfd„| j
                  | j                  fD «       «       | j                  t        j                  ‰d«      «      S )rá   r   c              3  ó4   •K  — | ]  } |‰d    «      –— Œ y­wr£   r’   r¥   s     €rK   r–   z-RepNCSPELAN4.forward_split.<locals>.<genexpr>�  s   øè ø€ Ò8˜a‘�1�R‘5—Ñ8ùr¨   )
rß   rh   rã   rÌ   r©   rk   rl   r  r@   rŠ   rª   s     @rK   rä   zRepNCSPELAN4.forward_split~  sg   ø€ ä�—‘˜!“×"Ñ" D§F¡F¨D¯F©FÐ#3°QÓ7Ó8ˆØ	�‰Ó8 D§H¡H¨d¯h©hÐ#7Ô8Ô8Ø�x‰xœŸ	™	 ! Q›Ó(Ð(rL   rÂ   )
rG   rX   rn   rX   r  rX   r†  rX   rž   rX   rY   ræ   rb   s   @rK   r/   r/   d  s   ø„ Ùö1ó")÷)rL   r/   c                  ó$   ‡ — e Zd ZdZdˆ fd„Zˆ xZS )r   z!ELAN1 module with 4 convolutions.c                óè   •— t         ‰| �  ||||«       |dz  | _        t        ||dd«      | _        t        |dz  |dd«      | _        t        ||dd«      | _        t        |d|z  z   |dd«      | _        y)zçInitialize ELAN1 layer.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            c3 (int): Intermediate channels.
            c4 (int): Intermediate channels for convolutions.
        rO   r   re   N)r:   r;   rÌ   r   rh   rk   rl   r  )rH   rG   rn   r  r†  rJ   s        €rK   r;   zELAN1.__init__ˆ  sw   ø€ ô 	‰Ñ˜˜R  RÔ(Ø�q‘ˆŒÜ˜˜B  1Ó%ˆŒÜ˜˜a™  Q¨Ó*ˆŒÜ˜˜B  1Ó%ˆŒÜ˜˜a "™f™ r¨1¨aÓ0ˆ�rL   )rG   rX   rn   rX   r  rX   r†  rX   ró   rb   s   @rK   r   r   …  s   ø„ Ù+÷1ñ 1rL   r   c                  ó,   ‡ — e Zd ZdZdˆ fd„Zdd„Zˆ xZS )r   zAConv.c                óJ   •— t         ‰| �  «        t        ||ddd«      | _        y)z}Initialize AConv module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
        re   rO   r   N)r:   r;   r   rh   ©rH   rG   rn   rJ   s      €rK   r;   zAConv.__init__œ  s$   ø€ ô 	‰ÑÔÜ˜˜B  1 aÓ(ˆ�rL   c                ó€   — t         j                  j                  j                  |ddddd«      }| j	                  |«      S )z!Forward pass through AConv layer.rO   r   r   FT)r@   r<   Ú
functionalÚ
avg_pool2drh   rp   s     rK   rV   zAConv.forward¦  s4   € ä�H‰H×Ñ×*Ñ*¨1¨a°°A°u¸dÓCˆØ�x‰x˜‹{ÐrL   ©rG   rX   rn   rX   rY   r\   rb   s   @rK   r   r   ™  s   ø„ Ùõ)÷rL   r   c                  ó,   ‡ — e Zd ZdZdˆ fd„Zdd„Zˆ xZS )r   zADown.c                óº   •— t         ‰| �  «        |dz  | _        t        |dz  | j                  ddd«      | _        t        |dz  | j                  ddd«      | _        y)z}Initialize ADown module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
        rO   re   r   r   N)r:   r;   rÌ   r   rh   rk   r�  s      €rK   r;   zADown.__init__¯  sS   ø€ ô 	‰ÑÔØ�q‘ˆŒÜ˜˜a™ §¡¨¨A¨qÓ1ˆŒÜ˜˜a™ §¡¨¨A¨qÓ1ˆ�rL   c                óT  — t         j                  j                  j                  |ddddd«      }|j	                  dd«      \  }}| j                  |«      }t         j                  j                  j                  |ddd«      }| j                  |«      }t        j                  ||fd«      S )z!Forward pass through ADown layer.rO   r   r   FTre   )	r@   r<   r‘  r’  rÓ   rh   Ú
max_pool2drk   rŠ   )rH   rI   rŒ   r‹   s       rK   rV   zADown.forward»  sˆ   € ä�H‰H×Ñ×*Ñ*¨1¨a°°A°u¸dÓCˆØ—‘˜˜A“‰ˆˆBØ�X‰X�b‹\ˆÜ�X‰X× Ñ ×+Ñ+¨B°°1°aÓ8ˆØ�X‰X�b‹\ˆÜ�y‰y˜"˜b˜ 1Ó%Ð%rL   r“  rY   r\   rb   s   @rK   r   r   ¬  s   ø„ Ùõ
2÷&rL   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   z	SPP-ELAN.c                óB  •— t         ‰| �  «        || _        t        ||dd«      | _        t        j                  |d|dz  ¬«      | _        t        j                  |d|dz  ¬«      | _        t        j                  |d|dz  ¬«      | _	        t        d|z  |dd«      | _
        y)zÞInitialize SPP-ELAN block.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            c3 (int): Intermediate channels.
            k (int): Kernel size for max pooling.
        r   rO   r¯   rN   N)r:   r;   rÌ   r   rh   r<   r�   rk   rl   r  Úcv5)rH   rG   rn   r  rg   rJ   s        €rK   r;   zSPPELAN.__init__È  s‡   ø€ ô 	‰ÑÔØˆŒÜ˜˜B  1Ó%ˆŒÜ—<‘<¨A°aÀÀaÁÔHˆŒÜ—<‘<¨A°aÀÀaÁÔHˆŒÜ—<‘<¨A°aÀÀaÁÔHˆŒÜ˜˜B™  A qÓ)ˆ�rL   c                óè   ‡— | j                  |«      gŠ‰j                  ˆfd„| j                  | j                  | j                  fD «       «       | j                  t        j                  ‰d«      «      S )z#Forward pass through SPPELAN layer.c              3  ó4   •K  — | ]  } |‰d    «      –— Œ y­wr£   r’   r¥   s     €rK   r–   z"SPPELAN.forward.<locals>.<genexpr>Ü  s   øè ø€ ÒB˜a‘�1�R‘5—ÑBùr¨   r   )rh   r©   rk   rl   r  rš  r@   rŠ   rª   s     @rK   rV   zSPPELAN.forwardÙ  sP   ø€ à�X‰X�a‹[ˆMˆØ	�‰ÓB D§H¡H¨d¯h©h¸¿¹Ð#AÔBÔBØ�x‰xœŸ	™	 ! Q›Ó(Ð(rL   )r²   )rG   rX   rn   rX   r  rX   rg   rX   rY   r\   rb   s   @rK   r   r   Å  s   ø„ Ùö*÷")rL   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r'   z	CBLinear.c           
     ó˜   •— t         ‰| �  «        || _        t        j                  |t        |«      ||t        ||«      |d¬«      | _        y)a  Initialize CBLinear module.

        Args:
            c1 (int): Input channels.
            c2s (list[int]): List of output channel sizes.
            k (int): Kernel size.
            s (int): Stride.
            p (int | None): Padding.
            g (int): Groups.
        T)Úgroupsr7   N)r:   r;   Úc2sr<   r=   Úsumr   r?   )rH   rG   r   rg   r  r  rÎ   rJ   s          €rK   r;   zCBLinear.__init__ã  s>   ø€ ô 	‰ÑÔØˆŒÜ—I‘I˜b¤# c£(¨A¨q´'¸!¸Q³-ÈÐPTÔUˆ�	rL   c                óZ   — | j                  |«      j                  | j                  d¬«      S )z$Forward pass through CBLinear layer.r   r†   )r?   rã   r   rp   s     rK   rV   zCBLinear.forwardò  s$   € à�y‰y˜‹|×!Ñ! $§(¡(°Ð!Ó2Ð2rL   )r   r   Nr   )rG   rX   r   ú	list[int]rg   rX   r  rX   r  z
int | NonerÎ   rX   )rI   rZ   r[   re  r\   rb   s   @rK   r'   r'   à  s   ø„ ÙöV÷3rL   r'   c                  ó,   ‡ — e Zd ZdZdˆ fd„Zdd„Zˆ xZS )r&   zCBFuse.c                ó0   •— t         ‰| �  «        || _        y)zmInitialize CBFuse module.

        Args:
            idx (list[int]): Indices for feature selection.
        N)r:   r;   Úidx)rH   r¦  rJ   s     €rK   r;   zCBFuse.__init__ú  s   ø€ ô 	‰ÑÔØˆ�rL   c           	     ó  — |d   j                   dd }t        |dd «      D ��cg c]-  \  }}t        j                  || j                  |      |d¬«      ‘Œ/ }}}t        j                  t        j                  ||dd z   «      d¬«      S c c}}w )z¹Forward pass through CBFuse layer.

        Args:
            xs (list[torch.Tensor]): List of input tensors.

        Returns:
            (torch.Tensor): Fused output tensor.
        r¤   rO   NÚnearest©ÚsizeÚmoder   r†   )rP   Ú	enumeraterˆ   Úinterpolater¦  r@   r¡  Ústack)rH   ÚxsÚtarget_sizer”   rI   Úress         rK   rV   zCBFuse.forward  s„   € ð ˜‘f—l‘l 1 2Ð&ˆÜ[dÐegÐhkÐikÐelÓ[m×nÑSWÐSTÐVWŒq�}‰}˜Q˜tŸx™x¨™{™^°+ÀIÖNÐnˆÑnÜ�y‰yœŸ™ S¨2¨b¨c¨7¡]Ó3¸Ô;Ð;ùó os   ¤2B	)r¦  r£  )r¯  re  r[   rZ   r\   rb   s   @rK   r&   r&   ÷  s   ø„ Ùõ÷<rL   r&   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )ÚC3fz<Faster Implementation of CSP Bottleneck with 3 convolutions.c                ó  •‡‡‡— t         ‰| �  «        t        ||z  «      Št        |‰dd«      | _        t        |‰dd«      | _        t        d|z   ‰z  |d«      | _        t        j                  ˆˆˆfd„t        |«      D «       «      | _
        y)ag  Initialize CSP bottleneck layer with three convolutions.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of Bottleneck blocks.
            shortcut (bool): Whether to use shortcut connections.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
        r   rO   c           	   3  ó@   •K  — | ]  }t        ‰‰‰‰d d¬«      –— Œ y­wrÆ   rê   rë   s     €€€rK   r–   zC3f.__init__.<locals>.<genexpr>$  s&   øè ø€ ÒlÐ^_œz¨"¨b°(¸AÐAQÐUX×YÐYÑlùrì   N)r:   r;   rX   r   rh   rk   rl   r<   r˜   r™   rš   rí   s	       `` @€rK   r;   zC3f.__init__  sv   û€ ô 	‰ÑÔÜ��a‘‹[ˆÜ˜˜B  1Ó%ˆŒÜ˜˜B  1Ó%ˆŒÜ˜˜Q™ "™ b¨!Ó,ˆŒÜ—‘ÕlÔchÐijÓckÔlÓlˆ�rL   c                óÚ   ‡— | j                  |«      | j                  |«      gŠ‰j                  ˆfd„| j                  D «       «       | j	                  t        j                  ‰d«      «      S )zForward pass through C3f layer.c              3  ó4   •K  — | ]  } |‰d    «      –— Œ y­wr£   r’   r¥   s     €rK   r–   zC3f.forward.<locals>.<genexpr>)  r§   r¨   r   )rk   rh   r©   rš   rl   r@   rŠ   rª   s     @rK   rV   zC3f.forward&  sL   ø€ à�X‰X�a‹[˜$Ÿ(™( 1›+Ð&ˆØ	�‰Ó* 4§6¡6Ô*Ô*Ø�x‰xœŸ	™	 ! Q›Ó(Ð(rL   rå   r×   rY   r\   rb   s   @rK   r³  r³    s   ø„ ÙFöm÷$)rL   r³  c                  óP   ‡ — e Zd ZdZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zˆ xZS )r$   rÙ   c	                ó˜   •‡ ‡‡‡‡— t         ‰	‰ �  |||‰‰|«       t        j                  ˆˆˆˆ ˆfd„t	        |«      D «       «      ‰ _        y)a¨  Initialize C3k2 module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of blocks.
            c3k (bool): Whether to use C3k blocks.
            e (float): Expansion ratio.
            attn (bool): Whether to use attention blocks.
            g (int): Groups for convolutions.
            shortcut (bool): Whether to use shortcut connections.
        c              3  óv  •K  — | ]°  }‰rct        j                  t        ‰j                  ‰j                  ‰‰«      t	        ‰j                  d t        ‰j                  dz  d«      ¬«      «      nF‰r#t        ‰j                  ‰j                  d‰‰«      n!t        ‰j                  ‰j                  ‰‰«      –— Œ² y­w)rÖ   é@   r   ©Ú
attn_ratioÚ	num_headsrO   N)r<   rÀ   r   rÌ   ÚPSABlockr6  ÚC3k)r“   rT   rE  Úc3krÎ   rH   r    s     €€€€€rK   r–   z C3k2.__init__.<locals>.<genexpr>H  s˜   øè ø€ ò 

ð ñ	 ô	 �M‰MÜ˜4Ÿ6™6 4§6¡6¨8°QÓ7Ü˜Ÿ™¨C¼3¸t¿v¹vÈ¹|ÈQÓ;OÔPôñ ô �T—V‘V˜TŸV™V Q¨°!Ô4ä˜DŸF™F D§F¡F¨H°aÓ8ó9ñ

ùs   ƒB6B9N©r:   r;   r<   r˜   r™   rš   )
rH   rG   rn   rž   rÁ  rÊ   rE  rÎ   r    rJ   s
   `   ` ```€rK   r;   zC3k2.__init__0  s?   ý€ ô. 	‰Ñ˜˜R  H¨a°Ô3Ü—‘÷ 

ô ˜1“Xô

ó 

ˆ�rL   )r   FrÖ   Fr   T)rG   rX   rn   rX   rž   rX   rÁ  r«   rÊ   rB   rE  r«   rÎ   rX   r    r«   ró   rb   s   @rK   r$   r$   -  sr   ø„ ÙFð ØØØØØð"
àð"
ð ð"
ð ð	"
ð
 ð"
ð ð"
ð ð"
ð ð"
ð ÷"
ñ "
rL   r$   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )rÀ  zhC3k is a CSP bottleneck module with customizable kernel sizes for feature extraction in neural networks.c                óª   •‡‡‡‡— t         ‰	| �  |||‰‰|«       t        ||z  «      Št        j                  ˆˆˆˆfd„t        |«      D «       Ž | _        y)ag  Initialize C3k module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of Bottleneck blocks.
            shortcut (bool): Whether to use shortcut connections.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
            k (int): Kernel size.
        c           	   3  óD   •K  — | ]  }t        ‰‰‰‰‰‰fd ¬«      –— Œ y­w)rÈ   rÉ   Nrê   )r“   rT   rm   rÎ   rg   r    s     €€€€rK   r–   zC3k.__init__.<locals>.<genexpr>g  s(   øè ø€ Ò dÐVW¤¨B°°H¸aÀAÀqÀ6ÈS×!QÐ!QÑ dùr—   Nrþ   )
rH   rG   rn   rž   r    rÎ   rÊ   rg   rm   rJ   s
       `` `@€rK   r;   zC3k.__init__X  sF   ü€ ô 	‰Ñ˜˜R  H¨a°Ô3Ü��a‘‹[ˆä—‘Ö dÔ[`ÐabÓ[cÔ dÐeˆ�rL   )r   Tr   rÖ   re   )rG   rX   rn   rX   rž   rX   r    r«   rÎ   rX   rÊ   rB   rg   rX   ró   rb   s   @rK   rÀ  rÀ  U  s   ø„ Ùr÷fò frL   rÀ  c                  ób   ‡ — e Zd ZdZdˆ fd„Zdd„Zdd„Z ej                  «       d„ «       Z	ˆ xZ
S )r0   z\RepVGGDW is a class that represents a depth-wise convolutional block in RepVGG architecture.c           	     ó¾   •— t         ‰| �  «        t        ||ddd|d¬«      | _        t        ||ddd|d¬«      | _        || _        t        j                  «       | _        y)zdInitialize RepVGGDW module.

        Args:
            ed (int): Input and output channels.
        r#  r   re   F©rÎ   rv   N)	r:   r;   r   r?   Úconv1r‡   r<   r  rv   )rH   ÚedrJ   s     €rK   r;   zRepVGGDW.__init__m  sT   ø€ ô 	‰ÑÔÜ˜˜R  A q¨B°EÔ:ˆŒ	Ü˜"˜b ! Q¨¨R°UÔ;ˆŒ
ØˆŒÜ—7‘7“9ˆ�rL   c                óf   — | j                  | j                  |«      | j                  |«      z   «      S )zØPerform a forward pass of the RepVGGDW block.

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

        Returns:
            (torch.Tensor): Output tensor after applying the depth-wise convolution.
        )rv   r?   rÉ  rp   s     rK   rV   zRepVGGDW.forwardy  s(   € ð �x‰x˜Ÿ	™	 !› t§z¡z°!£}Ñ4Ó5Ð5rL   c                óB   — | j                  | j                  |«      «      S )zÞPerform a forward pass of the fused RepVGGDW block.

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

        Returns:
            (torch.Tensor): Output tensor after applying the depth-wise convolution.
        )rv   r?   rp   s     rK   rw  zRepVGGDW.forward_fuse„  s   € ð �x‰x˜Ÿ	™	 !›Ó%Ð%rL   c                ó`  — t        | d«      syt        | j                  j                  | j                  j                  «      }t        | j                  j                  | j                  j                  «      }|j
                  }|j                  }|j
                  }|j                  }t        j                  j                  j                  |g d¢«      }||z   }||z   }|j
                  j                  j                  |«       |j                  j                  j                  |«       || _        | `y)z¡Fuse the convolutional layers in the RepVGGDW block.

        This method fuses the convolutional layers and updates the weights and biases accordingly.
        rÉ  N)rO   rO   rO   rO   )Úhasattrr   r?   r  rÉ  rE   r7   r@   r<   r‘  r‰   rF   Úcopy_)	rH   r?   rÉ  Úconv_wÚconv_bÚconv1_wÚconv1_bÚfinal_conv_wÚfinal_conv_bs	            rK   ry  zRepVGGDW.fuse�  s×   € ô �t˜WÔ%ØÜ §	¡	§¡°·	±	·±Ó=ˆÜ  §¡§¡°$·*±*·-±-Ó@ˆà—‘ˆØ—‘ˆØ—,‘,ˆØ—*‘*ˆä—(‘(×%Ñ%×)Ñ)¨'²<Ó@ˆà Ñ'ˆØ Ñ'ˆà�‰×Ñ×Ñ˜|Ô,Ø�	‰	�‰×Ñ˜\Ô*àˆŒ	Ø‰JrL   )rÊ  rX   r[   ÚNonerY   )r]   r^   r_   r`   r;   rV   rw  r@   Úno_gradry  ra   rb   s   @rK   r0   r0   j  s1   ø„ Ùfõ
ó	6ó	&ð €U‡]�]ƒ_ñó ôrL   r0   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   a©  Compact Inverted Block (CIB) module.

    Args:
        c1 (int): Number of input channels.
        c2 (int): Number of output channels.
        shortcut (bool, optional): Whether to add a shortcut connection. Defaults to True.
        e (float, optional): Scaling factor for the hidden channels. Defaults to 0.5.
        lk (bool, optional): Whether to use RepVGGDW for the third convolutional layer. Defaults to False.
    c                óN  •— t         ‰| �  «        t        ||z  «      }t        j                  t        ||d|¬«      t        |d|z  d«      |rt        d|z  «      nt        d|z  d|z  dd|z  ¬«      t        d|z  |d«      t        ||d|¬«      «      | _        |xr ||k(  | _        y)a  Initialize the CIB module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            shortcut (bool): Whether to use shortcut connection.
            e (float): Expansion ratio.
            lk (bool): Whether to use RepVGGDW.
        re   r  rO   r   N)	r:   r;   rX   r<   rÀ   r   r0   rh   r�   )rH   rG   rn   r    rÊ   Úlkrm   rJ   s          €rK   r;   zCIB.__init__¶  s¢   ø€ ô 	‰ÑÔÜ��a‘‹[ˆÜ—=‘=Ü��R˜˜bÔ!Ü��Q˜‘V˜QÓÙ "ŒH�Q˜‘VÔ¬¨Q°©V°Q¸±V¸QÀ!ÀbÁ&Ô(IÜ��R‘˜˜QÓÜ��R˜˜bÔ!ó
ˆŒð Ò(  b¡ˆ�rL   c                ód   — | j                   r|| j                  |«      z   S | j                  |«      S )z Forward pass of the CIB module.

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

        Returns:
            (torch.Tensor): Output tensor.
        )r�   rh   rp   s     rK   rV   zCIB.forwardÌ  s)   € ð #'§(¢(ˆq�4—8‘8˜A“;‰Ð;°·±¸³Ð;rL   )TrÖ   F)
rG   rX   rn   rX   r    r«   rÊ   rB   rÚ  r«   rY   r\   rb   s   @rK   r   r   «  s   ø„ ñö)÷,	<rL   r   c                  óB   ‡ — e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zˆ xZS )r!   aD  C2fCIB class represents a convolutional block with C2f and CIB modules.

    Args:
        c1 (int): Number of input channels.
        c2 (int): Number of output channels.
        n (int, optional): Number of CIB modules to stack. Defaults to 1.
        shortcut (bool, optional): Whether to use shortcut connection. Defaults to False.
        lk (bool, optional): Whether to use large kernel. Defaults to False.
        g (int, optional): Number of groups for grouped convolution. Defaults to 1.
        e (float, optional): Expansion ratio for CIB modules. Defaults to 0.5.
    c                ó�   •‡ ‡‡— t         ‰‰ �  |||‰||«       t        j                  ˆˆ ˆfd„t	        |«      D «       «      ‰ _        y)au  Initialize C2fCIB module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of CIB modules.
            shortcut (bool): Whether to use shortcut connection.
            lk (bool): Whether to use large kernel.
            g (int): Groups for convolutions.
            e (float): Expansion ratio.
        c              3  óf   •K  — | ](  }t        ‰j                  ‰j                  ‰d ‰¬«      –— Œ* y­w)rÈ   )rÊ   rÚ  N)r   rÌ   )r“   rT   rÚ  rH   r    s     €€€rK   r–   z"C2fCIB.__init__.<locals>.<genexpr>ô  s)   øè ø€ Ò]Èqœs 4§6¡6¨4¯6©6°8¸sÀr×JÐJÑ]ùs   ƒ.1NrÂ  )	rH   rG   rn   rž   r    rÚ  rÎ   rÊ   rJ   s	   `   ``  €rK   r;   zC2fCIB.__init__å  s9   û€ ô 	‰Ñ˜˜R  H¨a°Ô3Ü—‘Õ]ÔTYÐZ[ÓT\Ô]Ó]ˆ�rL   )r   FFr   rÖ   )rG   rX   rn   rX   rž   rX   r    r«   rÚ  r«   rÎ   rX   rÊ   rB   ró   rb   s   @rK   r!   r!   Ø  sZ   ø„ ñ
ð nqð^Øð^Øð^Ø#&ð^Ø6:ð^ØHLð^ØY\ð^Øej÷^ñ ^rL   r!   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   aù  Attention module that performs self-attention on the input tensor.

    Args:
        dim (int): The input tensor dimension.
        num_heads (int): The number of attention heads.
        attn_ratio (float): The ratio of the attention key dimension to the head dimension.

    Attributes:
        num_heads (int): The number of attention heads.
        head_dim (int): The dimension of each attention head.
        key_dim (int): The dimension of the attention key.
        scale (float): The scaling factor for the attention scores.
        qkv (Conv): Convolutional layer for computing the query, key, and value.
        proj (Conv): Convolutional layer for projecting the attended values.
        pe (Conv): Convolutional layer for positional encoding.
    c                óP  •— t         ‰| �  «        || _        ||z  | _        t	        | j                  |z  «      | _        | j
                  dz  | _        | j
                  |z  }||dz  z   }t        ||dd¬«      | _        t        ||dd¬«      | _	        t        ||dd|d¬«      | _
        y)	zâInitialize multi-head attention module.

        Args:
            dim (int): Input dimension.
            num_heads (int): Number of attention heads.
            attn_ratio (float): Attention ratio for key dimension.
        ç      à¿rO   r   Fru   re   rÈ  N)r:   r;   r¾  Úhead_dimrX   Úkey_dimr2  r   ÚqkvrT  Úpe)rH   r‡   r¾  r½  Únh_kdr;  rJ   s         €rK   r;   zAttention.__init__	  s�   ø€ ô 	‰ÑÔØ"ˆŒØ˜yÑ(ˆŒÜ˜4Ÿ=™=¨:Ñ5Ó6ˆŒØ—\‘\ 4Ñ'ˆŒ
Ø—‘˜yÑ(ˆØ�%˜!‘)‰OˆÜ˜˜Q  uÔ-ˆŒÜ˜˜c 1¨%Ô0ˆŒ	Ü�s˜C  A¨°%Ô8ˆ�rL   c           	     óP  — |j                   \  }}}}||z  }| j                  |«      }|j                  || j                  | j                  dz  | j
                  z   |«      j                  | j                  | j                  | j
                  gd¬«      \  }}	}
|j                  dd«      |	z  | j                  z  }|j                  d¬«      }|
|j                  dd«      z  j                  ||||«      | j                  |
j                  ||||«      «      z   }| j                  |«      }|S )zÃForward pass of the Attention module.

        Args:
            x (torch.Tensor): The input tensor.

        Returns:
            (torch.Tensor): The output tensor after self-attention.
        rO   r†   éþÿÿÿr¤   )rP   rä  rD   r¾  rã  râ  rã   rQ   r2  rR   rå  r_  rT  )rH   rI   ÚBÚCÚHÚWÚNrä  rb  rg   rc  rE  s               rK   rV   zAttention.forward  s  € ð —W‘W‰
ˆˆ1ˆa�Ø�‰EˆØ�h‰h�q‹kˆØ—(‘(˜1˜dŸn™n¨d¯l©l¸QÑ.>ÀÇÁÑ.NÐPQÓR×XÑXØ�\‰\˜4Ÿ<™<¨¯©Ð7¸Qð Yó 
‰ˆˆ1ˆað —‘˜B Ó# aÑ'¨4¯:©:Ñ5ˆØ�|‰| ˆ|Ó#ˆØ�—‘  BÓ'Ñ'×-Ñ-¨a°°A°qÓ9¸D¿G¹GÀAÇIÁIÈaÐQRÐTUÐWXÓDYÓ<ZÑZˆØ�I‰I�a‹LˆØˆrL   )rd  rÖ   )r‡   rX   r¾  rX   r½  rB   rY   r\   rb   s   @rK   r   r   ÷  s   ø„ ñö"9÷&rL   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r¿  aF  PSABlock class implementing a Position-Sensitive Attention block for neural networks.

    This class encapsulates the functionality for applying multi-head attention and feed-forward neural network layers
    with optional shortcut connections.

    Attributes:
        attn (Attention): Multi-head attention module.
        ffn (nn.Sequential): Feed-forward neural network module.
        add (bool): Flag indicating whether to add shortcut connections.

    Methods:
        forward: Performs a forward pass through the PSABlock, applying attention and feed-forward layers.

    Examples:
        Create a PSABlock and perform a forward pass
        >>> psablock = PSABlock(c=128, attn_ratio=0.5, num_heads=4, shortcut=True)
        >>> input_tensor = torch.randn(1, 128, 32, 32)
        >>> output_tensor = psablock(input_tensor)
    c           	     óÈ   •— t         ‰| �  «        t        |||¬«      | _        t	        j
                  t        ||dz  d«      t        |dz  |dd¬«      «      | _        || _        y)a  Initialize the PSABlock.

        Args:
            c (int): Input and output channels.
            attn_ratio (float): Attention ratio for key dimension.
            num_heads (int): Number of attention heads.
            shortcut (bool): Whether to use shortcut connections.
        r¼  rO   r   Fru   N)	r:   r;   r   rE  r<   rÀ   r   Úffnr�   )rH   rÌ   r½  r¾  r    rJ   s        €rK   r;   zPSABlock.__init__H  sU   ø€ ô 	‰ÑÔä˜a¨JÀ)ÔLˆŒ	Ü—=‘=¤ a¨¨Q©°Ó!2´D¸¸Q¹ÀÀ1È%Ô4PÓQˆŒØˆ�rL   c                óÎ   — | j                   r|| j                  |«      z   n| j                  |«      }| j                   r|| j                  |«      z   }|S | j                  |«      }|S )zÕExecute a forward pass through PSABlock.

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

        Returns:
            (torch.Tensor): Output tensor after attention and feed-forward processing.
        )r�   rE  rð  rp   s     rK   rV   zPSABlock.forwardW  sV   € ð !%§¢ˆA�—	‘	˜!“Ò¨d¯i©i¸«lˆØ#ŸxšxˆA�—‘˜“‰OˆØˆð .2¯X©X°a«[ˆØˆrL   )rÖ   rN   T)
rÌ   rX   r½  rB   r¾  rX   r    r«   r[   rÖ  rY   r\   rb   s   @rK   r¿  r¿  3  s   ø„ ñö(÷rL   r¿  c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   a  PSA class for implementing Position-Sensitive Attention in neural networks.

    This class encapsulates the functionality for applying position-sensitive attention and feed-forward networks to
    input tensors, enhancing feature extraction and processing capabilities.

    Attributes:
        c (int): Number of hidden channels after applying the initial convolution.
        cv1 (Conv): 1x1 convolution layer to reduce the number of input channels to 2*c.
        cv2 (Conv): 1x1 convolution layer to reduce the number of output channels to c1.
        attn (Attention): Attention module for position-sensitive attention.
        ffn (nn.Sequential): Feed-forward network for further processing.

    Methods:
        forward: Applies position-sensitive attention and feed-forward network to the input tensor.

    Examples:
        Create a PSA module and apply it to an input tensor
        >>> psa = PSA(c1=128, c2=128, e=0.5)
        >>> input_tensor = torch.randn(1, 128, 64, 64)
        >>> output_tensor = psa.forward(input_tensor)
    c           	     óþ  •— t         ‰| �  «        ||k(  sJ ‚t        ||z  «      | _        t	        |d| j                  z  dd«      | _        t	        d| j                  z  |d«      | _        t        | j                  dt        | j                  dz  d«      ¬«      | _	        t        j                  t	        | j                  | j                  dz  d«      t	        | j                  dz  | j                  dd¬«      «      | _        y)	z£Initialize PSA module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            e (float): Expansion ratio.
        rO   r   rÖ   r»  r¼  Fru   N)r:   r;   rX   rÌ   r   rh   rk   r   r6  rE  r<   rÀ   rð  )rH   rG   rn   rÊ   rJ   s       €rK   r;   zPSA.__init__|  sÀ   ø€ ô 	‰ÑÔØ�RŠxˆˆxÜ�R˜!‘V“ˆŒÜ˜˜A §¡™J¨¨1Ó-ˆŒÜ˜˜DŸF™F™
 B¨Ó*ˆŒä˜dŸf™f°ÄÀDÇFÁFÈbÁLÐRSÓ@TÔUˆŒ	Ü—=‘=¤ d§f¡f¨d¯f©f°q©j¸!Ó!<¼dÀ4Ç6Á6ÈAÁ:ÈtÏvÉvÐWXÐ^cÔ>dÓeˆ�rL   c                ó  — | j                  |«      j                  | j                  | j                  fd¬«      \  }}|| j                  |«      z   }|| j	                  |«      z   }| j                  t        j                  ||fd«      «      S )zÐExecute forward pass in PSA module.

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

        Returns:
            (torch.Tensor): Output tensor after attention and feed-forward processing.
        r   r†   )rh   rã   rÌ   rE  rð  rk   r@   rŠ   rÔ   s       rK   rV   zPSA.forward�  ss   € ð �x‰x˜‹{× Ñ  $§&¡&¨$¯&©&Ð!1°qÐ Ó9‰ˆˆ1Ø�—	‘	˜!“ÑˆØ�—‘˜“‰OˆØ�x‰xœŸ	™	 1 a &¨!Ó,Ó-Ð-rL   )rÖ   )rG   rX   rn   rX   rÊ   rB   rY   r\   rb   s   @rK   r   r   e  s   ø„ ñö,f÷".rL   r   c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )r   aH  C2PSA module with attention mechanism for enhanced feature extraction and processing.

    This module implements a convolutional block with attention mechanisms to enhance feature extraction and processing
    capabilities. It includes a series of PSABlock modules for self-attention and feed-forward operations.

    Attributes:
        c (int): Number of hidden channels.
        cv1 (Conv): 1x1 convolution layer to reduce the number of input channels to 2*c.
        cv2 (Conv): 1x1 convolution layer to reduce the number of output channels to c1.
        m (nn.Sequential): Sequential container of PSABlock modules for attention and feed-forward operations.

    Methods:
        forward: Performs a forward pass through the C2PSA module, applying attention and feed-forward operations.

    Examples:
        >>> c2psa = C2PSA(c1=256, c2=256, n=3, e=0.5)
        >>> input_tensor = torch.randn(1, 256, 64, 64)
        >>> output_tensor = c2psa(input_tensor)

    Notes:
        This module essentially is the same as PSA module, but refactored to allow stacking more PSABlock modules.
    c                ó(  •‡ — t         ‰‰ �  «        ||k(  sJ ‚t        ||z  «      ‰ _        t	        |d‰ j                  z  dd«      ‰ _        t	        d‰ j                  z  |d«      ‰ _        t        j                  ˆ fd„t        |«      D «       Ž ‰ _
        y)zÖInitialize C2PSA module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of PSABlock modules.
            e (float): Expansion ratio.
        rO   r   c              3  óh   •K  — | ])  }t        ‰j                  d ‰j                  dz  ¬«      –— Œ+ y­w)rÖ   r»  r¼  N)r¿  rÌ   ©r“   rT   rH   s     €rK   r–   z!C2PSA.__init__.<locals>.<genexpr>Ã  s+   øè ø€ Ò lÐ^_¤¨$¯&©&¸SÈDÏFÉFÐVXÉL×!YÐ!YÑ lùrÏ   NrÐ   ©rH   rG   rn   rž   rÊ   rJ   s   `    €rK   r;   zC2PSA.__init__´  sy   ù€ ô 	‰ÑÔØ�RŠxˆˆxÜ�R˜!‘V“ˆŒÜ˜˜A §¡™J¨¨1Ó-ˆŒÜ˜˜DŸF™F™
 B¨Ó*ˆŒä—‘Ó lÔchÐijÓckÔ lÐmˆ�rL   c                óè   — | j                  |«      j                  | j                  | j                  fd¬«      \  }}| j                  |«      }| j	                  t        j                  ||fd«      «      S )zÊProcess the input tensor through a series of PSA blocks.

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

        Returns:
            (torch.Tensor): Output tensor after processing.
        r   r†   )rh   rã   rÌ   rš   rk   r@   rŠ   rÔ   s       rK   rV   zC2PSA.forwardÅ  s]   € ð �x‰x˜‹{× Ñ  $§&¡&¨$¯&©&Ð!1°qÐ Ó9‰ˆˆ1Ø�F‰F�1‹IˆØ�x‰xœŸ	™	 1 a &¨!Ó,Ó-Ð-rL   ©r   rÖ   rø   rY   r\   rb   s   @rK   r   r   œ  s   ø„ ñö.n÷".rL   r   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )r"   a¨  C2fPSA module with enhanced feature extraction using PSA blocks.

    This class extends the C2f module by incorporating PSA blocks for improved attention mechanisms and feature
    extraction.

    Attributes:
        c (int): Number of hidden channels.
        cv1 (Conv): 1x1 convolution layer to reduce the number of input channels to 2*c.
        cv2 (Conv): 1x1 convolution layer to reduce the number of output channels to c2.
        m (nn.ModuleList): List of PSABlock modules for feature extraction.

    Methods:
        forward: Performs a forward pass through the C2fPSA module.
        forward_split: Performs a forward pass using split() instead of chunk().

    Examples:
        >>> import torch
        >>> from ultralytics.nn.modules.block import C2fPSA
        >>> model = C2fPSA(c1=64, c2=64, n=3, e=0.5)
        >>> x = torch.randn(1, 64, 128, 128)
        >>> output = model(x)
        >>> print(output.shape)
    c                ó”   •‡ — ||k(  sJ ‚t         ‰‰ �  ||||¬«       t        j                  ˆ fd„t	        |«      D «       «      ‰ _        y)z×Initialize C2fPSA module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            n (int): Number of PSABlock modules.
            e (float): Expansion ratio.
        )rž   rÊ   c           	   3  ó|   •K  — | ]3  }t        ‰j                  d t        ‰j                  dz  d«      ¬«      –— Œ5 y­w)rÖ   r»  r   r¼  N)r¿  rÌ   r6  rø  s     €rK   r–   z"C2fPSA.__init__.<locals>.<genexpr>÷  s3   øè ø€ ÒrÐdeœx¨¯©¸3Ì#ÈdÏfÉfÐXZÉlÐ\]ÓJ^×_Ð_Ñrùs   ƒ9<NrÂ  rù  s   `    €rK   r;   zC2fPSA.__init__ì  sC   ù€ ð �RŠxˆˆxÜ‰Ñ˜˜R 1¨ÐÔ*Ü—‘ÓrÔinÐopÓiqÔrÓrˆ�rL   rû  rø   ró   rb   s   @rK   r"   r"   Ó  s   ø„ ñ÷0sò srL   r"   c                  ó,   ‡ — e Zd ZdZdˆ fd„Zdd„Zˆ xZS )r2   aH  SCDown module for downsampling with separable convolutions.

    This module performs downsampling using a combination of pointwise and depthwise convolutions, which helps in
    efficiently reducing the spatial dimensions of the input tensor while maintaining the channel information.

    Attributes:
        cv1 (Conv): Pointwise convolution layer that reduces the number of channels.
        cv2 (Conv): Depthwise convolution layer that performs spatial downsampling.

    Methods:
        forward: Applies the SCDown module to the input tensor.

    Examples:
        >>> import torch
        >>> from ultralytics.nn.modules.block import SCDown
        >>> model = SCDown(c1=64, c2=128, k=3, s=2)
        >>> x = torch.randn(1, 64, 128, 128)
        >>> y = model(x)
        >>> print(y.shape)
        torch.Size([1, 128, 64, 64])
    c                ót   •— t         ‰| �  «        t        ||dd«      | _        t        |||||d¬«      | _        y)z½Initialize SCDown module.

        Args:
            c1 (int): Input channels.
            c2 (int): Output channels.
            k (int): Kernel size.
            s (int): Stride.
        r   F)rg   r  rÎ   rv   N)r:   r;   r   rh   rk   )rH   rG   rn   rg   r  rJ   s        €rK   r;   zSCDown.__init__  s8   ø€ ô 	‰ÑÔÜ˜˜B  1Ó%ˆŒÜ˜˜B ! q¨B°EÔ:ˆ�rL   c                óB   — | j                  | j                  |«      «      S )zÄApply convolution and downsampling to the input tensor.

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

        Returns:
            (torch.Tensor): Downsampled output tensor.
        )rk   rh   rp   s     rK   rV   zSCDown.forward  s   € ð �x‰x˜Ÿ™ ›Ó$Ð$rL   r  rY   r\   rb   s   @rK   r2   r2   ú  s   ø„ ñõ,;÷	%rL   r2   c                  óB   ‡ — e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Zˆ xZS )r3   a?  TorchVision module to allow loading any torchvision model.

    This class provides a way to load a model from the torchvision library, optionally load pre-trained weights, and
    customize the model by truncating or unwrapping layers.

    Args:
        model (str): Name of the torchvision model to load.
        weights (str, optional): Pre-trained weights to load. Default is "DEFAULT".
        unwrap (bool, optional): Unwraps the model to a sequential containing all but the last `truncate` layers.
        truncate (int, optional): Number of layers to truncate from the end if `unwrap` is True. Default is 2.
        split (bool, optional): Returns output from intermediate child modules as list. Default is False.

    Attributes:
        m (nn.Module): The loaded torchvision model, possibly truncated and unwrapped.
    c                ó†  •— ddl }t        ‰| �	  «        t        |j                  d«      r#|j                  j                  ||¬«      | _        n. |j                  j                  |   t        |«      ¬«      | _        |rŠt        | j                  j                  «       «      }t        |d   t        j                  «      r#g t        |d   j                  «       «      ¢|dd ¢}t        j                  |r|d|  n|Ž | _        || _        yd| _        t        j                  «       x| j                  _        | j                  _        y)ae  Load the model and weights from torchvision.

        Args:
            model (str): Name of the torchvision model to load.
            weights (str): Pre-trained weights to load.
            unwrap (bool): Whether to unwrap the model.
            truncate (int): Number of layers to truncate.
            split (bool): Whether to split the output.
        r   NÚ	get_model)Úweights)Ú
pretrainedr   F)Útorchvisionr:   r;   rÎ  Úmodelsr  rš   Ú__dict__r«   rß   ÚchildrenÚ
isinstancer<   rÀ   rã   rö   ÚheadÚheads)	rH   Úmodelr  ÚunwrapÚtruncaterã   r  ÚlayersrJ   s	           €rK   r;   zTorchVision.__init__;  sû   ø€ ó 	ä‰ÑÔÜ�;×%Ñ% {Ô3Ø ×'Ñ'×1Ñ1°%ÀÐ1ÓIˆD�Fà7�[×'Ñ'×0Ñ0°Ñ7Ä4ÈÃ=ÔQˆDŒFÙÜ˜$Ÿ&™&Ÿ/™/Ó+Ó,ˆFÜ˜& ™)¤R§]¡]Ô3ØCœ4  q¡	× 2Ñ 2Ó 4Ó5ÐC¸¸q¸r¸
ÐC�Ü—]‘]¹8 V¨J¨h¨YÑ%7ÈÐQˆDŒFØˆD�JàˆDŒJÜ)+¯©«Ð6ˆD�F‰FŒK˜$Ÿ&™&�,rL   c                ó”   ‡— | j                   r)|gŠ‰j                  ˆfd„| j                  D «       «       ‰S | j                  |«      Š‰S )zÈForward pass through the model.

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

        Returns:
            (torch.Tensor | list[torch.Tensor]): Output tensor or list of tensors.
        c              3  ó4   •K  — | ]  } |‰d    «      –— Œ y­wr£   r’   r¥   s     €rK   r–   z&TorchVision.forward.<locals>.<genexpr>c  s   øè ø€ Ò. !‘Q�q˜‘u—XÑ.ùr¨   )rã   r©   rš   rª   s     @rK   rV   zTorchVision.forwardX  sD   ø€ ð �:Š:Ø�ˆAØ�H‰HÓ. t§v¡vÔ.Ô.ð ˆð —‘�q“	ˆAØˆrL   )ÚDEFAULTTrO   F)
r  Ústrr  r  r  r«   r  rX   rã   r«   rY   r\   rb   s   @rK   r3   r3   *  sA   ø„ ñð" kpð7Øð7Ø#&ð7Ø<@ð7ØSVð7Øcgõ7÷:rL   r3   c                  ó8   ‡ — e Zd ZdZddˆ fd„Zˆ fd„Zdd„Zˆ xZS )ÚAAttnaÏ  Area-attention module for YOLO models, providing efficient attention mechanisms.

    This module implements an area-based attention mechanism that processes input features in a spatially-aware manner,
    making it particularly effective for object detection tasks.

    Attributes:
        area (int): Number of areas the feature map is divided into.
        num_heads (int): Number of heads into which the attention mechanism is divided.
        head_dim (int): Dimension of each attention head.
        qkv (Conv): Convolution layer for computing query, key and value tensors.
        proj (Conv): Projection convolution layer.
        pe (Conv): Position encoding convolution layer.

    Methods:
        forward: Applies area-attention to input tensor.

    Examples:
        >>> attn = AAttn(dim=256, num_heads=8, area=4)
        >>> x = torch.randn(1, 256, 32, 32)
        >>> output = attn(x)
        >>> print(output.shape)
        torch.Size([1, 256, 32, 32])
    c           	     ó  •— t         ‰| �  «        || _        || _        ||z  x| _        }|| j                  z  x| _        }t        ||dz  dd¬«      | _        t        ||dd¬«      | _        t        ||ddd|d¬«      | _	        y)a#  Initialize an Area-attention module for YOLO models.

        Args:
            dim (int): Number of hidden channels.
            num_heads (int): Number of heads into which the attention mechanism is divided.
            area (int): Number of areas the feature map is divided into.
        re   r   Fru   r#  rÈ  N)
r:   r;   Úarear¾  râ  Úall_head_dimr   rä  rT  rå  )rH   r‡   r¾  r  râ  r  rJ   s         €rK   r;   zAAttn.__init__‚  s‡   ø€ ô 	‰ÑÔØˆŒ	à"ˆŒØ#&¨)Ñ#3Ð3ˆŒ˜Ø+3°d·n±nÑ+DÐDˆÔ˜Lä˜˜\¨AÑ-¨q°eÔ<ˆŒÜ˜ s¨A°5Ô9ˆŒ	Ü�| \°1°a¸¸lÐPUÔVˆ�rL   c                óz   •— t         ‰| �  |«       t        | d«      s| j                  | j                  z  | _        yy)z6Add missing all_head_dim attribute to old checkpoints.r  N)r:   Ú__setstate__rÎ  râ  r¾  r  )rH   ÚstaterJ   s     €rK   r  zAAttn.__setstate__•  s4   ø€ ä‰Ñ˜UÔ#Ü�t˜^Ô,Ø $§¡°·±Ñ >ˆDÕð -rL   c                ój  — |j                   \  }}}}||z  }| j                  |«      j                  d«      j                  dd«      }| j                  dkD  rJ|j                  || j                  z  || j                  z  | j                  dz  «      }|j                   \  }}}|j                  ||| j                  | j                  dz  «      j                  dddd«      j                  | j                  | j                  | j                  gd¬«      \  }}	}
|j                  dd«      |	z  | j                  dz  z  }|j                  d¬«      }|
|j                  dd«      z  }|j                  dddd«      }|
j                  dddd«      }
| j                  dkD  r~|j                  || j                  z  || j                  z  | j                  «      }|
j                  || j                  z  || j                  z  | j                  «      }
|j                   \  }}}|j                  |||| j                  «      j                  dddd«      j                  «       }|
j                  |||| j                  «      j                  dddd«      j                  «       }
|| j                  |
«      z   }| j                  |«      S )	zÊProcess the input tensor through the area-attention.

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

        Returns:
            (torch.Tensor): Output tensor after area-attention.
        rO   r   re   r   r†   rè  r¤   rá  )rP   rä  ÚflattenrQ   r  r_  r  rD   r¾  râ  Úpermuterã   rR   Ú
contiguousrå  rT  )rH   rI   ré  rT   rë  rì  rí  rä  rb  rg   rc  rE  s               rK   rV   zAAttn.forward›  sI  € ð —W‘W‰
ˆˆ1ˆa�Ø�‰Eˆà�h‰h�q‹k×!Ñ! !Ó$×.Ñ.¨q°!Ó4ˆØ�9‰9�qŠ=Ø—+‘+˜a $§)¡)™m¨Q°$·)±)©^¸T×=NÑ=NÐQRÑ=RÓSˆCØ—i‘i‰GˆAˆq�!à�H‰H�Q˜˜4Ÿ>™>¨4¯=©=¸1Ñ+<Ó=ß‰W�Q˜˜1˜aÓ ß‰U�D—M‘M 4§=¡=°$·-±-Ð@ÀaˆUÓHñ 	ˆˆ1ˆað
 —‘˜B Ó# aÑ'¨D¯M©M¸4Ñ,?Ñ@ˆØ�|‰| ˆ|Ó#ˆØ�—‘˜r 2Ó&Ñ&ˆØ�I‰I�a˜˜A˜qÓ!ˆØ�I‰I�a˜˜A˜qÓ!ˆà�9‰9�qŠ=Ø—	‘	˜!˜tŸy™y™.¨!¨d¯i©i©-¸×9JÑ9JÓKˆAØ—	‘	˜!˜tŸy™y™.¨!¨d¯i©i©-¸×9JÑ9JÓKˆAØ—g‘g‰GˆAˆq�!à�I‰I�a˜˜A˜t×0Ñ0Ó1×9Ñ9¸!¸QÀÀ1ÓE×PÑPÓRˆØ�I‰I�a˜˜A˜t×0Ñ0Ó1×9Ñ9¸!¸QÀÀ1ÓE×PÑPÓRˆà�—‘˜“
‰NˆØ�y‰y˜‹|ÐrL   rÂ   )r‡   rX   r¾  rX   r  rX   rY   )r]   r^   r_   r`   r;   r  rV   ra   rb   s   @rK   r  r  i  s   ø„ ñö0Wô&?÷$rL   r  c                  ó@   ‡ — e Zd ZdZddˆ fd„Zedd„«       Zdd„Zˆ xZS )	ÚABlocka§  Area-attention block module for efficient feature extraction in YOLO models.

    This module implements an area-attention mechanism combined with a feed-forward network for processing feature maps.
    It uses a novel area-based attention approach that is more efficient than traditional self-attention while
    maintaining effectiveness.

    Attributes:
        attn (AAttn): Area-attention module for processing spatial features.
        mlp (nn.Sequential): Multi-layer perceptron for feature transformation.

    Methods:
        _init_weights: Initializes module weights using truncated normal distribution.
        forward: Applies area-attention and feed-forward processing to input tensor.

    Examples:
        >>> block = ABlock(dim=256, num_heads=8, mlp_ratio=1.2, area=1)
        >>> x = torch.randn(1, 256, 32, 32)
        >>> output = block(x)
        >>> print(output.shape)
        torch.Size([1, 256, 32, 32])
    c           	     ó   •— t         ‰| �  «        t        |||¬«      | _        t	        ||z  «      }t        j                  t        ||d«      t        ||dd¬«      «      | _        | j                  | j                  «       y)aa  Initialize an Area-attention block module.

        Args:
            dim (int): Number of input channels.
            num_heads (int): Number of heads into which the attention mechanism is divided.
            mlp_ratio (float): Expansion ratio for MLP hidden dimension.
            area (int): Number of areas the feature map is divided into.
        )r¾  r  r   Fru   N)r:   r;   r  rE  rX   r<   rÀ   r   ÚmlpÚapplyÚ_init_weights)rH   r‡   r¾  Ú	mlp_ratior  Úmlp_hidden_dimrJ   s         €rK   r;   zABlock.__init__Ù  si   ø€ ô 	‰ÑÔä˜#¨¸Ô>ˆŒ	Ü˜S 9™_Ó-ˆÜ—=‘=¤ c¨>¸1Ó!=¼tÀNÐTWÐYZÐ`eÔ?fÓgˆŒà�
‰
�4×%Ñ%Õ&rL   c                óþ   — t        | t        j                  «      rct        j                  j	                  | j
                  d¬«       | j                  �+t        j                  j                  | j                  d«       yyy)z‚Initialize weights using a truncated normal distribution.

        Args:
            m (nn.Module): Module to initialize.
        g{®Gáz”?)ÚstdNr   )r  r<   r=   ÚinitÚtrunc_normal_rE   r7   Ú	constant_rº   s    rK   r'  zABlock._init_weightsê  sY   € ô �aœŸ™Ô#Ü�G‰G×!Ñ! !§(¡(°Ð!Ô5Ø�v‰vÐ!Ü—‘×!Ñ! !§&¡&¨!Õ,ð "ð $rL   c                óR   — || j                  |«      z   }|| j                  |«      z   S )zÎForward pass through ABlock.

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

        Returns:
            (torch.Tensor): Output tensor after area-attention and feed-forward processing.
        )rE  r%  rp   s     rK   rV   zABlock.forwardö  s(   € ð �—	‘	˜!“ÑˆØ�4—8‘8˜A“;‰ÐrL   )g333333ó?r   )r‡   rX   r¾  rX   r(  rB   r  rX   )rš   r¬   rY   )	r]   r^   r_   r`   r;   r|  r'  rV   ra   rb   s   @rK   r#  r#  Â  s&   ø„ ñö,'ð" ò	-ó ð	-÷
rL   r#  c                  ód   ‡ — e Zd ZdZ	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Zˆ xZS )ÚA2C2faê  Area-Attention C2f module for enhanced feature extraction with area-based attention mechanisms.

    This module extends the C2f architecture by incorporating area-attention and ABlock layers for improved feature
    processing. It supports both area-attention and standard convolution modes.

    Attributes:
        cv1 (Conv): Initial 1x1 convolution layer that reduces input channels to hidden channels.
        cv2 (Conv): Final 1x1 convolution layer that processes concatenated features.
        gamma (nn.Parameter | None): Learnable parameter for residual scaling when using area attention.
        m (nn.ModuleList): List of either ABlock or C3k modules for feature processing.

    Methods:
        forward: Processes input through area-attention or standard convolution pathway.

    Examples:
        >>> m = A2C2f(512, 512, n=1, a2=True, area=1)
        >>> x = torch.randn(1, 512, 32, 32)
        >>> output = m(x)
        >>> print(output.shape)
        torch.Size([1, 512, 32, 32])
    c                ó�  •‡‡‡‡	‡
‡— t         ‰| �  «        t        ||z  «      Š‰dz  dk(  sJ d«       ‚t        |‰dd«      | _        t        d|z   ‰z  |d«      | _        ‰r/|r-t        j                  dt        j                  |«      z  d¬«      nd| _
        t        j                  ˆˆˆˆ	ˆˆ
fd	„t        |«      D «       «      | _        y)
a  Initialize Area-Attention C2f module.

        Args:
            c1 (int): Number of input channels.
            c2 (int): Number of output channels.
            n (int): Number of ABlock or C3k modules to stack.
            a2 (bool): Whether to use area attention blocks. If False, uses C3k blocks instead.
            area (int): Number of areas the feature map is divided into.
            residual (bool): Whether to use residual connections with learnable gamma parameter.
            mlp_ratio (float): Expansion ratio for MLP hidden dimension.
            e (float): Channel expansion ratio for hidden channels.
            g (int): Number of groups for grouped convolutions.
            shortcut (bool): Whether to use shortcut connections in C3k blocks.
        rr   r   z-Dimension of ABlock must be a multiple of 32.r   ç{®Gáz„?TrN  Nc              3  óŒ   •K  — | ];  }‰r&t        j                  ˆˆˆfd „t        d«      D «       Ž nt        ‰‰d‰‰«      –— Œ= y­w)c              3  ó@   •K  — | ]  }t        ‰‰d z  ‰‰«      –— Œ y­w)rr   N)r#  )r“   rT   r  rm   r(  s     €€€rK   r–   z+A2C2f.__init__.<locals>.<genexpr>.<genexpr>>  s    øè ø€ ÒTÀaœF 2 r¨R¡x°¸D×AÑTùrì   rO   N)r<   rÀ   r™   rÀ  )r“   rT   Úa2r  rm   rÎ   r(  r    s     €€€€€€rK   r–   z!A2C2f.__init__.<locals>.<genexpr>=  sI   øè ø€ ò 
ð ñ ô �M‰MÕTÌ5ÐQRË8ÔTÑUä�R˜˜Q ¨!Ó,ó-ñ
ùs   ƒAA)r:   r;   rX   r   rh   rk   r<   rC   r@   r1  Úgammar˜   r™   rš   )rH   rG   rn   rž   r6  r  Úresidualr(  rÊ   rÎ   r    rm   rJ   s       `` ` ``@€rK   r;   zA2C2f.__init__  s¬   þ€ ô6 	‰ÑÔÜ��a‘‹[ˆØ�B‰w˜!Š|ÐLÐLÓLˆ|ä˜˜B  1Ó%ˆŒÜ˜˜Q™ "™ b¨!Ó,ˆŒáPRÑW_”R—\‘\ $¬¯©°B«Ñ"7ÀtÕLÐeiˆŒ
Ü—‘÷ 
ð 
ô ˜1“Xô	
ó 
ˆ�rL   c                óL  ‡— | j                  |«      gŠ‰j                  ˆfd„| j                  D «       «       | j                  t	        j
                  ‰d«      «      Š| j                  �;|| j                  j                  d| j                  j                  d   dd«      ‰z  z   S ‰S )z³Forward pass through A2C2f layer.

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

        Returns:
            (torch.Tensor): Output tensor after processing.
        c              3  ó4   •K  — | ]  } |‰d    «      –— Œ y­wr£   r’   r¥   s     €rK   r–   z A2C2f.forward.<locals>.<genexpr>N  r§   r¨   r   r¤   r   )	rh   r©   rš   rk   r@   rŠ   r7  rD   rP   rª   s     @rK   rV   zA2C2f.forwardD  sƒ   ø€ ð �X‰X�a‹[ˆMˆØ	�‰Ó* 4§6¡6Ô*Ô*Ø�H‰H”U—Y‘Y˜q !“_Ó%ˆØ�:‰:Ð!Ø�t—z‘z—‘ r¨4¯:©:×+;Ñ+;¸AÑ+>ÀÀ1ÓEÈÑIÑIÐIØˆrL   )r   Tr   Fg       @rÖ   r   T)rG   rX   rn   rX   rž   rX   r6  r«   r  rX   r8  r«   r(  rB   rÊ   rB   rÎ   rX   r    r«   rY   r\   rb   s   @rK   r1  r1    s�   ø„ ñð4 ØØØØØØØð(
àð(
ð ð(
ð ð	(
ð
 ð(
ð ð(
ð ð(
ð ð(
ð ð(
ð ð(
ð õ(
÷TrL   r1  c                  ó.   ‡ — e Zd ZdZddˆ fd„Zdd„Zˆ xZS )Ú	SwiGLUFFNz@SwiGLU Feed-Forward Network for transformer-based architectures.c                ó    •— t         ‰| �  «        t        j                  |||z  «      | _        t        j                  ||z  dz  |«      | _        y)zâInitialize SwiGLU FFN with input dimension, output dimension, and expansion factor.

        Args:
            gc (int): Guide channels.
            ec (int): Embedding channels.
            e (int): Expansion factor.
        rO   N)r:   r;   r<   r-  Úw12Úw3)rH   r3  rœ   rÊ   rJ   s       €rK   r;   zSwiGLUFFN.__init__X  s@   ø€ ô 	‰ÑÔÜ—9‘9˜R  R¡Ó(ˆŒÜ—)‘)˜A ™F a™K¨Ó,ˆ�rL   c                ó¢   — | j                  |«      }|j                  dd¬«      \  }}t        j                  |«      |z  }| j	                  |«      S )z.Apply SwiGLU transformation to input features.rO   r¤   r†   )r>  rÓ   rˆ   Úsilur?  )rH   rI   Úx12rŒ   r‹   Úhiddens         rK   rV   zSwiGLUFFN.forwardd  sD   € à�h‰h�q‹kˆØ—‘˜1 "�Ó%‰ˆˆBÜ—‘˜“˜b‘ˆØ�w‰w�v‹ÐrL   )rN   )r3  rX   rœ   rX   rÊ   rX   r[   rÖ  rY   r\   rb   s   @rK   r<  r<  U  s   ø„ ÙJö
-÷rL   r<  c                  ó,   ‡ — e Zd ZdZdˆ fd„Zdd„Zˆ xZS )ÚResidualz7Residual connection wrapper for neural network modules.c                ó$  •— t         ‰| �  «        || _        t        j                  j                  | j                  j                  j                  «       t        j                  j                  | j                  j                  j                  «       y)z�Initialize residual module with the wrapped module.

        Args:
            m (nn.Module): Module to wrap with residual connection.
        N)	r:   r;   rš   r<   r,  Úzeros_r?  r7   rE   )rH   rš   rJ   s     €rK   r;   zResidual.__init__o  sS   ø€ ô 	‰ÑÔØˆŒÜ
�‰�‰�t—v‘v—y‘y—~‘~Ô&ô 	�‰�‰�t—v‘v—y‘y×'Ñ'Õ(rL   c                ó*   — || j                  |«      z   S )z,Apply residual connection to input features.rº   rp   s     rK   rV   zResidual.forward|  s   € à�4—6‘6˜!“9‰}ÐrL   )rš   r¬   r[   rÖ  rY   r\   rb   s   @rK   rE  rE  l  s   ø„ ÙAõ)÷rL   rE  c                  ó,   ‡ — e Zd ZdZdˆ fd„Zdd„Zˆ xZS )ÚSAVPEzESpatial-Aware Visual Prompt Embedding module for feature enhancement.c           	     ó–  •‡— t         ‰| �  «        t        j                  ˆfd„t	        |«      D «       «      | _        t        j                  ˆfd„t	        |«      D «       «      | _        d| _        t        j                  d‰z  |d«      | _	        t        j                  d‰z  | j                  dd¬«      | _
        t        j                  d| j                  dd¬«      | _        t        j                  t        d| j                  z  | j                  d«      t        j                  | j                  | j                  dd¬«      «      | _        y)	a  Initialize SAVPE module with channels, intermediate channels, and embedding dimension.

        Args:
            ch (list[int]): List of input channel dimensions.
            c3 (int): Intermediate channels.
            embed (int): Embedding dimension.
        c           	   3  óÜ   •K  — | ]c  \  }}t        j                  t        |‰d «      t        ‰‰d «      |dv rt        j                  |dz  ¬«      nt        j                  «       «      –— Œe y­w)re   ¾   r   rO   rO   ©Úscale_factorN©r<   rÀ   r   ÚUpsamplerö   ©r“   r”   rI   r  s      €rK   r–   z!SAVPE.__init__.<locals>.<genexpr>�  sa   øè ø€ ò !
ñ ��1ô �M‰MÜ�Q˜˜A“¤ R¨¨Q£ÐTUÐY_ÑT_´·±È!ÈaÉ%Õ1PÔeg×epÑepÓer÷ñ!
ùs   ƒA)A,c              3  óÄ   •K  — | ]W  \  }}t        j                  t        |‰d «      |dv rt        j                  |dz  ¬«      nt        j                  «       «      –— ŒY y­w)r   rM  rO   rN  NrP  rR  s      €rK   r–   z!SAVPE.__init__.<locals>.<genexpr>”  sP   øè ø€ ò !
á��1ô �M‰Mœ$˜q " a›.ÈQÐRXÉ[¬"¯+©+À1ÀqÁ5Õ*IÔ^`×^iÑ^iÓ^k×lñ!
ùs   ƒAA rW   re   r   )ry   rO   N)r:   r;   r<   r˜   r¬  rh   rk   rÌ   r=   rl   r  rš  rÀ   r   Úcv6)rH   rZ  r  r=  rJ   s     ` €rK   r;   zSAVPE.__init__„  sò   ù€ ô 	‰ÑÔÜ—=‘=ó !
ô " "›ô	!
ó 
ˆŒô —=‘=ó !
ä! "›ô!
ó 
ˆŒð
 ˆŒÜ—9‘9˜Q ™V U¨AÓ.ˆŒÜ—9‘9˜Q ™V T§V¡V¨Q¸Ô:ˆŒÜ—9‘9˜Q §¡¨°1Ô5ˆŒÜ—=‘=¤ a¨$¯&©&¡j°$·&±&¸!Ó!<¼b¿i¹iÈÏÉÐPT×PVÑPVÐXYÐcdÔ>eÓfˆ�rL   c                ó˜  — t        |«      D ��cg c]  \  }} | j                  |   |«      ‘Œ }}}| j                  t        j                  |d¬«      «      }t        |«      D ��cg c]  \  }} | j
                  |   |«      ‘Œ }}}| j                  t        j                  |d¬«      «      }|j                  \  }}}}	|j                  d   }
|j                  ||d«      }|j                  |d| j                  ||	«      j                  d|
ddd«      j                  ||
z  | j                  ||	«      }|j                  ||
d||	«      j                  ||
z  d||	«      }| j                  t        j                  || j                  |«      fd¬«      «      }|j                  ||
| j                  d«      }|j                  ||
dd«      }||z  t        j                  |«      t        j                  |j                   «      j"                  z  z   }t%        j&                  |d¬«      j)                  |j                   «      }|j+                  dd«      |j                  || j                  || j                  z  d«      j+                  dd«      z  }t%        j,                  |j+                  dd«      j                  ||
d«      dd¬«      S c c}}w c c}}w )zJProcess input features and visual prompts to generate enhanced embeddings.r   r†   r¤   rè  éýÿÿÿrO   rl  )r¬  rk   r  r@   rŠ   rh   rl   rP   rD   r_  rÌ   ÚexpandrT  rš  Úlogical_notÚfinfor9   Úminrˆ   rR   ÚtorQ   rn  )rH   rI   Úvpr”   Úxir¦   ré  rê  rë  rì  ÚQÚscoreÚ
aggregateds                rK   rV   zSAVPE.forwardŸ  sI  € ä*3°A«,×7¡  Bˆ[ˆT�X‰X�a‰[˜�_Ð7ˆÑ7Ø�H‰H”U—Y‘Y˜q aÔ(Ó)ˆä*3°A«,×7¡  Bˆ[ˆT�X‰X�a‰[˜�_Ð7ˆÑ7Ø�H‰H”U—Y‘Y˜q aÔ(Ó)ˆà—W‘W‰
ˆˆ1ˆa�à�H‰H�Q‰Kˆà�F‰F�1�a˜Óˆà�I‰I�a˜˜DŸF™F A qÓ)×0Ñ0°°Q¸¸BÀÓC×KÑKÈAÐPQÉEÐSW×SYÑSYÐ[\Ð^_Ó`ˆØ�Z‰Z˜˜1˜a  AÓ&×.Ñ.¨q°1©u°a¸¸AÓ>ˆà�H‰H”U—Y‘Y  4§8¡8¨B£<Ð0°aÔ8Ó9ˆà�I‰I�a˜˜DŸF™F BÓ'ˆØ�Z‰Z˜˜1˜a Ó$ˆà�B‘œ×*Ñ*¨2Ó.´·±¸Q¿W¹WÓ1E×1IÑ1IÑIÑIˆÜ—	‘	˜% RÔ(×+Ñ+¨A¯G©GÓ4ˆØ—_‘_ R¨Ó,¨q¯y©y¸¸D¿F¹FÀAÈÏÉÁKÐQSÓ/T×/^Ñ/^Ð_aÐceÓ/fÑfˆ
ä�{‰{˜:×/Ñ/°°BÓ7×?Ñ?ÀÀ1ÀbÓIÈrÐUVÔWÐWùó1 8ùó 8s   �K Á%K)rZ  r£  r  rX   r=  rX   )rI   re  r\  rZ   r[   rZ   r\   rb   s   @rK   rJ  rJ  �  s   ø„ ÙOõg÷6XrL   rJ  c                  ó:   ‡ — e Zd ZdZddˆ fd„Zddˆ fd„Zd„ Zˆ xZS )	ÚProto26zDUltralytics YOLO26 models mask Proto module for segmentation models.c           	     ó:  •‡— t         ‰| �  |||«       t        j                  ˆfd„‰dd D «       «      | _        t        ‰d   |d¬«      | _        t        j                  t        ‰d   |d¬«      t        ||d¬«      t        j                  ||d«      «      | _	        y)ap  Initialize the Ultralytics YOLO models mask Proto module with specified number of protos and masks.

        Args:
            ch (tuple): Tuple of channel sizes from backbone feature maps.
            c_ (int): Intermediate channels.
            c2 (int): Output channels (number of protos).
            nc (int): Number of classes for semantic segmentation.
        c              3  ó@   •K  — | ]  }t        |‰d    d¬«      –— Œ y­w)r   r   rf   Nr¿   )r“   rI   rZ  s     €rK   r–   z#Proto26.__init__.<locals>.<genexpr>É  s!   øè ø€ Ò(MÀ¬¨a°°A±¸!×)<Ð)<Ñ(Mùrì   r   Nr   re   rf   )
r:   r;   r<   r˜   Úfeat_refiner   Ú	feat_fuserÀ   r=   Úsemseg)rH   rZ  rm   rn   ÚncrJ   s    `   €rK   r;   zProto26.__init__¿  s�   ù€ ô 	‰Ñ˜˜R Ô$ÜŸ=™=Ó(MÀbÈÈÀfÔ(MÓMˆÔÜ˜b ™e R¨1Ô-ˆŒÜ—m‘m¤D¨¨A©°°aÔ$8¼$¸rÀ2ÈÔ:KÌRÏYÉYÐWYÐ[]Ð_`ÓMaÓbˆ�rL   c                ó>  •— |d   }t        | j                  «      D ]=  \  }} |||dz      «      }t        j                  ||j                  dd d¬«      }||z   }Œ? t
        ‰	| �  | j                  |«      «      }| j                  r|r| j                  |«      }||fS |S )zUPerform a forward pass by fusing multi-scale feature maps and generating proto masks.r   r   rO   Nr¨  r©  )
r¬  re  rˆ   r­  rP   r:   rV   rf  Útrainingrg  )
rH   rI   Úreturn_semsegÚfeatr”   ÚfÚup_featr  rg  rJ   s
            €rK   rV   zProto26.forwardÍ  sŸ   ø€ à�‰tˆÜ˜d×.Ñ.Ó/ò 	"‰DˆAˆqÙ˜˜!˜a™%™“kˆGÜ—m‘m G°$·*±*¸Q¸R°.ÀyÔQˆGØ˜'‘>‰Dð	"ô ‰G‰O˜DŸN™N¨4Ó0Ó1ˆØ�=Š=™]Ø—[‘[ Ó&ˆFØ�v�;ÐØˆrL   c                ó   — d| _         y)zHFuse the model for inference by removing the semantic segmentation head.N)rg  rx  s    rK   ry  zProto26.fuseÚ  s	   € àˆ�rL   )r’   rq   rr   éP   )rZ  Útuplerm   rX   rn   rX   rh  rX   )T)rI   rZ   rk  r«   r[   rZ   )r]   r^   r_   r`   r;   rV   ry  ra   rb   s   @rK   rb  rb  ¼  s   ø„ ÙNöcöörL   rb  c                  ód   ‡ — e Zd ZdZed„ «       Zed„ «       Zed„ «       Zˆ fd„Z	d„ Z
d„ Zd„ Zˆ xZS )	ÚRealNVPz¼RealNVP: a flow-based generative model.

    References:
        https://arxiv.org/abs/1605.08803
        https://github.com/open-mmlab/mmpose/blob/main/mmpose/models/utils/realnvp.py
    c            
     ó  — t        j                  t        j                  dd«      t        j                  «       t        j                  dd«      t        j                  «       t        j                  dd«      t        j                  «       «      S )z3Get the scale model in a single invertible mapping.rO   r»  )r<   rÀ   r-  r  ÚTanhr’   rL   rK   ÚnetszRealNVP.netsç  sY   € ô �}‰}œRŸY™Y q¨"Ó-¬r¯w©w«y¼"¿)¹)ÀBÈÓ:KÌRÏWÉWËYÔXZ×XaÑXaÐbdÐfgÓXhÔjl×jqÑjqÓjsÓtÐtrL   c            
     óô   — t        j                  t        j                  dd«      t        j                  «       t        j                  dd«      t        j                  «       t        j                  dd«      «      S )z9Get the translation model in a single invertible mapping.rO   r»  )r<   rÀ   r-  r  r’   rL   rK   ÚnettzRealNVP.nettì  sM   € ô �}‰}œRŸY™Y q¨"Ó-¬r¯w©w«y¼"¿)¹)ÀBÈÓ:KÌRÏWÉWËYÔXZ×XaÑXaÐbdÐfgÓXhÓiÐirL   c                ój   — t         j                  j                  | j                  | j                  «      S )zThe prior distribution.)r@   ÚdistributionsÚMultivariateNormalÚlocÚcovrx  s    rK   ÚpriorzRealNVP.priorñ  s%   € ô ×"Ñ"×5Ñ5°d·h±hÀÇÁÓIÐIrL   c                óÖ  •— t         ‰| �  «        | j                  dt        j                  d«      «       | j                  dt        j
                  d«      «       | j                  dt        j                  ddgddggdz  t        j                  ¬«      «       t        j                  j                  t        t        | j                  «      «      D �cg c]  }| j                  «       ‘Œ c}«      | _        t        j                  j                  t        t        | j                  «      «      D �cg c]  }| j                  «       ‘Œ c}«      | _        | j#                  «        y c c}w c c}w )	Nr|  rO   r}  Úmaskr   r   re   r8   )r:   r;   Úregister_bufferr@   r/  ÚeyerU  Úfloat32r<   r˜   r™   r°   r€  rv  r  rx  ÚtÚinit_weights)rH   rT   rJ   s     €rK   r;   zRealNVP.__init__ö  sì   ø€ Ü‰ÑÔà×Ñ˜U¤E§K¡K°£NÔ3Ø×Ñ˜U¤E§I¡I¨a£LÔ1Ø×Ñ˜V¤U§\¡\°A°q°6¸A¸q¸6Ð2BÀQÑ2FÌeÏmÉmÔ%\Ô]ä—‘×$Ñ$¼5ÄÀTÇYÁYÃÓ;PÖ%Q°a d§i¡i¥kÒ%QÓRˆŒÜ—‘×$Ñ$¼5ÄÀTÇYÁYÃÓ;PÖ%Q°a d§i¡i¥kÒ%QÓRˆŒØ×ÑÕùò &RùÚ%Qs   ÃE!Ä-E&c                óº   — | j                  «       D ]H  }t        |t        j                  «      sŒt        j                  j                  |j                  d¬«       ŒJ y)zInitialize model weights.r3  )ÚgainN)Úmodulesr  r<   r-  r,  Úxavier_uniform_rE   )rH   rš   s     rK   r…  zRealNVP.init_weights  s@   € à—‘“ò 	=ˆAÜ˜!œRŸY™YÕ'Ü—‘×'Ñ'¨¯©°tÐ'Õ<ñ	=rL   c                óô  — |j                  |j                  d   «      |}}t        t        t	        | j
                  «      «      «      D ]«  }| j                  |   |z  } | j                  |   |«      d| j                  |   z
  z  } | j
                  |   |«      d| j                  |   z
  z  }d| j                  |   z
  ||z
  z  t        j                  | «      z  |z   }||j                  d¬«      z  }Œ­ ||fS )z€Apply mapping from the data space to the latent space and calculate the log determinant of the Jacobian
        matrix.
        r   r   r†   )Ú	new_zerosrP   Úreversedr™   r°   r„  r€  r  r@   ro  r¡  )rH   rI   Úlog_det_jacobÚzr”   Úz_r  r„  s           rK   Ú
backward_pzRealNVP.backward_p  së   € ð Ÿ;™; q§w¡w¨q¡zÓ2°A�qˆÜœ%¤ D§F¡F£Ó,Ó-ò 	*ˆAØ—‘˜1‘ Ñ!ˆBØ�—‘�q‘	˜"“  T§Y¡Y¨q¡\Ñ!1Ñ2ˆAØ�—‘�q‘	˜"“  T§Y¡Y¨q¡\Ñ!1Ñ2ˆAØ�T—Y‘Y˜q‘\Ñ! a¨!¡eÑ,¬u¯y©y¸!¸«}Ñ<¸rÑAˆAØ˜QŸU™U q˜U›\Ñ)‰Mð	*ð �-ÐÐrL   c                ó.  — |j                   t        j                  k(  rG| j                  d   d   j                  j                   t        j                  k7  r| j                  «        | j                  |«      \  }}| j                  j                  |«      |z   S )z<Calculate the log probability of given sample in data space.r   )	r9   r@   rƒ  r  rE   rB   r�  r~  Úlog_prob)rH   rI   rŽ  Úlog_dets       rK   r’  zRealNVP.log_prob  sj   € à�7‰7”e—m‘mÒ#¨¯©¨q©	°!©×(;Ñ(;×(AÑ(AÄUÇ]Á]Ò(RØ�J‰JŒLØ—_‘_ QÓ'‰
ˆˆ7Ø�z‰z×"Ñ" 1Ó%¨Ñ/Ð/rL   )r]   r^   r_   r`   r|  rv  rx  Úpropertyr~  r;   r…  r�  r’  ra   rb   s   @rK   rs  rs  ß  s^   ø„ ñð ñuó ðuð ñjó ðjð ñJó ðJô	ò=ò ö0rL   rs  )Lr`   Ú
__future__r   r@   Útorch.nnr<   Útorch.nn.functionalr‘  rˆ   Úultralytics.utils.torch_utilsr   r?   r   r   r   r	   r
   r   Útransformerr   Ú__all__ÚModuler   r-   r+   r*   r   r   r   r   r   r   r%   r.   r   r#   r)   r   r   r  r1   r)  r    r,   r(   r   r~  r�  r/   r   r   r   r   r'   r&   r³  r$   rÀ  r0   r   r!   r   r¿  r   r   r"   r2   r3   r  r#  r1  r<  rE  rJ  rb  rs  r’   rL   rK   ú<module>rœ     s™  ðá å "ã Ý ß Ð å :ç F× FÝ )ð(€ôV\ˆ"�)‰)ô \ô2>ˆB�I‰Iô >ô,!ˆR�Y‰Yô !ôH)(ˆb�i‰iô )(ôXDˆ"�)‰)ô Dô.;ˆ2�9‰9ô ;ô@ˆ�‰ô ô*6ˆ�‰ô 6ô6)ˆ"�)‰)ô )ôDJˆ�‰ô Jô4xˆ"ô xô&;ˆB�I‰Iô ;ô00ˆ2ô 0ô&Mˆbô Mô&/�b—i‘iô /ô8P�—‘ô Pô6C�B—I‘Iô Cô>J�"—)‘)ô Jô0�"—)‘)ô ô>1$˜"Ÿ)™)ô 1$ôh?)ˆb�i‰iô ?)ôD>%�r—y‘yô >%ôB6�b—i‘iô 6ô4.6˜Ÿ	™	ô .6ôb,�Jô ,ô*_ˆRô _ô&)�2—9‘9ô )ôB1ˆLô 1ô(ˆB�I‰Iô ô&&ˆB�I‰Iô &ô2)ˆb�i‰iô )ô63ˆr�y‰yô 3ô.<ˆR�Y‰Yô <ô4)ˆ"�)‰)ô )ô8%
ˆ3ô %
ôPfˆ"ô fô*>ˆu�x‰x�‰ô >ôB*<ˆ"�)‰)ô *<ôZ^ˆSô ^ô>9�—	‘	ô 9ôx/ˆr�y‰yô /ôd4.ˆ"�)‰)ô 4.ôn4.ˆB�I‰Iô 4.ôn$sˆSô $sôN-%ˆR�Y‰Yô -%ô`<�"—)‘)ô <ô~VˆB�I‰Iô Vôr>ˆR�Y‰Yô >ôBOˆB�I‰Iô Oôd�—	‘	ô ô.ˆr�y‰yô ô*8XˆB�I‰Iô 8Xôv ˆeô  ôF:0ˆb�i‰iõ :0rL   