o

    h                     @   s:   d dl mZ ddlmZ ddlmZ G dd dejZdS )    N   )
ConvModule)make_divisiblec                       sD   e Zd ZdZddddeddeddff fdd		Zd
d Z  ZS )SELayera%  Squeeze-and-Excitation Module.

    Args:
        channels (int): The input (and output) channels of the SE layer.
        squeeze_channels (None or int): The intermediate channel number of
            SElayer. Default: None, means the value of ``squeeze_channels``
            is ``make_divisible(channels // ratio, divisor)``.
        ratio (int): Squeeze ratio in SELayer, the intermediate channel will
            be ``make_divisible(channels // ratio, divisor)``. Only used when
            ``squeeze_channels`` is None. Default: 16.
        divisor(int): The divisor to true divide the channel number. Only
            used when ``squeeze_channels`` is None. Default: 8.
        conv_cfg (None or dict): Config dict for convolution layer. Default:
            None, which means using conv2d.
        return_weight(bool): Whether to return the weight. Default: False.
        act_cfg (dict or Sequence[dict]): Config dict for activation layer.
            If act_cfg is a dict, two activation layers will be configurated
            by this dict. If act_cfg is a sequence of dicts, the first
            activation layer will be configurated by the first dict and the
            second activation layer will be configurated by the second dict.
            Default: (dict(type='ReLU'), dict(type='Sigmoid'))
    N      ReLU)typeSigmoidc                    s   t t|   t|dksJ td| _|d u r t|| |}t|t	r)|dks2J d| d t
||dd||d d| _t
||dd||d d| _d S )N   r   r   z9"squeeze_channels" should be a positive integer, but get z	 instead.)in_channelsout_channelskernel_sizestrideconv_cfgact_cfg)
superr   __init__lennnAdaptiveAvgPool2dglobal_avgpoolr   
isinstanceintr   conv1conv2)selfchannelssqueeze_channelsratiodivisorr   r   	__class__ 2/root/Awesome-Backbones/configs/common/se_layer.pyr   #   s4   zSELayer.__init__c                 C   s&   |  |}| |}| |}|| S )N)r   r   r   )r   xoutr#   r#   r$   forwardD   s   


zSELayer.forward)__name__
__module____qualname____doc__dictr   r'   
__classcell__r#   r#   r!   r$   r      s    !r   )torch.nnr   conv_moduler   r   Moduler   r#   r#   r#   r$   <module>   s    