ó
    EñiG  ã                   óü   • S SK r S SKJr  S SKrS SKJrJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  SS	KJr       SS
\S\S\S\\   S\\\4   S\\\4   S\\\4   S\\   S\4S jjr " S S\R&                  5      rg)é    N)ÚOptional)ÚnnÚTensor)Úinit)Ú_pair)Ú	Parameter)Ú_assert_has_opsé   )Ú_log_api_usage_onceÚinputÚoffsetÚweightÚbiasÚstrideÚpaddingÚdilationÚmaskÚreturnc                 ó^  • [         R                  R                  5       (       d2  [         R                  R                  5       (       d  [	        [
        5        [        5         UR                  S   nUSLn	Uc9  [         R                  " U R                  S   S4U R                  U R                  S9nUc)  [         R                  " X€R                  U R                  S9n[        U5      u  p«[        U5      u  pÍ[        U5      u  pïUR                  SS u  nnU R                  u  nn  nUR                  S   SU-  U-  -  nUUR                  S   -  nUS:X  a$  [        SUR                  S    SSU-  U-   35      e[         R                  R                  R                  U UUUUU
UUUUUUUU	5      $ )	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                         ÚX/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torchvision/ops/deform_conv.pyr   r      sš  € ôb �9‰9×!Ñ!×#Ñ#¬E¯I©I×,@Ñ,@×,BÑ,BÜœMÔ*ÜÔØ—<‘< ‘?€Là˜4Ð€Hà�|Ü�{Š{˜EŸK™K¨™N¨AÐ.°u·|±|È5Ï;É;ÑWˆà�|Ü�{Š{˜<·±ÀEÇKÁKÑPˆä˜v›Ñ€HÜ˜“>�L€EÜ˜“?�L€EØ!Ÿ<™<¨¨Ð,Ñ€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                   óš   ^ • \ rS rSrSr     SS\S\S\S\S\S\S	\S
\4U 4S jjjrSS jrSS\	S\	S\
\	   S\	4S jjrS\4S jrSrU =r$ )ÚDeformConv2dén   z
See :func:`deform_conv2d`.
Úin_channelsr$   Úkernel_sizer   r   r   Úgroupsr   c	           	      óJ  >• [         T	U ]  5         [        U 5        X-  S:w  a  [        S5      eX'-  S:w  a  [        S5      eXl        X l        [        U5      U l        [        U5      U l        [        U5      U l	        [        U5      U l
        Xpl        [        [        R                  " X!U-  U R                  S   U R                  S   5      5      U l        U(       a%  [        [        R                  " U5      5      U l        OU R#                  SS 5        U R%                  5         g )Nr   z'in_channels must be divisible by groupsz(out_channels must be divisible by groupsr   r   )ÚsuperÚ__init__r   Ú
ValueErrorr7   r$   r   r8   r   r   r   r9   r   r   Úemptyr   r   Úregister_parameterÚreset_parameters)
Úselfr7   r$   r8   r   r   r   r9   r   Ú	__class__s
            €r2   r<   ÚDeformConv2d.__init__s   sô   ø€ ô 	‰ÑÔÜ˜DÔ!àÑ 1Ó$ÜÐFÓGÐGØÑ  AÓ%ÜÐGÓHÐHà&ÔØ(ÔÜ  Ó-ˆÔÜ˜F“mˆŒÜ˜W“~ˆŒÜ˜h›ˆŒØŒäÜ�KŠK˜°VÑ&;¸T×=MÑ=MÈaÑ=PÐRV×RbÑRbÐcdÑReÓfó
ˆŒö Ü!¤%§+¢+¨lÓ";Ó<ˆD�Ià×#Ñ# F¨DÔ1à×ÑÕr3   r   c                 óB  • [         R                  " U R                  [        R                  " S5      S9  U R
                  b_  [         R                  " U R                  5      u  pS[        R                  " U5      -  n[         R                  " U R
                  U* U5        g g )Né   )Úar   )r   Úkaiming_uniform_r   ÚmathÚsqrtr   Ú_calculate_fan_in_and_fan_outÚuniform_)rA   Úfan_inr.   Úbounds       r2   r@   ÚDeformConv2d.reset_parameters™   sl   € Ü×Ò˜dŸk™k¬T¯YªY°q«\Ò:à�9‰9Ñ Ü×:Ò:¸4¿;¹;ÓG‰IˆFØœŸ	š	 &Ó)Ñ)ˆEÜ�MŠM˜$Ÿ)™) e V¨UÕ3ð !r3   r   r   r   c                 ó†   • [        UUU R                  U R                  U R                  U R                  U R
                  US9$ )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   )rA   r   r   r   s       r2   ÚforwardÚDeformConv2d.forward¡   s=   € ô ØØØ�K‰KØ�I‰IØ—;‘;Ø—L‘LØ—]‘]Øñ	
ð 		
r3   c           	      ó   • U R                   R                   SU R                   SU R                   SU R                   SU R
                   3	nXR                  S:w  a  SU R                   3OS-  nXR                  S:w  a  S	U R                   3OS-  nXR                  S
:w  a  SU R                   3OS-  nXR                  c  SOS-  nUS-  nU$ )NÚ(z, z, kernel_size=z	, stride=©r   r   z
, padding=Ú ©r   r   z, dilation=r   z	, groups=z, bias=FalseÚ))
rB   Ú__name__r7   r$   r8   r   r   r   r9   r   )rA   Úss     r2   Ú__repr__ÚDeformConv2d.__repr__µ   sÔ   € à�~‰~×&Ñ&Ð' qØ×ÑÐ Ø�×"Ñ"Ð#Ø˜T×-Ñ-Ð.Ø˜Ÿ™�}ð	&ð 	
ð 	
¯L©L¸FÓ,Bˆz˜$Ÿ,™,˜Ñ(ÈÑJˆØ	¯m©m¸vÓ.Eˆ{˜4Ÿ=™=˜/Ñ*È2ÑMˆØ	¯+©+¸Ó*:ˆy˜Ÿ™˜Ñ&ÀÑBˆØ	Ÿy™yÑ0‰^°bÑ8ˆØ	ˆS‰ˆàˆr3   )	r   r   r9   r7   r8   r$   r   r   r   )r   r   r   r   T)r   N)N)rX   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚintÚboolr<   r@   r   r   rP   ÚstrrZ   Ú__static_attributes__Ú__classcell__)rB   s   @r2   r5   r5   n   s¯   ø† ñð ØØØØñ$ àð$ ð ð$ ð ð	$ ð
 ð$ ð ð$ ð ð$ ð ð$ ð ÷$ ð $ ôL4ñ
˜Vð 
¨Vð 
¸8ÀFÑ;Kð 
ÐW]õ 
ð(˜#÷ ò r3   r5   )NrV   rT   rV   N)rH   Útypingr   r   r   r   Útorch.nnr   Útorch.nn.modules.utilsr   Útorch.nn.parameterr   Útorchvision.extensionr	   Úutilsr   Útupler`   r   ÚModuler5   © r3   r2   Ú<module>rn      sË   ðÛ Ý ã ß Ý Ý (Ý (Ý 1å 'ð "Ø$Ø%Ø &Ø!ñ]Øð]àð]ð ð]ð �6Ñ
ð	]ð
 �#�s�(‰Oð]ð �3˜�8‰_ð]ð �C˜�H‰oð]ð �6Ñ
ð]ð õ]ô@U�2—9‘9õ Ur3   