§
    ezniæ1  ã                   ó  — d Z ddlZddlZddlZddlmZ dZd d„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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dS )!zConvolution modules.é    N)ÚConvÚConv2Ú	LightConvÚDWConvÚDWConvTranspose2dÚConvTransposeÚFocusÚ	GhostConvÚChannelAttentionÚSpatialAttentionÚCBAMÚConcatÚRepConvé   c                 óÀ   ‡— ‰dk    r.t          | t          ¦  «        r‰| dz
  z  dz   nˆfd„| D ¦   «         } |€&t          | t          ¦  «        r| dz  nd„ | D ¦   «         }|S )zPad to 'same' shape outputs.r   c                 ó&   •— g | ]}‰|d z
  z  d z   ‘ŒS ©r   © )Ú.0ÚxÚds     €ú{/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/ultralytics/nn/modules/conv.pyú
<listcomp>zautopad.<locals>.<listcomp>   s%   ø€ Ð7SÐ7SÐ7SÈA¸¸QÀ¹U¹Àa¹Ð7SÐ7SÐ7Só    Né   c                 ó   — g | ]}|d z  ‘ŒS ©r   r   ©r   r   s     r   r   zautopad.<locals>.<listcomp>   s   € Ð.AÐ.AÐ.A¸!¨q°A©vÐ.AÐ.AÐ.Ar   )Ú
isinstanceÚint)ÚkÚpr   s     `r   Úautopadr#      s{   ø€ àˆ1‚u€uÝ)¨!­SÑ1Ô1ÐSˆA��Q‘‰K˜!‰OˆOÐ7SÐ7SÐ7SÐ7SÐQRÐ7SÑ7SÔ7SˆØ€yÝ  ¥CÑ(Ô(ÐAˆA�‰FˆFÐ.AÐ.A¸qÐ.AÑ.AÔ.AˆØ€Hr   c                   óN   ‡ — e Zd ZdZ ej        ¦   «         Zdˆ fd„	Zd„ Zd„ Z	ˆ xZ
S )	r   zeStandard convolution with args(ch_in, ch_out, kernel, stride, padding, groups, dilation, activation).r   NTc	                 óX  •— t          ¦   «                              ¦   «          t          j        ||||t	          |||¦  «        ||d¬¦  «        | _        t          j        |¦  «        | _        |du r| j        n.t          |t          j
        ¦  «        r|nt          j        ¦   «         | _        dS )ú@Initialize Conv layer with given arguments including activation.F©ÚgroupsÚdilationÚbiasTN)ÚsuperÚ__init__ÚnnÚConv2dr#   ÚconvÚBatchNorm2dÚbnÚdefault_actr   ÚModuleÚIdentityÚact©
ÚselfÚc1Úc2r!   Úsr"   Úgr   r5   Ú	__class__s
            €r   r,   zConv.__init__   s”   ø€ å‰Œ×ÒÑÔÐÝ”I˜b " a¨­G°A°q¸!Ñ,<Ô,<ÀQÐQRÐY^Ð_Ñ_Ô_ˆŒ	Ý”. Ñ$Ô$ˆŒØ'*¨d { {�4Ô#Ð#½zÈ#ÍrÌyÑ?YÔ?YÐ8l¸¸Õ_aÔ_jÑ_lÔ_lˆŒˆˆr   c                 óx   — |                       |                      |                      |¦  «        ¦  «        ¦  «        S ©zFApply convolution, batch normalization and activation to input tensor.©r5   r1   r/   ©r7   r   s     r   ÚforwardzConv.forward"   ó*   € à�xŠx˜Ÿš §	¢	¨!¡¤Ñ-Ô-Ñ.Ô.Ð.r   c                 óR   — |                       |                      |¦  «        ¦  «        S )z*Perform transposed convolution of 2D data.©r5   r/   r@   s     r   Úforward_fusezConv.forward_fuse&   ó   € à�xŠx˜Ÿ	š	 !™œÑ%Ô%Ð%r   )r   r   Nr   r   T©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r-   ÚSiLUr2   r,   rA   rE   Ú__classcell__©r<   s   @r   r   r      st   ø€ € € € € ØoÐoØ�"”'‘)”)€Kðmð mð mð mð mð mð/ð /ð /ð&ð &ð &ð &ð &ð &ð &r   r   c                   ó6   ‡ — e Zd ZdZd
ˆ fd„	Zd„ Zd„ Zd	„ Zˆ xZS )r   z+Simplified RepConv module with Conv fusing.é   r   NTc	                 óº   •— t          ¦   «                              ||||||||¬¦  «         t          j        ||d|t	          d||¦  «        ||d¬¦  «        | _        dS )r&   ©r;   r   r5   r   Fr'   N)r+   r,   r-   r.   r#   Úcv2r6   s
            €r   r,   zConv2.__init__.   s`   ø€ å‰Œ×Ò˜˜R  A q¨A°¸ÐÑ<Ô<Ð<Ý”9˜R  Q¨­7°1°a¸Ñ+;Ô+;ÀAÐPQÐX]Ð^Ñ^Ô^ˆŒˆˆr   c                 ó¤   — |                       |                      |                      |¦  «        |                      |¦  «        z   ¦  «        ¦  «        S r>   )r5   r1   r/   rS   r@   s     r   rA   zConv2.forward3   s9   € à�xŠx˜Ÿš §	¢	¨!¡¤¨t¯xªx¸©{¬{Ñ :Ñ;Ô;Ñ<Ô<Ð<r   c                 óx   — |                       |                      |                      |¦  «        ¦  «        ¦  «        S )zLApply fused convolution, batch normalization and activation to input tensor.r?   r@   s     r   rE   zConv2.forward_fuse7   rB   r   c                 ó”  — t          j        | j        j        j        ¦  «        }d„ |j        dd…         D ¦   «         }| j        j        j                             ¦   «         |dd…dd…|d         |d         dz   …|d         |d         dz   …f<   | j        j        xj        |z  c_        |                      d¦  «         | j	        | _
        dS )zFuse parallel convolutions.c                 ó   — g | ]}|d z  ‘ŒS r   r   r   s     r   r   z$Conv2.fuse_convs.<locals>.<listcomp>>   s   € Ð)Ð)Ð)˜ˆQ�!‰VÐ)Ð)Ð)r   r   Nr   r   rS   )ÚtorchÚ
zeros_liker/   ÚweightÚdataÚshaperS   ÚcloneÚ__delattr__rE   rA   )r7   ÚwÚis      r   Ú
fuse_convszConv2.fuse_convs;   sÀ   € åÔ˜TœYÔ-Ô2Ñ3Ô3ˆØ)Ð)˜QœW Q R Rœ[Ð)Ñ)Ô)ˆØ04´´Ô0D×0JÒ0JÑ0LÔ0Lˆˆ!ˆ!ˆ!ˆQˆQˆQ��!”�Q�q”T˜A‘X�˜q œt A a¤D¨1¡H˜}Ð
,Ñ-ØŒ	ÔÐÔ Ñ"ÐÔØ×Ò˜ÑÔÐØÔ(ˆŒˆˆr   )rP   r   Nr   r   T)	rH   rI   rJ   rK   r,   rA   rE   ra   rM   rN   s   @r   r   r   +   sv   ø€ € € € € Ø5Ð5ð_ð _ð _ð _ð _ð _ð
=ð =ð =ð/ð /ð /ð)ð )ð )ð )ð )ð )ð )r   r   c                   óH   ‡ — e Zd ZdZd ej        ¦   «         fˆ fd„	Zd„ Zˆ xZS )r   z¤
    Light convolution with args(ch_in, ch_out, kernel).

    https://github.com/PaddlePaddle/PaddleDetection/blob/develop/ppdet/modeling/backbones/hgnet_v2.py
    r   c                 ó¨   •— t          ¦   «                              ¦   «          t          ||dd¬¦  «        | _        t	          ||||¬¦  «        | _        dS )r&   r   F©r5   N)r+   r,   r   Úconv1r   Úconv2)r7   r8   r9   r!   r5   r<   s        €r   r,   zLightConv.__init__L   sM   ø€ å‰Œ×ÒÑÔÐÝ˜"˜b !¨Ð/Ñ/Ô/ˆŒ
Ý˜B  A¨3Ð/Ñ/Ô/ˆŒ
ˆ
ˆ
r   c                 óR   — |                       |                      |¦  «        ¦  «        S )z%Apply 2 convolutions to input tensor.)rf   re   r@   s     r   rA   zLightConv.forwardR   s   € à�zŠz˜$Ÿ*š* Q™-œ-Ñ(Ô(Ð(r   )	rH   rI   rJ   rK   r-   ÚReLUr,   rA   rM   rN   s   @r   r   r   E   se   ø€ € € € € ðð ð "#¨¨¬©	¬	ð 0ð 0ð 0ð 0ð 0ð 0ð)ð )ð )ð )ð )ð )ð )r   r   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )r   zDepth-wise convolution.r   Tc           
      ó~   •— t          ¦   «                              ||||t          j        ||¦  «        ||¬¦  «         dS )z8Initialize Depth-wise convolution with given parameters.rR   N©r+   r,   ÚmathÚgcd)r7   r8   r9   r!   r:   r   r5   r<   s          €r   r,   zDWConv.__init__Z   s<   ø€ å‰Œ×Ò˜˜R  A­¬°"°bÑ)9Ô)9¸QÀCÐÑHÔHÐHÐHÐHr   ©r   r   r   T©rH   rI   rJ   rK   r,   rM   rN   s   @r   r   r   W   sM   ø€ € € € € Ø!Ð!ðIð Ið Ið Ið Ið Ið Ið Ið Ið Ir   r   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )r   z!Depth-wise transpose convolution.r   r   c                 ó~   •— t          ¦   «                              ||||||t          j        ||¦  «        ¬¦  «         dS )z9Initialize DWConvTranspose2d class with given parameters.)r(   Nrk   )r7   r8   r9   r!   r:   Úp1Úp2r<   s          €r   r,   zDWConvTranspose2d.__init__b   s<   ø€ å‰Œ×Ò˜˜R  A r¨2µd´h¸rÀ2Ñ6FÔ6FÐÑGÔGÐGÐGÐGr   )r   r   r   r   ro   rN   s   @r   r   r   _   sM   ø€ € € € € Ø+Ð+ðHð Hð Hð Hð Hð Hð Hð Hð Hð Hr   r   c                   óN   ‡ — e Zd ZdZ ej        ¦   «         Zdˆ fd„	Zd„ Zd„ Z	ˆ xZ
S )	r   zConvolution transpose 2d layer.r   r   Tc                 ób  •— t          ¦   «                              ¦   «          t          j        |||||| ¬¦  «        | _        |rt          j        |¦  «        nt          j        ¦   «         | _        |du r| j        n.t          |t          j
        ¦  «        r|nt          j        ¦   «         | _        dS )zRInitialize ConvTranspose2d layer with batch normalization and activation function.©r*   TN)r+   r,   r-   ÚConvTranspose2dÚconv_transposer0   r4   r1   r2   r   r3   r5   )	r7   r8   r9   r!   r:   r"   r1   r5   r<   s	           €r   r,   zConvTranspose.__init__k   s–   ø€ å‰Œ×ÒÑÔÐÝ Ô0°°R¸¸A¸qÈ2ÀvÐNÑNÔNˆÔØ(*Ð=•"”. Ñ$Ô$Ð$µ´±´ˆŒØ'*¨d { {�4Ô#Ð#½zÈ#ÍrÌyÑ?YÔ?YÐ8l¸¸Õ_aÔ_jÑ_lÔ_lˆŒˆˆr   c                 óx   — |                       |                      |                      |¦  «        ¦  «        ¦  «        S )zMApplies transposed convolutions, batch normalization and activation to input.)r5   r1   rx   r@   s     r   rA   zConvTranspose.forwardr   s.   € à�xŠx˜Ÿš × 3Ò 3°AÑ 6Ô 6Ñ7Ô7Ñ8Ô8Ð8r   c                 óR   — |                       |                      |¦  «        ¦  «        S )z@Applies activation and convolution transpose operation to input.)r5   rx   r@   s     r   rE   zConvTranspose.forward_fusev   s"   € à�xŠx˜×+Ò+¨AÑ.Ô.Ñ/Ô/Ð/r   )r   r   r   TTrG   rN   s   @r   r   r   g   st   ø€ € € € € Ø)Ð)Ø�"”'‘)”)€Kðmð mð mð mð mð mð9ð 9ð 9ð0ð 0ð 0ð 0ð 0ð 0ð 0r   r   c                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )r	   z"Focus wh information into c-space.r   NTc           	      ó„   •— t          ¦   «                              ¦   «          t          |dz  ||||||¬¦  «        | _        dS )zfInitializes Focus object with user defined channel, convolution, padding, group and activation values.é   rd   N)r+   r,   r   r/   )	r7   r8   r9   r!   r:   r"   r;   r5   r<   s	           €r   r,   zFocus.__init__~   s?   ø€ å‰Œ×ÒÑÔÐÝ˜˜a™  Q¨¨1¨a°SÐ9Ñ9Ô9ˆŒ	ˆ	ˆ	r   c                 óÒ   — |                       t          j        |dddd…ddd…f         |dddd…ddd…f         |dddd…ddd…f         |dddd…ddd…f         fd¦  «        ¦  «        S )zš
        Applies convolution to concatenated tensor and returns the output.

        Input shape is (b,c,w,h) and output shape is (b,4c,w/2,h/2).
        .Nr   r   )r/   rX   Úcatr@   s     r   rA   zFocus.forward„   s›   € ð �yŠy�œ A c¨3¨3¨Q¨3°°°!° mÔ$4°a¸¸Q¸TÀ¸TÀ3À3ÀQÀ3¸Ô6GÈÈ3ÐPSÐPSÐRSÐPSÐUVÐUYÐXYÐUYÈ>ÔIZÐ\]Ð^aÐcdÐcgÐfgÐcgÐijÐimÐlmÐimÐ^mÔ\nÐ#oÐqrÑsÔsÑtÔtÐtr   )r   r   Nr   T©rH   rI   rJ   rK   r,   rA   rM   rN   s   @r   r	   r	   {   sY   ø€ € € € € Ø,Ð,ð:ð :ð :ð :ð :ð :ðuð uð uð uð uð uð ur   r	   c                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )r
   z:Ghost Convolution https://github.com/huawei-noah/ghostnet.r   Tc           	      ó¾   •— t          ¦   «                              ¦   «          |dz  }t          ||||d||¬¦  «        | _        t          ||ddd||¬¦  «        | _        dS )zƒInitializes the GhostConv object with input channels, output channels, kernel size, stride, groups and
        activation.
        r   Nrd   é   r   )r+   r,   r   Úcv1rS   )	r7   r8   r9   r!   r:   r;   r5   Úc_r<   s	           €r   r,   zGhostConv.__init__‘   sd   ø€ õ 	‰Œ×ÒÑÔÐØ�1‰WˆÝ˜˜B  1 d¨A°3Ð7Ñ7Ô7ˆŒÝ˜˜B  1 d¨B°CÐ8Ñ8Ô8ˆŒˆˆr   c                 ó€   — |                       |¦  «        }t          j        ||                      |¦  «        fd¦  «        S )zJForward propagation through a Ghost Bottleneck layer with skip connection.r   )r„   rX   r   rS   )r7   r   Úys      r   rA   zGhostConv.forwardš   s2   € à�HŠH�Q‰KŒKˆÝŒy˜!˜TŸXšX a™[œ[Ð)¨1Ñ-Ô-Ð-r   rn   r€   rN   s   @r   r
   r
   Ž   sR   ø€ € € € € ØDÐDð9ð 9ð 9ð 9ð 9ð 9ð.ð .ð .ð .ð .ð .ð .r   r
   c                   óf   ‡ — e Zd ZdZ ej        ¦   «         Zdˆ fd„	Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zˆ xZS )r   z½
    RepConv is a basic rep-style block, including training and deploy status.

    This module is used in RT-DETR.
    Based on https://github.com/DingXiaoH/RepVGG/blob/main/repvgg.py
    rP   r   TFc           	      óØ  •— t          ¦   «                              ¦   «          |dk    r|dk    sJ ‚|| _        || _        || _        |du r| j        n.t          |t          j        ¦  «        r|nt          j	        ¦   «         | _
        |	r!||k    r|dk    rt          j        |¬¦  «        nd| _        t          ||||||d¬¦  «        | _        t          ||d|||dz  z
  |d¬¦  «        | _        dS )	zXInitializes Light Convolution layer with inputs, outputs & optional activation function.rP   r   T)Únum_featuresNF)r"   r;   r5   r   )r+   r,   r;   r8   r9   r2   r   r-   r3   r4   r5   r0   r1   r   re   rf   )r7   r8   r9   r!   r:   r"   r;   r   r5   r1   Údeployr<   s              €r   r,   zRepConv.__init__©   sñ   ø€ å‰Œ×ÒÑÔÐØ�AŠvˆv˜!˜qš&˜&˜&Ð ØˆŒØˆŒØˆŒØ'*¨d { {�4Ô#Ð#½zÈ#ÍrÌyÑ?YÔ?YÐ8l¸¸Õ_aÔ_jÑ_lÔ_lˆŒà57ÐY¸BÀ"ºH¸HÈÈaÊÈ•"”.¨bÐ1Ñ1Ô1Ð1ÐUYˆŒÝ˜"˜b ! Q¨!¨q°eÐ<Ñ<Ô<ˆŒ
