
    hG                         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                  " XR                  U R                  S9n[        U5      u  p[        U5      u  p[        U5      u  pU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dtyper
   zthe 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                         S/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/ops/deform_conv.pyr   r      s   b 99!!##EII,@,@,B,BM*<<?L4H|{{EKKNA.u||5;;W|{{<EKKPvH>LE?LE!<<,Iy"[[A}aLLOI	(ABM!V\\!_4M##)<<?"33_`adm`mpy`y_z|
 	
 99  ..     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$ )DeformConv2dn   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&( -FmW~hKKV&;T=M=Ma=PRVRbRbcdRef
 !%++l";<DI##FD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    dkkTYYq\:99 ::4;;GIF		&))EMM$))eVU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=     KKII;;LL]]	
 		
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--.}	& 	
 	
LLF,Bz$,,(J	mmv.E{4==/*2M	++*:y&B	yy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 
8F;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Ho] 6
] ]@U299 Ur3   