o
    _{j  ã                   @   sL   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                       sB   e Zd ZdZedd�ddddf‡ fdd	„	Zd
d„ Zdd„ Z‡  ZS )ÚX3DHeada7  Classification head for I3D.

    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.5.
        init_std (float): Std value for Initiation. Default: 0.01.
        fc1_bias (bool): If the first fc layer has bias. Default: False.
    ÚCrossEntropyLoss)ÚtypeÚavgg      à?g{®Gáz„?Fc                    sÎ   t ƒ  |||¡ || _|| _|| _| jdkrtj| jd�| _nd | _|| _d| _	|| _
|| _tj| j| j	| jd�| _t | j	| j
¡| _t ¡ | _d | _| jdkrXt d¡| _d S | jdkret d¡| _d S t‚)Nr   )Úpi   )Úbiasr
   )r   r   r   Úmax)ÚsuperÚ__init__Úspatial_typeÚdropout_ratioÚinit_stdÚnnÚDropoutÚdropoutÚin_channelsÚmid_channelsÚnum_classesÚfc1_biasÚLinearÚfc1Úfc2ÚReLUÚreluÚpoolÚAdaptiveAvgPool3dÚAdaptiveMaxPool3dÚNotImplementedError)Úselfr   r   Úloss_clsr   r   r   r   ©Ú	__class__© ú4/root/disk_3tb/HAC/mmaction/models/heads/x3d_head.pyr      s,   
ÿ


zX3DHead.__init__c                 C   s$   t | j| jd� t | j| jd� dS )z%Initiate the parameters from scratch.)ÚstdN)r   r   r   r   )r#   r'   r'   r(   Úinit_weights;   s   zX3DHead.init_weightsc                 C   s`   | j dusJ ‚|   |¡}| |jd d¡}|  |¡}|  |¡}| jdur)|  |¡}|  |¡}|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.
        Nr   éÿÿÿÿ)r   ÚviewÚshaper   r   r   r   )r#   ÚxÚ	cls_scorer'   r'   r(   Úforward@   s   






zX3DHead.forward)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údictr   r*   r0   Ú__classcell__r'   r'   r%   r(   r      s    ù$r   )
Útorch.nnr   Úmmcv.cnnr   Úregistryr   Úbaser   Úregister_moduler   r'   r'   r'   r(   Ú<module>   s    