This commit is contained in:
Glenn Jocher
2019-07-11 11:56:46 +02:00
parent 3373006d0e
commit b005a17eff
2 changed files with 6 additions and 6 deletions
+5 -5
View File
@@ -281,7 +281,7 @@ def compute_loss(p, targets, model, giou_loss=True): # predictions, targets, mo
MSE = nn.MSELoss()
BCEcls = nn.BCEWithLogitsLoss(pos_weight=ft([h['cls_pw']]))
BCEobj = nn.BCEWithLogitsLoss(pos_weight=ft([h['obj_pw']]))
CE = nn.CrossEntropyLoss() # (weight=model.class_weights)
# CE = nn.CrossEntropyLoss() # (weight=model.class_weights)
# Compute losses
bs = p[0].shape[0] # batch size
@@ -304,10 +304,10 @@ def compute_loss(p, targets, model, giou_loss=True): # predictions, targets, mo
lxy += (k * h['xy']) * MSE(torch.sigmoid(pi[..., 0:2]), txy[i]) # xy loss
lwh += (k * h['wh']) * MSE(pi[..., 2:4], twh[i]) # wh yolo loss
# tclsm = torch.zeros_like(pi[..., 5:])
# tclsm[range(len(b)), tcls[i]] = 1.0
# lcls += (k * h['cls']) * BCEcls(pi[..., 5:], tclsm) # cls loss (BCE)
lcls += (k * h['cls']) * CE(pi[..., 5:], tcls[i]) # cls loss (CE)
tclsm = torch.zeros_like(pi[..., 5:])
tclsm[range(len(b)), tcls[i]] = 1.0
lcls += (k * h['cls']) * BCEcls(pi[..., 5:], tclsm) # cls loss (BCE)
# lcls += (k * h['cls']) * CE(pi[..., 5:], tcls[i]) # cls loss (CE)
# Append targets to text file
# with open('targets.txt', 'a') as file: