@@ -325,13 +325,13 @@ def complete_box_iou(boxes1: Tensor, boxes2: Tensor, eps: float = 1e-7) -> Tenso
325
325
326
326
diou , iou = _box_diou_iou (boxes1 , boxes2 , eps )
327
327
328
- w_pred = boxes1 [:, 2 ] - boxes1 [:, 0 ]
329
- h_pred = boxes1 [:, 3 ] - boxes1 [:, 1 ]
328
+ w_pred = boxes1 [:, None , 2 ] - boxes1 [:, None , 0 ]
329
+ h_pred = boxes1 [:, None , 3 ] - boxes1 [:, None , 1 ]
330
330
331
331
w_gt = boxes2 [:, 2 ] - boxes2 [:, 0 ]
332
332
h_gt = boxes2 [:, 3 ] - boxes2 [:, 1 ]
333
333
334
- v = (4 / (torch .pi ** 2 )) * torch .pow (( torch .atan (w_gt / h_gt ) - torch .atan (w_pred / h_pred ) ), 2 )
334
+ v = (4 / (torch .pi ** 2 )) * torch .pow (torch .atan (w_pred / h_pred ) - torch .atan (w_gt / h_gt ), 2 )
335
335
with torch .no_grad ():
336
336
alpha = v / (1 - iou + v + eps )
337
337
return diou - alpha * v
@@ -358,7 +358,7 @@ def distance_box_iou(boxes1: Tensor, boxes2: Tensor, eps: float = 1e-7) -> Tenso
358
358
359
359
boxes1 = _upcast (boxes1 )
360
360
boxes2 = _upcast (boxes2 )
361
- diou , _ = _box_diou_iou (boxes1 , boxes2 )
361
+ diou , _ = _box_diou_iou (boxes1 , boxes2 , eps = eps )
362
362
return diou
363
363
364
364
@@ -375,7 +375,9 @@ def _box_diou_iou(boxes1: Tensor, boxes2: Tensor, eps: float = 1e-7) -> Tuple[Te
375
375
x_g = (boxes2 [:, 0 ] + boxes2 [:, 2 ]) / 2
376
376
y_g = (boxes2 [:, 1 ] + boxes2 [:, 3 ]) / 2
377
377
# The distance between boxes' centers squared.
378
- centers_distance_squared = (_upcast (x_p - x_g ) ** 2 ) + (_upcast (y_p - y_g ) ** 2 )
378
+ centers_distance_squared = (_upcast ((x_p [:, None ] - x_g [None , :])) ** 2 ) + (
379
+ _upcast ((y_p [:, None ] - y_g [None , :])) ** 2
380
+ )
379
381
# The distance IoU is the IoU penalized by a normalized
380
382
# distance between boxes' centers squared.
381
383
return iou - (centers_distance_squared / diagonal_distance_squared ), iou
0 commit comments