o
    )i                     @   s   d dl Z d dlZ d dlm  mZ d dl mZmZ ddlmZ 	dded	e	d
e
dede	dedefddZ	dded	e	d
e
dede	dedefddZe jd G dd dejZe jd G dd deZdS )    N)nnTensor   )_log_api_usage_onceFư>Tinputp
block_sizeinplaceepstrainingreturnc                 C   s^  t j st j stt |dk s|dkrtd| d| jdkr,td| j d|r2|dkr4| S |  \}}}}	t	||	|}|| |	 |d || d	 |	| d	    }
t j
|||| d	 |	| d	 f| j| jd
}||
 tj||d gd dd}tj|d||f|d d}d	| }| ||   }|r| || | S | | | } | S )a  
    Implements DropBlock2d from `"DropBlock: A regularization method for convolutional networks"
    <https://arxiv.org/abs/1810.12890>`.

    Args:
        input (Tensor[N, C, H, W]): The input tensor or 4-dimensions with the first one
                    being its batch i.e. a batch with ``N`` rows.
        p (float): Probability of an element to be dropped.
        block_size (int): Size of the block to drop.
        inplace (bool): If set to ``True``, will do this operation in-place. Default: ``False``.
        eps (float): A value added to the denominator for numerical stability. Default: 1e-6.
        training (bool): apply dropblock if is ``True``. Default: ``True``.

    Returns:
        Tensor[N, C, H, W]: The randomly zeroed tensor after dropblock.
                  ?4drop probability has to be between 0 and 1, but got .   z#input should be 4 dimensional. Got  dimensions.r      dtypedevicer   value)r   r   ZstrideZkernel_sizepadding)torchjitis_scripting
is_tracingr   drop_block2d
ValueErrorndimsizeminemptyr   r   
bernoulli_FpadZ
max_pool2dnumelsummul_)r   r   r	   r
   r   r   NCHWgammanoisenormalize_scale r3   i/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/torchvision/ops/drop_block.pyr    	   s,   
,,
r    c                 C   s~  t j st j stt |dk s|dkrtd| d| jdkr,td| j d|r2|dkr4| S |  \}}}}	}
t	|||	|
}|| |	 |
 |d || d	 |	| d	  |
| d	    }t j
|||| d	 |	| d	 |
| d	 f| j| jd
}|| tj||d gd dd}tj|d|||f|d d}d	| }| ||   }|r| || | S | | | } | S )a  
    Implements DropBlock3d from `"DropBlock: A regularization method for convolutional networks"
    <https://arxiv.org/abs/1810.12890>`.

    Args:
        input (Tensor[N, C, D, H, W]): The input tensor or 5-dimensions with the first one
                    being its batch i.e. a batch with ``N`` rows.
        p (float): Probability of an element to be dropped.
        block_size (int): Size of the block to drop.
        inplace (bool): If set to ``True``, will do this operation in-place. Default: ``False``.
        eps (float): A value added to the denominator for numerical stability. Default: 1e-6.
        training (bool): apply dropblock if is ``True``. Default: ``True``.

    Returns:
        Tensor[N, C, D, H, W]: The randomly zeroed tensor after dropblock.
    r   r   r   r      z#input should be 5 dimensional. Got r      r   r   r      r   r   )r   r   r   r   )r   r   r   r   r   drop_block3dr!   r"   r#   r$   r%   r   r   r&   r'   r(   Z
max_pool3dr)   r*   r+   )r   r   r	   r
   r   r   r,   r-   Dr.   r/   r0   r1   r2   r3   r3   r4   r8   7   s4   
<,
r8   c                       sX   e Zd ZdZddededededd	f
 fd
dZdedefddZ	de
fddZ  ZS )DropBlock2dz#
    See :func:`drop_block2d`.
    Fr   r   r	   r
   r   r   Nc                    s&   t    || _|| _|| _|| _d S N)super__init__r   r	   r
   r   selfr   r	   r
   r   	__class__r3   r4   r=   q   s
   

zDropBlock2d.__init__r   c                 C      t || j| j| j| j| jS z
        Args:
            input (Tensor): Input feature map on which some areas will be randomly
                dropped.
        Returns:
            Tensor: The tensor after DropBlock layer.
        )r    r   r	   r
   r   r   r?   r   r3   r3   r4   forwardy      zDropBlock2d.forwardc                 C   s*   | j j d| j d| j d| j d}|S )Nz(p=z, block_size=z
, inplace=))rA   __name__r   r	   r
   )r?   sr3   r3   r4   __repr__   s   &zDropBlock2d.__repr__Fr   )rH   
__module____qualname____doc__floatintboolr=   r   rE   strrJ   __classcell__r3   r3   r@   r4   r:   l   s
    $
r:   c                       sJ   e Zd ZdZddededededd	f
 fd
dZdedefddZ	  Z
S )DropBlock3dz#
    See :func:`drop_block3d`.
    Fr   r   r	   r
   r   r   Nc                    s   t  |||| d S r;   )r<   r=   r>   r@   r3   r4   r=      s   zDropBlock3d.__init__r   c                 C   rB   rC   )r8   r   r	   r
   r   r   rD   r3   r3   r4   rE      rF   zDropBlock3d.forwardrK   )rH   rL   rM   rN   rO   rP   rQ   r=   r   rE   rS   r3   r3   r@   r4   rT      s    $rT   )Fr   T)r   Ztorch.fxZtorch.nn.functionalr   Z
functionalr'   r   utilsr   rO   rP   rQ   r    r8   ZfxwrapModuler:   rT   r3   r3   r3   r4   <module>   sR    
/
2