U
    ­Ê¹jÕ  ã                   @   sJ   d dl Z d dlm  mZ ddlmZ d	e je jeee	e jdœdd„Z
dS )
é    Né   )Ú_log_api_usage_onceç      Ð?Únone)ÚinputsÚtargetsÚalphaÚgammaÚ	reductionÚreturnc           
      C   sÈ   t j ¡ st j ¡ sttƒ t  | ¡}tj| |dd�}|| d| d|   }|d| |  }|dkr†|| d| d|   }	|	| }|dkr�n4|dkr¢| 	¡ }n"|dkr´| 
¡ }ntd|› d�ƒ‚|S )	a  
    Loss used in RetinaNet for dense detection: https://arxiv.org/abs/1708.02002.

    Args:
        inputs (Tensor): A float tensor of arbitrary shape.
                The predictions for each example.
        targets (Tensor): A float tensor with the same shape as inputs. Stores the binary
                classification label for each element in inputs
                (0 for the negative class and 1 for the positive class).
        alpha (float): Weighting factor in range (0,1) to balance
                positive vs negative examples or -1 for ignore. Default: ``0.25``.
        gamma (float): Exponent of the modulating factor (1 - p_t) to
                balance easy vs hard examples. Default: ``2``.
        reduction (string): ``'none'`` | ``'mean'`` | ``'sum'``
                ``'none'``: No reduction will be applied to the output.
                ``'mean'``: The output will be averaged.
                ``'sum'``: The output will be summed. Default: ``'none'``.
    Returns:
        Loss tensor with the reduction option applied.
    r   )r
   é   r   ÚmeanÚsumz$Invalid Value for arg 'reduction': 'z3 
 Supported reduction modes: 'none', 'mean', 'sum')ÚtorchZjitZis_scriptingÚ
is_tracingr   Úsigmoid_focal_lossZsigmoidÚFZ binary_cross_entropy_with_logitsr   r   Ú
ValueError)
r   r   r   r	   r
   ÚpZce_lossZp_tZlossZalpha_t© r   úY/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torchvision/ops/focal_loss.pyr      s&    



ÿr   )r   r   r   )r   Ztorch.nn.functionalÚnnZ
functionalr   Úutilsr   ZTensorÚfloatÚstrr   r   r   r   r   Ú<module>   s      ûú