Ë
    [²jG  ã                   óø   — d dl Z d dlmZ d dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ dd	lmZ 	 	 	 	 	 dd
edededee   deeef   deeef   deeef   dee   defd„Z G d„ dej&                  «      Zy)é    N)ÚOptional)ÚnnÚTensor)Úinit)Ú_pair)Ú	Parameter)Ú_assert_has_opsé   )Ú_log_api_usage_onceÚinputÚoffsetÚweightÚbiasÚstrideÚpaddingÚdilationÚmaskÚreturnc                 óT  — t         j                  j                  «       s-t         j                  j                  «       st	        t
        «       t        «        |j                  d   }|du}	|€;t        j                  | j                  d   df| j                  | j                  ¬«      }|€,t        j                  || j                  | j                  ¬«      }t        |«      \  }
}t        |«      \  }}t        |«      \  }}|j                  dd \  }}| j                  \  }}}}|j                  d   d|z  |z  z  }||j                  d   z  }|dk(  r$t        d|j                  d   › dd|z  |z  › �«      ‚t         j                  j                  j                  | |||||
||||||||	«      S )	a?  
    Performs Deformable Convolution v2, described in
    `Deformable ConvNets v2: More Deformable, Better Results
    <https://arxiv.org/abs/1811.11168>`__ if :attr:`mask` is not ``None`` and
    Performs Deformable Convolution, described in
    `Deformable Convolutional Networks
    <https://arxiv.org/abs/1703.06211>`__ if :attr:`mask` is ``None``.

    Args:
        input (Tensor[batch_size, in_channels, in_height, in_width]): input tensor
        offset (Tensor[batch_size, 2 * offset_groups * kernel_height * kernel_width, out_height, out_width]):
            offsets to be applied for each position in the convolution kernel.
        weight (Tensor[out_channels, in_channels // groups, kernel_height, kernel_width]): convolution weights,
            split into groups of size (in_channels // groups)
        bias (Tensor[out_channels]): optional bias of shape (out_channels,). Default: None
        stride (int or Tuple[int, int]): distance between convolution centers. Default: 1
        padding (int or Tuple[int, int]): height/width of padding of zeroes around
            each image. Default: 0
        dilation (int or Tuple[int, int]): the spacing between kernel elements. Default: 1
        mask (Tensor[batch_size, offset_groups * kernel_height * kernel_width, out_height, out_width]):
            masks to be applied for each position in the convolution kernel. Default: None

    Returns:
        Tensor[batch_sz, out_channels, out_h, out_w]: result of convolution

    Examples::
        >>> input = torch.rand(4, 3, 10, 10)
        >>> kh, kw = 3, 3
        >>> weight = torch.rand(5, 3, kh, kw)
        >>> # offset and mask should have the same spatial size as the output
        >>> # of the convolution. In this case, for an input of 10, stride of 1
        >>> # and kernel size of 3, without padding, the output size is 8
        >>> offset = torch.rand(4, 2 * kh * kw, 8, 8)
        >>> mask = torch.rand(4, kh * kw, 8, 8)
        >>> out = deform_conv2d(input, offset, weight, mask=mask)
        >>> print(out.shape)
        >>> # returns
        >>>  torch.Size([4, 5, 8, 8])
    r   Né   )ÚdeviceÚdtypeéþÿÿÿr
   z�the shape of the offset tensor at dimension 1 is not valid. It should be a multiple of 2 * weight.size[2] * weight.size[3].
Got offset.shape[1]=z,, while 2 * weight.size[2] * weight.size[3]=)ÚtorchÚjitÚis_scriptingÚ
is_tracingr   Údeform_conv2dr	   ÚshapeÚzerosr   r   r   ÚRuntimeErrorÚopsÚtorchvision)r   r   r   r   r   r   r   r   Úout_channelsÚuse_maskÚstride_hÚstride_wÚpad_hÚpad_wÚdil_hÚdil_wÚ	weights_hÚ	weights_wÚ_Ún_in_channelsÚn_offset_grpsÚn_weight_grpss                         úZ/var/www/html/ia-enhanced/venv/lib/python3.12/site-packages/torchvision/ops/deform_conv.pyr   r      sœ  € ôb �9‰9×!Ñ!Ô#¬E¯I©I×,@Ñ,@Ô,BÜœMÔ*ÜÔØ—<‘< ‘?€Là˜4Ð€Hà€|Ü�{‰{˜EŸK™K¨™N¨AÐ.°u·|±|È5Ï;É;ÔWˆà€|Ü�{‰{˜<°·±ÀEÇKÁKÔPˆä˜v›Ñ€HˆhÜ˜“>�L€Eˆ5Ü˜“?�L€Eˆ5Ø!Ÿ<™<¨¨Ð,Ñ€IˆyØ"Ÿ[™[Ñ€A€}�a˜à—L‘L ‘O¨¨I©¸	Ñ(AÑB€MØ! V§\¡\°!¡_Ñ4€Mà˜ÒÜð#à#)§<¡<°¡?Ð"3Ð3_Ð`aÐdmÑ`mÐpyÑ`yÐ_zð|ó
ð 	
ô �9‰9× Ñ ×.Ñ.ØØØØØØØØØØØØØØóð ó    c                   ó„   ‡ — e Zd ZdZ	 	 	 	 	 ddededededededed	efˆ fd
„Zdd„Zddedede	e   defd„Z
defd„Zˆ xZS )ÚDeformConv2dz$
    See :func:`deform_conv2d`.
    Úin_channelsr$   Úkernel_sizer   r   r   Úgroupsr   c	           	      óD  •— t         ‰	| �  «        t        | «       ||z  dk7  rt        d«      ‚||z  dk7  rt        d«      ‚|| _        || _        t        |«      | _        t        |«      | _        t        |«      | _	        t        |«      | _
        || _        t        t        j                  |||z  | j                  d   | j                  d   «      «      | _        |r$t        t        j                  |«      «      | _        n| j#                  dd «       | j%                  «        y )Nr   z'in_channels must be divisible by groupsz(out_channels must be divisible by groupsr   r   )ÚsuperÚ__init__r   Ú
