o
    _{j�  ã                   @   s6   d dl mZmZ d dlmZ G dd„ dejed�ZdS )é    )ÚABCMetaÚabstractmethodNc                       s6   e Zd ZdZd	‡ fdd„	Zedd„ ƒZdd„ Z‡  ZS )
ÚBaseWeightedLosszöBase class for loss.

    All subclass should overwrite the ``_forward()`` method which returns the
    normal loss without loss weights.

    Args:
        loss_weight (float): Factor scalar multiplied on the loss.
            Default: 1.0.
    ç      ð?c                    s   t ƒ  ¡  || _d S ©N)ÚsuperÚ__init__Úloss_weight)Úselfr	   ©Ú	__class__© ú1/root/disk_3tb/HAC/mmaction/models/losses/base.pyr      s   

zBaseWeightedLoss.__init__c                 O   s   d S r   r   )r
   ÚargsÚkwargsr   r   r   Ú_forward   s   zBaseWeightedLoss._forwardc                 O   sP   | j |i |¤Ž}t|tƒr!|D ]}d|v r||  | j9  < q|S || j9 }|S )a9  Defines the computation performed at every call.

        Args:
            *args: The positional arguments for the corresponding
                loss.
            **kwargs: The keyword arguments for the corresponding
                loss.

        Returns:
            torch.Tensor: The calculated loss.
        Úloss)r   Ú
isinstanceÚdictr	   )r
   r   r   ÚretÚkr   r   r   Úforward   s   
€
ÿzBaseWeightedLoss.forward)r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Ú__classcell__r   r   r   r   r      s    

r   )Ú	metaclass)Úabcr   r   Útorch.nnÚnnÚModuler   r   r   r   r   Ú<module>   s    