提交 305c6a02 authored 作者: Glenn Jocher's avatar Glenn Jocher

compute_loss() leaf variable update

上级 c1a2a7a4
......@@ -439,7 +439,7 @@ class BCEBlurWithLogitsLoss(nn.Module):
def compute_loss(p, targets, model): # predictions, targets, model
device = targets.device
lcls, lbox, lobj = torch.zeros(3, 1, device=device)
lcls, lbox, lobj = torch.zeros(1, device=device), torch.zeros(1, device=device), torch.zeros(1, device=device)
tcls, tbox, indices, anchors = build_targets(p, targets, model) # targets
h = model.hyp # hyperparameters
......@@ -482,13 +482,13 @@ def compute_loss(p, targets, model): # predictions, targets, model
if model.nc > 1: # cls loss (only if multiple classes)
t = torch.full_like(ps[:, 5:], cn, device=device) # targets
t[range(n), tcls[i]] = cp
lcls = lcls + BCEcls(ps[:, 5:], t) # BCE
lcls += BCEcls(ps[:, 5:], t) # BCE
# Append targets to text file
# with open('targets.txt', 'a') as file:
# [file.write('%11.5g ' * 4 % tuple(x) + '\n') for x in torch.cat((txy[i], twh[i]), 1)]
lobj = lobj + BCEobj(pi[..., 4], tobj) * balance[i] # obj loss
lobj += BCEobj(pi[..., 4], tobj) * balance[i] # obj loss
s = 3 / np # output count scaling
lbox *= h['giou'] * s
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论