ValueErrorr6   r$   r   r7   r   r   r   r8   r   r   Úemptyr   r   Úregister_parameterÚreset_parameters)
Úselfr6   r$   r7   r   r   r   r8   r   Ú	__class__s
            €r2   r;   zDeformConv2d.__init__s   s   ø€ ô 	‰ÑÔÜ˜DÔ!à˜Ñ 1Ò$ÜÐFÓGÐGØ˜&Ñ  AÒ%ÜÐGÓHÐHà&ˆÔØ(ˆÔÜ  Ó-ˆÔÜ˜F“mˆŒÜ˜W“~ˆŒÜ˜h›ˆŒØˆŒäÜ�K‰K˜ k°VÑ&;¸T×=MÑ=MÈaÑ=PÐRV×RbÑRbÐcdÑReÓfó
ˆŒñ Ü!¤%§+¡+¨lÓ";Ó<ˆD�Ià×#Ñ# F¨DÔ1à×ÑÕr3   r   c                 ó>  — t        j                  | j                  t        j                  d«      ¬«       | j
                  �]t        j                  | j                  «      \  }}dt        j                  |«      z  }t        j                  | j
                  | |«       y y )Né   )Úar   )r   Úkaiming_uniform_r   ÚmathÚsqrtr   Ú_calculate_fan_in_and_fan_outÚuniform_)r@   Úfan_inr.   Úbounds       r2   r?   zDeformConv2d.reset_parameters™   sn   € Ü×Ñ˜dŸk™k¬T¯Y©Y°q«\Õ:à�9‰9Ð Ü×:Ñ:¸4¿;¹;ÓG‰IˆF�AØœŸ	™	 &Ó)Ñ)ˆEÜ�M‰M˜$Ÿ)™) e V¨UÕ3ð !r3   r   r   r   c           
      óŒ   — t        ||| j                  | j                  | j                  | j                  | j
                  |¬«      S )að  
        Args:
            input (Tensor[batch_size, in_channels, in_height, in_width]): input tensor
            offset (Tensor[batch_size, 2 * offset_groups * kernel_height * kernel_width, out_height, out_width]):
                offsets to be applied for each position in the convolution kernel.
            mask (Tensor[batch_size, offset_groups * kernel_height * kernel_width, out_height, out_width]):
                masks to be applied for each position in the convolution kernel.
        )r   r   r   r   )r   r   r   r   r   r   )r@   r   r   r   s       r2   ÚforwardzDeformConv2d.forward¡   s=   € ô ØØØ�K‰KØ�I‰IØ—;‘;Ø—L‘LØ—]‘]Øô	
ð 		
r3   c           	      ó   — | j                   j                  › d| j                  › d| j                  › d| j                  › d| j
                  › �	}|| j                  dk7  rd| j                  › �ndz  }|| j                  dk7  rd	| j                  › �ndz  }|| j                  d
k7  rd| j                  › �ndz  }|| j                  €dndz  }|dz  }|S )Nú(z, z, kernel_size=z	, stride=©r   r   z
, padding=Ú ©r   r   z, dilation=r   z	, groups=z, bias=Falseú))
rA   Ú__name__r6   r$   r7   r   r   r   r8   r   )r@   Úss     r2   Ú__repr__zDeformConv2d.__repr__µ   sÜ   € à�~‰~×&Ñ&Ð' qØ×ÑÐ Ø�×"Ñ"Ð#Ø˜T×-Ñ-Ð.Ø˜Ÿ™�}ð	&ð 	
ð 	
¨D¯L©L¸FÒ,Bˆz˜$Ÿ,™,˜Ñ(ÈÑJˆØ	¨d¯m©m¸vÒ.Eˆ{˜4Ÿ=™=˜/Ñ*È2ÑMˆØ	¨$¯+©+¸Ò*:ˆy˜Ÿ™˜Ñ&ÀÑBˆØ	˜tŸy™yÐ0‰^°bÑ8ˆØ	ˆS‰ˆàˆr3   )r   r   r   r   T)r   N)N)rT   Ú
__module__Ú__qualname__Ú__doc__ÚintÚboolr;   r?   r   r   rM   ÚstrrV   Ú__classcell__)rA   s   @r2   r5   r5   n   s¥   ø„ ñð ØØØØñ$ àð$ ð ð$ ð ð	$ ð
 ð$ ð ð$ ð ð$ ð ð$ ð õ$ óL4ñ
˜Vð 
¨Vð 
¸8ÀFÑ;Kð 
ÐW]ó 
ð(˜#÷ r3   r5   )NrR   rP   rR   N)rF   Útypingr   r   r   r   Útorch.nnr   Útorch.nn.modules.utilsr   Útorch.nn.parameterr   Útorchvision.extensionr	   Úutilsr   ÚtuplerZ   r   ÚModuler5   © r3   r2   ú<module>rg      sË   ðÛ Ý ã ß Ý Ý (Ý (Ý 1å 'ð "Ø$Ø%Ø &Ø!ñ]Øð]àð]ð ð]ð �6Ñ
ð	]ð
 �#�s�(‰Oð]ð �3˜�8‰_ð]ð �C˜�H‰oð]ð �6Ñ
ð]ð ó]ô@U�2—9‘9õ Ur3   