a
    PSic	                     @   sF   d dl Z ddlmZ ddlmZ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_loss_inter_unionnoneHz>)boxes1boxes2	reductionepsreturnc                 C   s
  t j st j stt t| } t|}t| |\}}|||  }| jdd\}}}	}
|jdd\}}}}t 	||}t 	||}t 
|	|}t 
|
|}|| ||  }||| ||   }d| }|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 and scales with the size of their smallest enclosing box.
    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:
        Hamid Rezatofighi et. al: Generalized Intersection over Union:
        A Metric and A Loss for Bounding Box Regression:
        https://arxiv.org/abs/1902.09630
    )dimr   meanr   g        sum)torchjitis_scripting
is_tracingr   generalized_box_iou_lossr   r   unbindminmaxnumelr   r   )r	   r
   r   r   intsctkunionkZioukx1y1x2y2x1gy1gx2gy2gxc1yc1xc2yc2Zarea_cZmioukloss r*   U/var/www/html/django/DPS/env/lib/python3.9/site-packages/torchvision/ops/giou_loss.pyr      s(    $"
r   )r   r   )
r   utilsr   _utilsr   r   Tensorstrfloatr   r*   r*   r*   r+   <module>   s     