This commit is contained in:
Glenn Jocher 2020-03-08 16:13:56 -07:00
parent 0037254bf2
commit 1d43b2a55a
1 changed files with 9 additions and 2 deletions

View File

@ -405,8 +405,15 @@ def compute_loss(p, targets, model): # predictions, targets, model
tobj[b, a, gj, gi] = (1.0 - model.gr) + model.gr * giou.detach().clamp(0).type(tobj.dtype) # giou ratio tobj[b, a, gj, gi] = (1.0 - model.gr) + model.gr * giou.detach().clamp(0).type(tobj.dtype) # giou ratio
if 'default' in arc and model.nc > 1: # cls loss (only if multiple classes) if 'default' in arc and model.nc > 1: # cls loss (only if multiple classes)
t = torch.zeros_like(ps[:, 5:]) # targets smooth = False # class label smoothing https://arxiv.org/pdf/1902.04103.pdf eqn 3
t[range(nb), tcls[i]] = 1.0 if smooth:
e = 0.1 #  class label smoothing epsilon
cp, cn = 1.0 - e, e / (model.nc - 0.99) # class positive and negative labels
else:
cp, cn = 1.0, 0.0
t = torch.zeros_like(ps[:, 5:]) + cn # targets
t[range(nb), tcls[i]] = cp
lcls += BCEcls(ps[:, 5:], t) # BCE lcls += BCEcls(ps[:, 5:], t) # BCE
# lcls += CE(ps[:, 5:], tcls[i]) # CE # lcls += CE(ps[:, 5:], tcls[i]) # CE