
    Ng.                         d dl Z d dl mZ 	 d dlmZmZ dZn# e$ r dZ	 dd
Zd ZY nw xY w G d dej                  ZdS )    N)nn)inplace_abninplace_abn_syncTF皙?h㈵>
leaky_relu{Gz?c
                      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_params
             S/var/www/html/ai-engine/env/lib/python3.11/site-packages/timm/layers/inplace_abn.pyr   r   
   s    np p 	p    c                      t          di |  d S )N )r   )kwargss    r   r   r      s    fr   c                   4     e Zd ZdZ	 	 d fd	Zd	 Zd
 Z x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	                    t          t          |                                            || _        || _        || _        || _        |rt          |t                    r|dv sJ |r|nd| _	        nd|t          j        k    rd| _	        nL|t          j        k    rd| _	        n4||t          j        k    rd| _	        nJ d|j         d            d| _	        || _        | j        rWt          j        t#          j        |                    | _        t          j        t#          j        |                    | _        n,|                     dd            |                     d	d            |                     d
t#          j        |                     |                     dt#          j        |                     |                                  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__s
            r   r"   zInplaceAbn.__init__(   s   j$((***(  	')S)) U $IIIII-6 F		J &&$)DMM",..$0DMM&)r{*B*B$.DMMT"Ty7I"T"T"TTTT&DM"; 	2,uz,'?'?@@DKU[%>%>??DII##Hd333##FD111^U[-F-FGGG]EJ|,D,DEEEr   c                 @   t           j                            | j        d           t           j                            | j        d           | j        rLt           j                            | j        d           t           j                            | j        d           d S d S )Nr      )r   init	constant_r   r   r$   r   r   )r4   s    r   r3   zInplaceAbn.reset_parametersJ   s    
$+Q///
$*A...; 	,Gdk1---Gdi+++++	, 	,r   c                     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)r4   r   outputs      r   forwardzInplaceAbn.forwardQ   s_    t{DIt'8$:JM4=$(DM4>S S fe$$ 	AYFr   )r   r   TTr   r	   N)r+   
__module____qualname____doc__r"   r3   r@   __classcell__)r8   s   @r   r   r      sp         ( UYDH                 D, , ,      r   r   )Tr   r   r   r	   )	r.   r   inplace_abn.functionsr   r   has_iabnr   Moduler   r   r   r   <module>rH      s          CCCCCCCCHH 	 	 	H gkp p p p
    	D D D D D D D D D Ds   
 ))