o
    پi.                     @   sn   d dl Z d dl mZ zd dlmZmZ dZW n ey+   dZ		dd
dZdd ZY nw G dd dejZdS )    N)nn)inplace_abninplace_abn_syncTF皙?h㈵>
leaky_relu{Gz?c
           
      C   s   t d)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eps
activationactivation_param r   K/home/ubuntu/.local/lib/python3.10/site-packages/timm/layers/inplace_abn.pyr   
   s   r   c                  K   s   t di |  d S )Nr   )r   )kwargsr   r   r   r      s   r   c                       s6   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|   || _|| _|| _|| _|rPt|tr(|dv s J |r$|nd| _	n+|t
jkr1d| _	n"|t
jkr:d| _	n|d u sC|t
jkrGd| _	nJ d|j dd| _	|| _| jrlt
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act_namer   ELU	LeakyReLUIdentity__name__	act_param	Parametertorchonesr   zerosr   register_parameterregister_bufferreset_parameters)	selfr   r   r   r   	apply_act	act_layerr&   
drop_layer	__class__r   r   r   (   s4   


zInplaceAbn.__init__c                 C   sN   t j| jd t j| jd | jr%t j| jd t j| jd d S d S )Nr      )r   init	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-   r9   __classcell__r   r   r2   r   r      s    "r   )Tr   r   r   r   )	r(   r   inplace_abn.functionsr   r   has_iabnr	   Moduler   r   r   r   r   <module>   s    
