
    ^j                         d Z ddlmZmZmZ ddlmZ ddlmZ ddlm	Z	  G d dej                        ZeZ G d	 d
ej                        Zy)a
   Depthwise Separable Conv Modules

Basic DWS convs. Other variations of DWS exist with batch norm or activations between the
DW and PW convs such as the Depthwise modules in MobileNetV2 / EfficientNet and Xception.

Hacked together by / Copyright 2020 Ross Wightman
    )OptionalTypeUnion)nn   )create_conv2d)get_norm_act_layerc                       e Zd ZdZdddddddej
                  ej                  ddddfd	ed
ededededede	de
dedeej                     deej                     de	deeej                        f fdZed        Zed        Zd Z xZS )SeparableConvNormActz4 Separable Conv w/ trailing Norm and Activation
       r    F      ?TNin_channelsout_channelskernel_sizestridedilationpaddingbiaschannel_multiplierpw_kernel_size
norm_layer	act_layer	apply_act
drop_layerc                    ||d}t         |           t        |t        ||z        |f|||dd|| _        t        t        ||z        ||	f||d|| _        t        |
|      }|t        |      ni } ||fd|i||| _        y )NdevicedtypeTr   r   r   	depthwiser   r   )r   r   )	super__init__r   intconv_dwconv_pwr	   dictbn)selfr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ddnorm_act_layernorm_kwargs	__class__s                      e/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/timm/layers/separable_conv.pyr$   zSeparableConvNormAct.__init__   s    $ /$001	
 	
 	
 %001
 
 
 ,J	B5?5Kdj1QS XXkXUWX    c                 .    | j                   j                  S Nr&   r   r*   s    r/   r   z SeparableConvNormAct.in_channels@       ||'''r0   c                 .    | j                   j                  S r2   r'   r   r4   s    r/   r   z!SeparableConvNormAct.out_channelsD       ||(((r0   c                 l    | j                  |      }| j                  |      }| j                  |      }|S r2   )r&   r'   r)   r*   xs     r/   forwardzSeparableConvNormAct.forwardH   s.    LLOLLOGGAJr0   )__name__
__module____qualname____doc__r   BatchNorm2dReLUr%   strboolfloatr   Moduler   r$   propertyr   r   r<   __classcell__r.   s   @r/   r   r      s     !(+"#*,..)+"48!+Y+Y +Y 	+Y
 +Y +Y +Y +Y !&+Y  +Y RYY+Y BII+Y +Y !bii1+YZ ( ( ) )r0   r   c                   \     e Zd ZdZ	 	 	 	 	 	 	 	 	 d fd	Zed        Zed        Zd Z xZ	S )SeparableConv2dz Separable Conv
    c                     |
|d}t         |           t        |t        ||z        |f|||dd|| _        t        t        ||z        ||	f||d|| _        y )Nr   Tr    r"   )r#   r$   r   r%   r&   r'   )r*   r   r   r   r   r   r   r   r   r   r   r   r+   r.   s                r/   r$   zSeparableConv2d.__init__U   s     /$001	
 	
 	
 %001
 
 
r0   c                 .    | j                   j                  S r2   r3   r4   s    r/   r   zSeparableConv2d.in_channelsz   r5   r0   c                 .    | j                   j                  S r2   r7   r4   s    r/   r   zSeparableConv2d.out_channels~   r8   r0   c                 J    | j                  |      }| j                  |      }|S r2   )r&   r'   r:   s     r/   r<   zSeparableConv2d.forward   s!    LLOLLOr0   )	r   r   r   r   Fr   r   NN)
r=   r>   r?   r@   r$   rG   r   r   r<   rH   rI   s   @r/   rK   rK   R   sX     "#
J ( ( ) )r0   rK   N)r@   typingr   r   r   torchr   r   create_norm_actr	   rF   r   SeparableConvBnActrK    r0   r/   <module>rU      sD    ) (  ( /<299 <~ * 3bii 3r0   