o
    _{j™  ã                   @   sV   d dl Z d dlmZ d dlmZmZmZmZ d dlm	Z	 e 
¡ G dd„ dejƒƒZdS )é    N)ÚCONV_LAYERSÚ
ConvModuleÚconstant_initÚkaiming_init)Ú_pairc                       s>   e Zd ZdZ						d‡ fdd„	Zdd	„ Zd
d„ Z‡  ZS )Ú	ConvAudioa  Conv2d module for AudioResNet backbone.

        <https://arxiv.org/abs/2001.08740>`_.

    Args:
        in_channels (int): Same as nn.Conv2d.
        out_channels (int): Same as nn.Conv2d.
        kernel_size (int | tuple[int]): Same as nn.Conv2d.
        op (string): Operation to merge the output of freq
            and time feature map. Choices are 'sum' and 'concat'.
            Default: 'concat'.
        stride (int | tuple[int]): Same as nn.Conv2d.
        padding (int | tuple[int]): Same as nn.Conv2d.
        dilation (int | tuple[int]): Same as nn.Conv2d.
        groups (int): Same as nn.Conv2d.
        bias (bool | str): If specified as `auto`, it will be decided by the
            norm_cfg. Bias will be set as True if norm_cfg is None, otherwise
            False.
    Úconcaté   r   Fc
           
         s   t ƒ  ¡  t|ƒ}t|ƒ}t|ƒ}|| _|| _|| _|dv s J ‚|| _|| _|| _|| _	|| _
|	| _d| _d| _t|||d df||d d df|	tdd�td	d�td
d�d�	| _t||d|d f|d|d d f|	tdd�td	d�td
d�d�	| _|  ¡  d S )N)r   Úsum)r   r   Fr   r	   é   ÚConv)ÚtypeÚBNÚReLU)Úkernel_sizeÚstrideÚpaddingÚbiasÚconv_cfgÚnorm_cfgÚact_cfg)ÚsuperÚ__init__r   Úin_channelsÚout_channelsr   Úopr   r   ÚdilationÚgroupsr   Úoutput_paddingÚ
transposedr   ÚdictÚconv_1Úconv_2Úinit_weights)
Úselfr   r   r   r   r   r   r   r   r   ©Ú	__class__© ú7/root/disk_3tb/HAC/mmaction/models/common/conv_audio.pyr      sN   


÷
÷zConvAudio.__init__c                 C   s>   |   |¡}|  |¡}| jdkrt ||gd¡}|S || }|S )z¼Defines the computation performed at every call.

        Args:
            x (torch.Tensor): The input data.

        Returns:
            torch.Tensor: The output of the module.
        r   r	   )r!   r"   r   ÚtorchÚcat)r$   ÚxÚx_1Zx_2Úoutr'   r'   r(   ÚforwardR   s   
	

ÿzConvAudio.forwardc                 C   s@   t | jjƒ t | jjƒ t| jjddd� t| jjddd� dS )z%Initiate the parameters from scratch.r	   r   )r   N)r   r!   Úconvr"   r   Úbn)r$   r'   r'   r(   r#   c   s   zConvAudio.init_weights)r   r	   r   r	   r	   F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r.   r#   Ú__classcell__r'   r'   r%   r(   r      s    ÷5r   )r)   Útorch.nnÚnnÚmmcv.cnnr   r   r   r   Ztorch.nn.modules.utilsr   Úregister_moduleÚModuler   r'   r'   r'   r(   Ú<module>   s    