diff --git a/models.py b/models.py index d6e31eaa..eb2fdcea 100755 --- a/models.py +++ b/models.py @@ -156,7 +156,8 @@ class YOLOLayer(nn.Module): io[..., :4] *= self.stride io[..., 4:] = torch.sigmoid(io[..., 4:]) # p_conf, p_cls - # io[..., 5:] = F.softmax(io[..., 5:], dim=4) # p_cls + # io[..., 4:] = F.softmax(io[..., 4:], dim=4) # unified detection CE + # io[..., 4] = io[..., 5:].max(4)[0] # unified detection BCE if self.nc == 1: io[..., 5] = 1 # single-class model https://github.com/ultralytics/yolov3/issues/235 diff --git a/train.py b/train.py index 8df94557..0166dccb 100644 --- a/train.py +++ b/train.py @@ -37,7 +37,7 @@ except: hyp = {'giou': 1.582, # giou loss gain 'xy': 4.688, # xy loss gain 'wh': 0.1857, # wh loss gain - 'cls': 27.76, # cls loss gain (CE should be around ~1.0) + 'cls': 27.76, # cls loss gain (CE=~1.0, uCE=~20, uBCE=~200,~30) 'cls_pw': 1.446, # cls BCELoss positive_weight 'obj': 21.35, # obj loss gain 'obj_pw': 3.941, # obj BCELoss positive_weight diff --git a/utils/utils.py b/utils/utils.py index 13a9f85e..0a0ed43c 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -324,6 +324,14 @@ def compute_loss(p, targets, model, giou_loss=True): # predictions, targets, mo lcls += (k * h['cls']) * BCEcls(pi[..., 5:], tclsm) # BCE # lcls += (k * h['cls']) * CE(pi[..., 5:], tcls[i]) # CE + # udm_ce = torch.zeros_like(pi0[..., 0]).long() # unified detection matrix for CE + # udm_ce[b, a, gj, gi] = tcls[i] + 1 + # lcls += (k * h['cls']) * CE(pi0[..., 4:].view(-1, model.nc + 1), udm_ce.view(-1)) # unified CE + + # udm = torch.zeros_like(pi0[..., 5:]) # unified detection matrix for BCE + # udm[b, a, gj, gi, tcls[i]] = 1.0 + # lcls += (k * h['cls']) * BCEcls(pi0[..., 5:], udm) # unified BCE (hyps 200-30) + # 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)]