-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Fix d/c IoU for different batch sizes #6338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
63c5551
73b907d
d4bc35e
5777bfb
c5c39b3
7bef3d0
2936153
13d1961
97298f6
c69ce0c
26aba8d
aa1f992
1ba1c69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -325,13 +325,13 @@ def complete_box_iou(boxes1: Tensor, boxes2: Tensor, eps: float = 1e-7) -> Tenso | |||||||||
|
|
||||||||||
| diou, iou = _box_diou_iou(boxes1, boxes2, eps) | ||||||||||
|
|
||||||||||
| w_pred = boxes1[:, 2] - boxes1[:, 0] | ||||||||||
| h_pred = boxes1[:, 3] - boxes1[:, 1] | ||||||||||
| w_pred = boxes1[:, None, 2] - boxes1[:, None, 0] | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this is needed?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary for the broadcasting to work properly. See also: vision/torchvision/ops/boxes.py Lines 368 to 371 in ea0be26
|
||||||||||
| h_pred = boxes1[:, None, 3] - boxes1[:, None, 1] | ||||||||||
|
|
||||||||||
| w_gt = boxes2[:, 2] - boxes2[:, 0] | ||||||||||
| h_gt = boxes2[:, 3] - boxes2[:, 1] | ||||||||||
|
|
||||||||||
| v = (4 / (torch.pi**2)) * torch.pow((torch.atan(w_gt / h_gt) - torch.atan(w_pred / h_pred)), 2) | ||||||||||
| v = (4 / (torch.pi**2)) * torch.pow(torch.atan(w_pred / h_pred) - torch.atan(w_gt / h_gt), 2) | ||||||||||
fmassa marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| with torch.no_grad(): | ||||||||||
| alpha = v / (1 - iou + v + eps) | ||||||||||
| return diou - alpha * v | ||||||||||
|
|
@@ -358,7 +358,7 @@ def distance_box_iou(boxes1: Tensor, boxes2: Tensor, eps: float = 1e-7) -> Tenso | |||||||||
|
|
||||||||||
| boxes1 = _upcast(boxes1) | ||||||||||
| boxes2 = _upcast(boxes2) | ||||||||||
| diou, _ = _box_diou_iou(boxes1, boxes2) | ||||||||||
| diou, _ = _box_diou_iou(boxes1, boxes2, eps=eps) | ||||||||||
| return diou | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
@@ -375,7 +375,9 @@ def _box_diou_iou(boxes1: Tensor, boxes2: Tensor, eps: float = 1e-7) -> Tuple[Te | |||||||||
| x_g = (boxes2[:, 0] + boxes2[:, 2]) / 2 | ||||||||||
| y_g = (boxes2[:, 1] + boxes2[:, 3]) / 2 | ||||||||||
| # The distance between boxes' centers squared. | ||||||||||
| centers_distance_squared = (_upcast(x_p - x_g) ** 2) + (_upcast(y_p - y_g) ** 2) | ||||||||||
| centers_distance_squared = (_upcast((x_p[:, None] - x_g[None, :])) ** 2) + ( | ||||||||||
| _upcast((y_p[:, None] - y_g[None, :])) ** 2 | ||||||||||
| ) | ||||||||||
| # The distance IoU is the IoU penalized by a normalized | ||||||||||
| # distance between boxes' centers squared. | ||||||||||
| return iou - (centers_distance_squared / diagonal_distance_squared), iou | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.