Skip to content

Commit

Permalink
fix(loss): fix the wrong implementation of GIoU (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joker316701882 committed Sep 22, 2021
1 parent 2213f2f commit 9a957f5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions yolox/models/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def forward(self, pred, target):

en = (tl < br).type(tl.type()).prod(dim=1)
area_i = torch.prod(br - tl, 1) * en
iou = (area_i) / (area_p + area_g - area_i + 1e-16)
area_u = area_p + area_g - area_i
iou = (area_i) / (area_u + 1e-16)

if self.loss_type == "iou":
loss = 1 - iou ** 2
Expand All @@ -41,7 +42,7 @@ def forward(self, pred, target):
(pred[:, :2] + pred[:, 2:] / 2), (target[:, :2] + target[:, 2:] / 2)
)
area_c = torch.prod(c_br - c_tl, 1)
giou = iou - (area_c - area_i) / area_c.clamp(1e-16)
giou = iou - (area_c - area_u) / area_c.clamp(1e-16)
loss = 1 - giou.clamp(min=-1.0, max=1.0)

if self.reduction == "mean":
Expand Down

0 comments on commit 9a957f5

Please sign in to comment.