a
    PSicÁ	  ã                   @   sN   d dl Z ddlmZ ddlmZ ddlmZ de je jee	e jd	œd
d„Z
dS )é    Né   )Ú_log_api_usage_onceé   )Ú_upcast_non_float)Ú_diou_iou_lossÚnoneçH¯¼šò×z>)Úboxes1Úboxes2Ú	reductionÚepsÚreturnc                 C   s@  t j ¡ st j ¡ sttƒ t| ƒ} t|ƒ}t| |ƒ\}}| jdd\}}}}	|jdd\}
}}}|| }|	| }||
 }|| }dt j	d  t  
t  || ¡t  || ¡ d¡ }t  ¡ $ |d| | |  }W d  ƒ n1 sæ0    Y  |||  }|dkr*| ¡ dkr| ¡ n
d	| ¡  }n|d
kr<| ¡ }|S )aã  
    Gradient-friendly IoU loss with an additional penalty that is non-zero when the
    boxes do not overlap. This loss function considers important geometrical
    factors such as overlap area, normalized central point distance and aspect ratio.
    This loss is symmetric, so the boxes1 and boxes2 arguments are interchangeable.

    Both sets of boxes are expected to be in ``(x1, y1, x2, y2)`` format with
    ``0 <= x1 < x2`` and ``0 <= y1 < y2``, and The two boxes should have the
    same dimensions.

    Args:
        boxes1 : (Tensor[N, 4] or Tensor[4]) first set of boxes
        boxes2 : (Tensor[N, 4] or Tensor[4]) second set of boxes
        reduction : (string, optional) Specifies the reduction to apply to the output:
            ``'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'``
        eps : (float): small number to prevent division by zero. Default: 1e-7

    Returns:
        Tensor: Loss tensor with the reduction option applied.

    Reference:
        Zhaohui Zheng et al.: Complete Intersection over Union Loss:
        https://arxiv.org/abs/1911.08287

    éÿÿÿÿ)Údimé   r   r   NÚmeanr   g        Úsum)ÚtorchÚjitÚis_scriptingÚ
is_tracingr   Úcomplete_box_iou_lossr   r   ÚunbindÚpiÚpowÚatanÚno_gradÚnumelr   r   )r	   r
   r   r   Ú	diou_lossÚiouÚx1Úy1Úx2Úy2Úx1gÚy1gÚx2gÚy2gÚw_predÚh_predÚw_gtÚh_gtÚvÚalphaÚloss© r/   úU/var/www/html/django/DPS/env/lib/python3.9/site-packages/torchvision/ops/ciou_loss.pyr      s(    %2
2
$
r   )r   r   )r   Úutilsr   Ú_utilsr   r   r   ÚTensorÚstrÚfloatr   r/   r/   r/   r0   Ú<module>   s     üû