o
    _{jM  ã                   @   sP   d dl mZ d dlmZ ddlmZ ddlmZmZ e 	¡ G dd„ deƒƒZ
dS )	é    N)Únormal_inité   )ÚHEADSé   )ÚAvgConsensusÚBaseHeadc                       sJ   e Zd ZdZedd�deddd�dd	f‡ fd
d„	Zdd„ Zdd„ Z‡  ZS )ÚTSNHeada|  Class head for TSN.

    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'.
        consensus (dict): Consensus config dict.
        dropout_ratio (float): Probability of dropout layer. Default: 0.4.
        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Úavgr   r   )r
   Údimgš™™™™™Ù?g{®Gáz„?c                    s´   t ƒ j||fd|i|¤Ž || _|| _|| _| ¡ }	|	 d¡}
|
dkr,tdi |	¤Ž| _nd | _| jdkr;t	 
d¡| _nd | _| jdkrLt	j| jd�| _nd | _t	 | j| j¡| _d S )	NÚloss_clsr
   r   r   )r   r   r   )Úp© )ÚsuperÚ__init__Úspatial_typeÚdropout_ratioÚinit_stdÚcopyÚpopr   Ú	consensusÚnnÚAdaptiveAvgPool2dÚavg_poolÚDropoutÚdropoutÚLinearÚin_channelsÚnum_classesÚfc_cls)Úselfr   r   r   r   r   r   r   ÚkwargsÚ
consensus_Úconsensus_type©Ú	__class__r   ú4/root/disk_3tb/HAC/mmaction/models/heads/tsn_head.pyr      s    	


zTSNHead.__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TSNHead.init_weightsc                 C   sx   | j dur
|   |¡}| d|f|jdd…  ¡}|  |¡}| d¡}| jdur,|  |¡}| | d¡d¡}|  |¡}|S )a,  Defines the computation performed at every call.

        Args:
            x (torch.Tensor): The input data.
            num_segs (int): Number of segments into which a video
                is divided.
        Returns:
            torch.Tensor: The classification scores for input samples.
        Néÿÿÿÿr   r   )	r   ÚreshapeÚshaper   Úsqueezer   ÚviewÚsizer    )r!   ÚxÚnum_segsÚ	cls_scorer   r   r'   Úforward@   s   






zTSNHead.forward)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údictr   r)   r3   Ú__classcell__r   r   r%   r'   r      s    
ù#r   )Útorch.nnr   Úmmcv.cnnr   Úregistryr   Úbaser   r   Úregister_moduler   r   r   r   r'   Ú<module>   s    