
    h
                         S SK r SSKJr  SSKJrJr    SS\ R                  S\ R                  S\S	\S
\ R                  4
S jjr	g)    N   )_log_api_usage_once   )_loss_inter_union_upcast_non_floatboxes1boxes2	reductionepsreturnc                    [         R                  R                  5       (       d2  [         R                  R                  5       (       d  [	        [
        5        [        U 5      n [        U5      n[        X5      u  pEXEU-   -  nU R                  SS9u  pxpUR                  SS9u  pp[         R                  " X{5      n[         R                  " X5      n[         R                  " X5      n[         R                  " X5      nUU-
  UU-
  -  nUUU-
  UU-   -  -
  nSU-
  nUS:X  a   U$ US:X  a;  UR                  5       S:  a  UR                  5       nU$ SUR                  5       -  nU$ US:X  a  UR                  5       nU$ [        S	U S
35      e)at  
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   nonemeanr   g        sumz$Invalid Value for arg 'reduction': 'z3 
 Supported reduction modes: 'none', 'mean', 'sum')torchjitis_scripting
is_tracingr   generalized_box_iou_lossr   r   unbindminmaxnumelr   r   
ValueError)r   r	   r
   r   intsctkunionkioukx1y1x2y2x1gy1gx2gy2gxc1yc1xc2yc2area_cmiouklosss                         Q/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/ops/giou_loss.pyr   r      s   F 99!!##EII,@,@,B,B45v&Fv&F'7OGsl#D]]r]*NBB2.Cc ))B
C
))B
C
))B
C
))B
CCiC#I&FVf_#67Eu9D F K 
f	"jjlQ.tyy{ K 58$((*4D K 
e	xxz
 K 29+=qr
 	
    )r   gHz>)
r   utilsr   _utilsr   r   Tensorstrfloatr    r0   r/   <module>r7      s[     ' 8 	DLLDLLD D 
	D
 \\Dr0   