Ý˜"˜b ! Q¨1¨q°A©v©:¸!ÀÐGÑGÔGˆŒ
ˆ
ˆ
r   c                 óR   — |                       |                      |¦  «        ¦  «        S )úForward process.rD   r@   s     r   rE   zRepConv.forward_fuse¶   rF   r   c                 óÀ   — | j         €dn|                       |¦  «        }|                      |                      |¦  «        |                      |¦  «        z   |z   ¦  «        S )r�   Nr   )r1   r5   re   rf   )r7   r   Úid_outs      r   rA   zRepConv.forwardº   sK   € à”g�o��¨4¯7ª7°1©:¬:ˆØ�xŠx˜Ÿ
š
 1™œ¨¯
ª
°1©¬Ñ5¸Ñ>Ñ?Ô?Ð?r   c                 óö   — |                       | j        ¦  «        \  }}|                       | j        ¦  «        \  }}|                       | j        ¦  «        \  }}||                      |¦  «        z   |z   ||z   |z   fS )zjReturns equivalent kernel and bias by adding 3x3 kernel, 1x1 kernel and identity kernel with their biases.)Ú_fuse_bn_tensorre   rf   r1   Ú_pad_1x1_to_3x3_tensor)r7   Ú	kernel3x3Úbias3x3Ú	kernel1x1Úbias1x1ÚkernelidÚbiasids          r   Úget_equivalent_kernel_biasz"RepConv.get_equivalent_kernel_bias¿   s   € à!×1Ò1°$´*Ñ=Ô=Ñˆ	�7Ø!×1Ò1°$´*Ñ=Ô=Ñˆ	�7Ø×/Ò/°´Ñ8Ô8Ñˆ�&Ø˜4×6Ò6°yÑAÔAÑAÀHÑLÈgÐX_ÑN_ÐbhÑNhÐhÐhr   c                 óX   — |€dS t           j        j                             |g d¢¦  «        S )z"Pads a 1x1 tensor to a 3x3 tensor.Nr   )r   r   r   r   )rX   r-   Ú
functionalÚpad)r7   r•   s     r   r’   zRepConv._pad_1x1_to_3x3_tensorÆ   s,   € àÐØ�1å”8Ô&×*Ò*¨9°l°l°lÑCÔCÐCr   c                 ó  — |€dS t          |t          ¦  «        rI|j        j        }|j        j        }|j        j        }|j        j        }|j        j        }|j        j        }nåt          |t          j
        ¦  «        rËt          | d¦  «        s‘| j        | j        z  }t          j        | j        |ddft          j        ¬¦  «        }	t#          | j        ¦  «        D ]}
