
    kh.                         d dl Z d dl mZ 	 d dlmZmZ dZ G d d	ej                        Zy# e$ r dZ	 d
dZd ZY 'w xY w)    N)nn)inplace_abninplace_abn_syncTFc
                     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/teggl/fontify/venv/lib/python3.12/site-packages/timm/layers/inplace_abn.pyr   r   
   s    np 	p    c                      t        di |  y )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.
    c	                 `   t         t        |           || _        || _        || _        || _        |rt        |t              r|dv sJ |r|nd| _	        no|t        j                  k(  rd| _	        nT|t        j                  k(  rd| _	        n9||t        j                  k(  rd| _	        nJ d|j                   d       d| _	        || _        | j                  r[t        j                   t#        j$                  |            | _        t        j                   t#        j(                  |            | _        n$| j-                  dd        | j-                  dd        | j/                  d	t#        j(                  |             | j/                  d
t#        j$                  |             | j1                          y )N)
leaky_relueluidentity r   r   r   z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__(   sT   j$(*( )S) $IIII-6	J &$)DM",,.$0DM&)r{{*B$.DMT$6y7I7I6J)"TT5&DM";;,,uzz,'?@DKU[[%>?DI##Hd3##FD1^U[[-FG]EJJ|,DEr   c                 n   t         j                  j                  | j                  d       t         j                  j                  | j                  d       | j
                  rUt         j                  j                  | j                  d       t         j                  j                  | j                  d       y y )Nr      )r   init	constant_r   r   r!   r	   r
   )r1   s    r   r0   zInplaceAbn.reset_parametersJ   sr    
$++Q/
$**A.;;GGdkk1-GGdii+ 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)r1   r   outputs      r   forwardzInplaceAbn.forwardQ   se    t{{DIIt'8'8$:J:JMM4==$((DMM4>>S fe$AYFr   )h㈵>皙?TTr   {Gz?N)r(   
__module____qualname____doc__r   r0   r=   __classcell__)r5   s   @r   r   r      s"    ( UYDH  D,r   r   )Tr?   r>   r   r@   )	r+   r   inplace_abn.functionsr   r   has_iabnr   Moduler   r   r   r   <module>rH      sR     CHD D  	H gkp
	s   
, >>