o
    Vhs	                     @   sZ   d dl Z d dlm  mZ ddlmZ 			dde jde jded	ed
e	de jfddZ
dS )    N   )_log_api_usage_once      ?noneinputstargetsalphagamma	reductionreturnc           
      C   s   d|  kr
dksn |dkrt d| dtj s%tj s%tt t| }tj	| |dd}|| d| d|   }|d| |  }|dkrZ|| d| d|   }	|	| }|dkra	 |S |dkrk|
 }|S |d	kru| }|S t d
| d)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      zInvalid alpha value: z4. alpha must be in the range [0,1] or -1 for ignore.r   )r
   meansumz$Invalid Value for arg 'reduction': 'z3 
 Supported reduction modes: 'none', 'mean', 'sum')
ValueErrortorchjitis_scripting
is_tracingr   sigmoid_focal_losssigmoidF binary_cross_entropy_with_logitsr   r   )
r   r   r   r	   r
   pce_lossp_tlossalpha_t r   N/var/www/vscode/kcb/lib/python3.10/site-packages/torchvision/ops/focal_loss.pyr      s.   
	
r   )r   r   r   )r   torch.nn.functionalnn
functionalr   utilsr   Tensorfloatstrr   r   r   r   r   <module>   s&    