o
    _{jz  ã                   @   sT   d dl Z d dlmZ d dlmZ ddlmZ ddlmZ e 	¡ G dd„ deƒƒZ
dS )	é    N)Únormal_inité   )ÚHEADSé   )ÚBaseHeadc                       sD   e Zd ZdZedd�dddddf‡ fd	d
„	Zdd„ Zdd„ Z‡  ZS )ÚSlowFastHeada]  The classification head for SlowFast.

    Args:
        num_classes (int): Number of classes to be classified.
        in_channels (int): Number of channels in input feature.
        loss_cls (dict): Config for building loss.
            Default: dict(type='CrossEntropyLoss').
        spatial_type (str): Pooling type in spatial dimension. Default: 'avg'.
        dropout_ratio (float): Probability of dropout layer. Default: 0.8.
        init_std (float): Std value for Initiation. Default: 0.01.
        kwargs (dict, optional): Any keyword argument to be used to initialize
            the head.
    ÚCrossEntropyLoss)ÚtypeÚavggš™™™™™é?g{®Gáz„?Fi   c	           
         sœ   t ƒ j|||fi |	¤Ž || _|| _|| _|| _|| _| jdkr)tj| jd�| _	nd | _	t 
|| j¡| _t 
| j|¡| _| jdkrIt d¡| _d S d | _d S )Nr   )Úpr
   )r   r   r   )ÚsuperÚ__init__Úspatial_typeÚdropout_ratioÚinit_stdÚreduce_channelÚreduce_channel_numÚnnÚDropoutÚdropoutÚLinearÚ	fc_reduceÚfc_clsÚAdaptiveAvgPool3dÚavg_pool)
ÚselfÚnum_classesÚin_channelsÚloss_clsr   r   r   r   r   Úkwargs©Ú	__class__© ú9/root/disk_3tb/HAC/mmaction/models/heads/slowfast_head.pyr      s   
	

zSlowFastHead.__init__c                 C   s   t | j| jd� dS )z%Initiate the parameters from scratch.)ÚstdN)r   r   r   )r   r"   r"   r#   Úinit_weights?   s   zSlowFastHead.init_weightsc                 C   sv   |\}}|   |¡}|   |¡}tj||fdd�}| jdur!|  |¡}| | d¡d¡}| jr2|  |¡}|  |¡}||fS )zÏDefines the computation performed at every call.

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

        Returns:
            torch.Tensor: The classification scores for input samples.
        r   )ÚdimNr   éÿÿÿÿ)	r   ÚtorchÚcatr   ÚviewÚsizer   r   r   )r   ÚxÚx_fastÚx_slowÚ	cls_scorer"   r"   r#   ÚforwardC   s   






zSlowFastHead.forward)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údictr   r%   r0   Ú__classcell__r"   r"   r    r#   r   	   s    ø&r   )r(   Útorch.nnr   Úmmcv.cnnr   Úregistryr   Úbaser   Úregister_moduler   r"   r"   r"   r#   Ú<module>   s    