U
    ¯Ê¹j.  ã                   @   sn   d dl Z d dl mZ zd dlmZmZ dZW n* ek
rV   dZdd
d„Zdd„ ZY nX G dd„ dejƒZdS )é    N)Únn)Úinplace_abnÚinplace_abn_syncTFçš™™™™™¹?çñhãˆµøä>Ú
leaky_reluç{®Gáz„?c
           
      C   s   t dƒ‚d S )Nz`Please install InplaceABN:'pip install git+https://github.com/mapillary/inplace_abn.git@v1.0.12')ÚImportError)
ÚxÚweightÚbiasÚrunning_meanÚrunning_varÚtrainingÚmomentumÚepsZ
activationZactivation_param© r   úV/var/www/html/bwave/python/venv/lib/python3.8/site-packages/timm/layers/inplace_abn.pyr   
   s    ÿr   c                  K   s   t f | Ž d S )N)r   )Úkwargsr   r   r   r      s    r   c                       s2   e Zd ZdZd‡ fdd	„	Zd
d„ Zdd„ Z‡  ZS )Ú
InplaceAbna   Activated Batch Normalization

    This gathers a BatchNorm and an activation function in a single module

    Parameters
    ----------
    num_features : int
        Number of feature channels in the input and output.
    eps : float
        Small constant to prevent numerical issues.
    momentum : float
        Momentum factor applied to compute running statistics.
    affine : bool
        If `True` apply learned scale and shift transformation after normalization.
    act_layer : str or nn.Module type
        Name or type of the activation functions, one of: `leaky_relu`, `elu`
    act_param : float
        Negative slope for the `leaky_relu` activation.
    r   r   Tr   r   Nc	           	         s&  t t| ƒ ¡  || _|| _|| _|| _|r¦t|tƒrP|dks@t	‚|rH|nd| _
q¬|tjkrbd| _
q¬|tjkrtd| _
q¬|d ks†|tjkrŽd| _
q¬ds¬t	d|j› d�ƒ‚nd| _
|| _| jrÞt t |¡¡| _t t |¡¡| _n|  dd ¡ |  d	d ¡ |  d
t |¡¡ |  dt |¡¡ |  ¡  d S )N)r   ÚeluÚidentityÚ r   r   r   FzInvalid act layer z	 for IABNr   r   r   r   )Úsuperr   Ú__init__Únum_featuresÚaffiner   r   Ú
isinstanceÚstrÚAssertionErrorÚact_namer   ZELUZ	LeakyReLUZIdentityÚ__name__Ú	act_paramÚ	ParameterÚtorchZonesr   Zzerosr   Zregister_parameterZregister_bufferÚreset_parameters)	Úselfr   r   r   r   Z	apply_actZ	act_layerr"   Z
drop_layer©Ú	__class__r   r   r   (   s4    


zInplaceAbn.__init__c                 C   sJ   t j | jd¡ t j | jd¡ | jrFt j | jd¡ t j | jd¡ d S )Nr   é   )r   ÚinitZ	constant_r   r   r   r   r   )r&   r   r   r   r%   J   s
    zInplaceAbn.reset_parametersc                 C   sB   t || j| j| j| j| j| j| j| j| j	ƒ
}t
|tƒr>|d }|S )Nr   )r   r   r   r   r   r   r   r   r    r"   r   Útuple)r&   r
   Úoutputr   r   r   ÚforwardQ   s            þ
zInplaceAbn.forward)r   r   TTr   r   N)r!   Ú
__module__Ú__qualname__Ú__doc__r   r%   r-   Ú__classcell__r   r   r'   r   r      s         ÿ"r   )Tr   r   r   r   )	r$   r   Zinplace_abn.functionsr   r   Zhas_iabnr	   ÚModuler   r   r   r   r   Ú<module>   s            ÿ
