Skip to content

Commit

Permalink
Update objectness IoU sort (ultralytics#3786)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher authored Jun 26, 2021
1 parent 77cfd67 commit 7bfb728
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions utils/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class ComputeLoss:
# Compute losses
def __init__(self, model, autobalance=False):
super(ComputeLoss, self).__init__()
self.sort_obj_iou = False
device = next(model.parameters()).device # get model device
h = model.hyp # hyperparameters

Expand Down Expand Up @@ -134,8 +135,9 @@ def __call__(self, p, targets): # predictions, targets, model

# Objectness
score_iou = iou.detach().clamp(0).type(tobj.dtype)
sort_id = torch.argsort(score_iou)
b, a, gj, gi, score_iou = b[sort_id], a[sort_id], gj[sort_id], gi[sort_id], score_iou[sort_id]
if self.sort_obj_iou:
sort_id = torch.argsort(score_iou)
b, a, gj, gi, score_iou = b[sort_id], a[sort_id], gj[sort_id], gi[sort_id], score_iou[sort_id]
tobj[b, a, gj, gi] = (1.0 - self.gr) + self.gr * score_iou # iou ratio

# Classification
Expand Down

0 comments on commit 7bfb728

Please sign in to comment.