d|	|
|
|z  ddf<   Œt%          j        |	¦  «                             |j        j        ¦  «        | _        | j        }|j        }|j        }|j        }|j        }|j        }||z                        ¦   «         }||z                       dddd¦  «        }||z  |||z  |z  z
  fS )zbGenerates appropriate kernels and biases for convolution by fusing branches of the neural network.N)r   r   Ú	id_tensorrP   )Údtyper   éÿÿÿÿ)r   r   r/   rZ   r1   Úrunning_meanÚrunning_varr*   Úepsr-   r0   Úhasattrr8   r;   ÚnpÚzerosÚfloat32ÚrangerX   Ú
from_numpyÚtoÚdevicerž   ÚsqrtÚreshape)r7   ÚbranchÚkernelr¡   r¢   ÚgammaÚbetar£   Ú	input_dimÚkernel_valuer`   ÚstdÚts                r   r‘   zRepConv._fuse_bn_tensorÍ   sƒ  € àˆ>Ø�4Ý�f�dÑ#Ô#ð 	Ø”[Ô'ˆFØ!œ9Ô1ˆLØ œ)Ô/ˆKØ”IÔ$ˆEØ”9”>ˆDØ”)”-ˆCˆCÝ˜¥¤Ñ/Ô/ð 	Ý˜4 Ñ-Ô-ð YØ œG t¤vÑ-�	Ý!œx¨¬°)¸QÀÐ(BÍ"Ì*ÐUÑUÔU�Ý˜tœw™œð =ð =�AØ;<�L  A¨	¡M°1°aÐ!7Ñ8Ð8Ý!&Ô!1°,Ñ!?Ô!?×!BÒ!BÀ6Ä=ÔCWÑ!XÔ!X�”Ø”^ˆFØ!Ô.ˆLØ Ô,ˆKØ”MˆEØ”;ˆDØ”*ˆCØ˜SÑ ×&Ò&Ñ(Ô(ˆØ�S‰[×!Ò! " a¨¨AÑ.Ô.ˆØ˜‰z˜4 ,°Ñ"6¸Ñ"<Ñ<Ð<Ð<r   c           
      ób  — t          | d¦  «        rdS |                      ¦   «         \  }}t          j        | j        j        j        | j        j        j        | j        j        j        | j        j        j	        | j        j        j
        | j        j        j        | j        j        j        d¬¦  «                             d¦  «        | _        || j        j        _        || j        j        _        |                      ¦   «         D ]}|                     ¦   «          Œ|                      d¦  «         |                      d¦  «         t          | d¦  «        r|                      d¦  «         t          | d	¦  «        r|                      d	¦  «         t          | d
¦  «        r|                      d
¦  «         dS dS )zaCombines two convolution layers into a single layer and removes unused attributes from the class.r/   NT)Úin_channelsÚout_channelsÚkernel_sizeÚstrideÚpaddingr)   r(   r*   Fre   rf   Únmr1   rž   )r¤   r™   r-   r.   re   r/   r·   r¸   r¹   rº   r»   r)   r(   Úrequires_grad_rZ   r[   r*   Ú
parametersÚdetach_r^   )r7   r¯   r*   Úparas       r   ra   zRepConv.fuse_convsé   s�  € å�4˜Ñ Ô ð 	ØˆFØ×6Ò6Ñ8Ô8‰ˆ�Ý”I¨$¬*¬/Ô*EØ+/¬:¬?Ô+GØ*.¬*¬/Ô*EØ%)¤Z¤_Ô%;Ø&*¤j¤oÔ&=Ø'+¤z¤Ô'?Ø%)¤Z¤_Ô%;Ø#'ð)ñ )ô )÷ *8ª¸Ñ)>Ô)>ð 	Œ	ð !'ˆŒ	ÔÔØ"ˆŒ	ŒÔØ—O’OÑ%Ô%ð 	ð 	ˆDØ�LŠL‰NŒNˆNˆNØ×Ò˜Ñ!Ô!Ð!Ø×Ò˜Ñ!Ô!Ð!Ý�4˜ÑÔð 	#Ø×Ò˜TÑ"Ô"Ð"Ý�4˜ÑÔð 	#Ø×Ò˜TÑ"Ô"Ð"Ý�4˜Ñ%Ô%ð 	*Ø×Ò˜[Ñ)Ô)Ð)Ð)Ð)ð	*ð 	*r   )rP   r   r   r   r   TFF)rH   rI   rJ   rK   r-   rL   r2   r,   rE   rA   r™   r’   r‘   ra   rM   rN   s   @r   r   r       s¿   ø€ € € € € ðð ð �"”'‘)”)€KðHð Hð Hð Hð Hð Hð&ð &ð &ð@ð @ð @ð
ið ið iðDð Dð Dð=ð =ð =ð8*ð *ð *ð *ð *ð *ð *r   r   c                   óP   ‡ — e Zd ZdZdeddfˆ fd„Zdej        dej        fd„Zˆ xZ	S )r   zaChannel-attention module https://github.com/open-mmlab/mmdetection/tree/v3.0.0rc1/configs/rtmdet.ÚchannelsÚreturnNc                 óè   •— t          ¦   «                              ¦   «          t          j        d¦  «        | _        t          j        ||dddd¬¦  «        | _        t          j        ¦   «         | _        dS )zXInitializes the class and sets the basic configurations and instance variables required.r   r   Trv   N)	r+   r,   r-   ÚAdaptiveAvgPool2dÚpoolr.   ÚfcÚSigmoidr5   )r7   rÂ   r<   s     €r   r,   zChannelAttention.__init__  sZ   ø€ å‰Œ×ÒÑÔÐÝÔ(¨Ñ+Ô+ˆŒ	Ý”)˜H h°°1°a¸dÐCÑCÔCˆŒÝ”:‘<”<ˆŒˆˆr   r   c                 ó~   — ||                       |                      |                      |¦  «        ¦  «        ¦  «        z  S )ziApplies forward pass using activation on convolutions of the input, optionally using batch normalization.)r5   rÇ   rÆ   r@   s     r   rA   zChannelAttention.forward  s/   € à�4—8’8˜DŸGšG D§I¢I¨a¡L¤LÑ1Ô1Ñ2Ô2Ñ2Ð2r   )
rH   rI   rJ   rK   r    r,   rX   ÚTensorrA   rM   rN   s   @r   r   r     sw   ø€ € € € € ØkÐkð  ð  ¨ð  ð  ð  ð  ð  ð  ð3˜œð 3¨%¬,ð 3ð 3ð 3ð 3ð 3ð 3ð 3ð 3r   r   c                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )r   zSpatial-attention module.é   c                 óä   •— t          ¦   «                              ¦   «          |dv s
J d¦   «         ‚|dk    rdnd}t          j        dd||d¬¦  «        | _        t          j        ¦   «         | _        d	S )
z>Initialize Spatial-attention module with kernel size argument.)rP   rÌ   zkernel size must be 3 or 7rÌ   rP   r   r   F)r»   r*   N)r+   r,   r-   r.   r„   rÈ   r5   )r7   r¹   r»   r<   s      €r   r,   zSpatialAttention.__init__  ss   ø€ å‰Œ×ÒÑÔÐØ˜fÐ$Ð$Ð$Ð&BÑ$Ô$Ð$Ø" aÒ'Ð'�!�!¨QˆÝ”9˜Q  ;¸ÀeÐLÑLÔLˆŒÝ”:‘<”<ˆŒˆˆr   c                 óâ   — ||                       |                      t          j        t          j        |dd¬¦  «        t          j        |dd¬¦  «        d         gd¦  «        ¦  «        ¦  «        z  S )zGApply channel and spatial attention on input for feature recalibration.r   T)Úkeepdimr   )r5   r„   rX   r   ÚmeanÚmaxr@   s     r   rA   zSpatialAttention.forward  sd   € à�4—8’8˜DŸHšH¥U¤Yµ´
¸1¸aÈÐ0NÑ0NÔ0NÕPUÔPYÐZ[Ð]^ÐhlÐPmÑPmÔPmÐnoÔPpÐ/qÐstÑ%uÔ%uÑvÔvÑwÔwÑwÐwr   ©rÌ   r€   rN   s   @r   r   r     sY   ø€ € € € € Ø#Ð#ð ð  ð  ð  ð  ð  ðxð xð xð xð xð xð xr   r   c                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )r   z%Convolutional Block Attention Module.rÌ   c                 ó˜   •— t          ¦   «                              ¦   «          t          |¦  «        | _        t	          |¦  «        | _        dS )z>Initialize CBAM with given input channel (c1) and kernel size.N)r+   r,   r   Úchannel_attentionr   Úspatial_attention)r7   r8   r¹   r<   s      €r   r,   zCBAM.__init__&  s?   ø€ å‰Œ×ÒÑÔÐÝ!1°"Ñ!5Ô!5ˆÔÝ!1°+Ñ!>Ô!>ˆÔÐÐr   c                 óR   — |                       |                      |¦  «        ¦  «        S )z+Applies the forward pass through C1 module.)rÖ   rÕ   r@   s     r   rA   zCBAM.forward,  s$   € à×%Ò% d×&<Ò&<¸QÑ&?Ô&?Ñ@Ô@Ð@r   rÒ   r€   rN   s   @r   r   r   #  sY   ø€ € € € € Ø/Ð/ð?ð ?ð ?ð ?ð ?ð ?ðAð Að Að Að Að Að Ar   r   c                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )r   z.Concatenate a list of tensors along dimension.r   c                 óV   •— t          ¦   «                              ¦   «          || _        dS )z;Concatenates a list of tensors along a specified dimension.N)r+   r,   r   )r7   Ú	dimensionr<   s     €r   r,   zConcat.__init__4  s$   ø€ å‰Œ×ÒÑÔÐØˆŒˆˆr   c                 ó6   — t          j        || j        ¦  «        S )z.Forward pass for the YOLOv8 mask Proto module.)rX   r   r   r@   s     r   rA   zConcat.forward9  s   € åŒy˜˜DœFÑ#Ô#Ð#r   r   r€   rN   s   @r   r   r   1  sR   ø€ € € € € Ø8Ð8ðð ð ð ð ð ð
$ð $ð $ð $ð $ð $ð $r   r   )Nr   )rK   rl   Únumpyr¥   rX   Útorch.nnr-   Ú__all__r#   r3   r   r   r   r   rw   r   r   r	   r
   r   r   r   r   r   r   r   r   ú<module>rß      sË  ðà Ð à €€€à Ð Ð Ð Ø €€€Ø Ð Ð Ð Ð Ð ðP€ðð ð ð ð&ð &ð &ð &ð &ˆ2Œ9ñ &ô &ð &ð()ð )ð )ð )ð )ˆDñ )ô )ð )ð4)ð )ð )ð )ð )�”	ñ )ô )ð )ð$Ið Ið Ið Ið IˆTñ Iô Ið IðHð Hð Hð Hð H˜Ô*ñ Hô Hð Hð0ð 0ð 0ð 0ð 0�B”Iñ 0ô 0ð 0ð(uð uð uð uð uˆBŒIñ uô uð uð&.ð .ð .ð .ð .�”	ñ .ô .ð .ð$a*ð a*ð a*ð a*ð a*ˆbŒiñ a*ô a*ð a*ðH3ð 3ð 3ð 3ð 3�r”yñ 3ô 3ð 3ðxð xð xð xð x�r”yñ xô xð xð Að Að Að Að Aˆ2Œ9ñ Aô Að Að
$ð 
$ð 
$ð 
$ð 
$ˆRŒYñ 
$ô 
$ð 
$ð 
$ð 
$r   