§
    ù²Åj  ã                   ó  — d dl Z d dlmZ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dS )é    N)ÚOptionalÚTuple)ÚnnÚTensor)Úinit)Ú_pair)Ú	Parameter)Ú_assert_has_opsé   )Ú_log_api_usage_once©é   r   ©r   r   ÚinputÚoffsetÚweightÚbiasÚstrideÚpaddingÚdilationÚmaskÚreturnc                 ó4  — t           j                             ¦   «         s2t           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                             | |||||
||||||||	¦  «        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   Nr   )Ú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                         úLC:\Projects\Historical\venv\Lib\site-packages\torchvision/ops/deform_conv.pyr!   r!      sÀ  € õb Œ9×!Ò!Ñ#Ô#ð +­E¬I×,@Ò,@Ñ,BÔ,Bð +Ý�MÑ*Ô*Ð*ÝÑÔÐØ”< ”?€Là˜4Ð€Hà€|ÝŒ{˜EœK¨œN¨AÐ.°u´|È5Ì;ÐWÑWÔWˆà€|ÝŒ{˜<°´ÀEÄKÐPÑPÔPˆå˜v™œÑ€HˆhÝ˜‘>”>�L€Eˆ5Ý˜‘?”?�L€Eˆ5Ø!œ<¨¨¨Ô,Ñ€IˆyØ"œ[Ñ€A€}�a˜à”L ”O¨¨I©¸	Ñ(AÑB€MØ! V¤\°!¤_Ñ4€Mà˜ÒÐÝð|à#)¤<°¤?ð|ð |à`aÐdmÑ`mÐpyÑ`yð|ð |ñ
ô 
ð 	
õ Œ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`.
    r   r   TÚin_channelsr'   Úkernel_sizer   r   r   Úgroupsr   c	           	      óº  •— t          ¦   «                              ¦   «          t          | ¦  «         ||z  dk    rt          d¦  «        ‚||z  dk    rt          d¦  «        ‚|| _        || _        t          |¦  «        | _        t          |¦  «        | _        t          |¦  «        | _	        t          |¦  «        | _
        || _        t          t          j        |||z  | j        d         | j        d         ¦  «        ¦  «        | _        |r't          t          j        |¦  «        ¦  «        | _        n|                      dd ¦  «         |                      ¦   «          d S )Nr   z'in_channels must be divisible by groupsz(out_channels must be divisible by groupsr   r   )ÚsuperÚ__init__r   Ú
ValueErrorr9   r'   r   r:   r   r   r   r;   r	   r   Úemptyr   r   Úregister_parameterÚreset_parameters)
Úselfr9   r'   r:   r   r   r   r;   r   Ú	__class__s
            €r5   r>   zDeformConv2d.__init__s   sC  ø€ õ 	‰Œ×ÒÑÔÐÝ˜DÑ!Ô!Ð!à˜Ñ 1Ò$Ð$ÝÐFÑGÔGÐGØ˜&Ñ  AÒ%Ð%ÝÐGÑHÔHÐHà&ˆÔØ(ˆÔÝ  Ñ-Ô-ˆÔÝ˜F‘m”mˆŒÝ˜W‘~”~ˆŒÝ˜h™œˆŒØˆŒåÝŒK˜ k°VÑ&;¸TÔ=MÈaÔ=PÐRVÔRbÐcdÔReÑfÔfñ
ô 
ˆŒð ð 	2Ý!¥%¤+¨lÑ";Ô";Ñ<Ô<ˆDŒIˆIà×#Ò# F¨DÑ1Ô1Ð1à×ÒÑÔÐÐÐr6   r   Nc                 ó  — t          j        | j        t          j        d¦  «        ¬¦  «         | j        �Qt          j        | j        ¦  «        \  }}dt          j        |¦  «        z  }t          j        | j        | |¦  «         d S d S )Né   )Úar   )r   Úkaiming_uniform_r   ÚmathÚsqrtr   Ú_calculate_fan_in_and_fan_outÚuniform_)rC   Úfan_inr1   Úbounds       r5   rB   zDeformConv2d.reset_parameters™   sz   € ÝÔ˜dœk­T¬Y°q©\¬\Ð:Ñ:Ô:Ð:àŒ9Ð ÝÔ:¸4¼;ÑGÔG‰IˆF�AØ�œ	 &Ñ)Ô)Ñ)ˆEÝŒM˜$œ) e V¨UÑ3Ô3Ð3Ð3Ð3ð !Ð r6   r   r   r   c           
      ób   — 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   )rC   r   r   r   s       r5   ÚforwardzDeformConv2d.forward¡   s=   € õ ØØØŒKØŒIØ”;Ø”LØ”]Øð	
ñ 	
ô 	
ð 		
r6   c           	      ó$  — | j         j        › d| j        › d| j        › d| j        › d| j        › �	}|| j        dk    r
d| j        › �ndz  }|| j        dk    r
d	| j        › �ndz  }|| j        d
k    r
d| j        › �ndz  }|| j	        €dndz  }|dz  }|S )Nú(z, z, kernel_size=z	, stride=r   z
, padding=Ú r   z, dilation=r   z	, groups=z, bias=Falseú))
rD   Ú__name__r9   r'   r:   r   r   r   r;   r   )rC   Úss     r5   Ú__repr__zDeformConv2d.__repr__µ   só   € àŒ~Ô&ð &ð &ØÔð&ð &àÔ"ð&ð &ð "Ô-ð&ð &ð œð	&ð &ð 	
ð 	
¨D¬L¸FÒ,BÐ,BÐ(˜$œ,Ð(Ð(Ð(ÈÑJˆØ	¨d¬m¸vÒ.EÐ.EÐ*˜4œ=Ð*Ð*Ð*È2ÑMˆØ	¨$¬+¸Ò*:Ð*:Ð&˜œÐ&Ð&Ð&ÀÑBˆØ	˜tœyÐ0ˆ^ˆ^°bÑ8ˆØ	ˆS‰ˆàˆr6   )r   r   r   r   T)r   N)N)rU   Ú
__module__Ú__qualname__Ú__doc__ÚintÚboolr>   rB   r   r   rP   ÚstrrW   Ú__classcell__)rD   s   @r5   r8   r8   n   s  ø€ € € € € ðð ð ØØØØð$ ð $ àð$ ð ð$ ð ð	$ ð
 ð$ ð ð$ ð ð$ ð ð$ ð ð$ ð $ ð $ ð $ ð $ ð $ ðL4ð 4ð 4ð 4ð
ð 
˜Vð 
¨Vð 
¸8ÀFÔ;Kð 
ÐW]ð 
ð 
ð 
ð 
ð(˜#ð ð ð ð ð ð ð ð r6   r8   )Nr   r   r   N)rI   Útypingr   r   r   r   r   Útorch.nnr   Útorch.nn.modules.utilsr   Útorch.nn.parameterr	   Útorchvision.extensionr
   Úutilsr   r[   r!   ÚModuler8   © r6   r5   ú<module>rg      s’  ðØ €€€Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à €€€Ø Ð Ð Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ø (Ð (Ð (Ð (Ð (Ð (Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1à 'Ð 'Ð 'Ð 'Ð 'Ð 'ð "Ø$Ø%Ø &Ø!ð]ð ]Øð]àð]ð ð]ð �6Ô
ð	]ð
 �#�s�(ŒOð]ð �3˜�8Œ_ð]ð �C˜�HŒoð]ð �6Ô
ð]ð ð]ð ]ð ]ð ]ð@Uð Uð Uð Uð U�2”9ñ Uô Uð Uð Uð Ur6   