a
    PSic                     @   sf   d dl Z d dlZ d dl mZmZ ddlmZ deeeeedddZ	e j
d G d	d
 d
ejZdS )    N)nnTensor   )_log_api_usage_onceT)inputpmodetrainingreturnc                 C   s   t j st j stt |dk s,|dkr:td| |dvrPtd| |r\|dkr`| S d| }|dkr| jd gdg| jd   }ndg| j }t j	|| j
| jd	}||}|dkr|| | | S )
a  
    Implements the Stochastic Depth from `"Deep Networks with Stochastic Depth"
    <https://arxiv.org/abs/1603.09382>`_ used for randomly dropping residual
    branches of residual architectures.

    Args:
        input (Tensor[N, ...]): The input tensor or arbitrary dimensions with the first one
                    being its batch i.e. a batch with ``N`` rows.
        p (float): probability of the input to be zeroed.
        mode (str): ``"batch"`` or ``"row"``.
                    ``"batch"`` randomly zeroes the entire input, ``"row"`` zeroes
                    randomly selected rows from the batch.
        training: apply stochastic depth if is ``True``. Default: ``True``

    Returns:
        Tensor[N, ...]: The randomly zeroed tensor.
    g        g      ?z4drop probability has to be between 0 and 1, but got )batchrowz0mode has to be either 'batch' or 'row', but got r   r      )dtypedevice)torchjitis_scripting
is_tracingr   stochastic_depth
ValueErrorshapendimemptyr   r   
bernoulli_div_)r   r   r   r	   Zsurvival_ratesizenoise r   \/var/www/html/django/DPS/env/lib/python3.9/site-packages/torchvision/ops/stochastic_depth.pyr      s"    

r   c                       sH   e Zd ZdZeedd fddZeedddZed	d
dZ	  Z
S )StochasticDepthz'
    See :func:`stochastic_depth`.
    N)r   r   r
   c                    s"   t    t|  || _|| _d S N)super__init__r   r   r   )selfr   r   	__class__r   r   r"   7   s    
zStochasticDepth.__init__)r   r
   c                 C   s   t || j| j| jS r    )r   r   r   r	   )r#   r   r   r   r   forward=   s    zStochasticDepth.forward)r
   c                 C   s"   | j j d| j d| j d}|S )Nz(p=z, mode=))r%   __name__r   r   )r#   sr   r   r   __repr__@   s    zStochasticDepth.__repr__)r(   
__module____qualname____doc__floatstrr"   r   r&   r*   __classcell__r   r   r$   r   r   2   s   r   )T)r   torch.fxr   r   utilsr   r.   r/   boolr   fxwrapModuler   r   r   r   r   <module>   s   '