diff --git a/models.py b/models.py index 2712c943..61c66dc1 100755 --- a/models.py +++ b/models.py @@ -123,16 +123,16 @@ class YOLOLayer(nn.Module): y = torch.sigmoid(p[..., 1]) # Center y # Width and height (yolo method) - w = p[..., 2] # Width - h = p[..., 3] # Height - width = torch.exp(w.data) * self.anchor_w - height = torch.exp(h.data) * self.anchor_h + # w = p[..., 2] # Width + # h = p[..., 3] # Height + # width = torch.exp(w.data) * self.anchor_w + # height = torch.exp(h.data) * self.anchor_h # Width and height (power method) - # w = torch.sigmoid(p[..., 2]) # Width - # h = torch.sigmoid(p[..., 3]) # Height - # width = ((w.data * 2) ** 2) * self.anchor_w - # height = ((h.data * 2) ** 2) * self.anchor_h + w = torch.sigmoid(p[..., 2]) # Width + h = torch.sigmoid(p[..., 3]) # Height + width = ((w.data * 2) ** 2) * self.anchor_w + height = ((h.data * 2) ** 2) * self.anchor_h # Add offset and scale with anchors (in grid space, i.e. 0-13) pred_boxes = FT(bs, self.nA, nG, nG, 4) @@ -168,13 +168,13 @@ class YOLOLayer(nn.Module): if nM > 0: lx = k * MSELoss(x[mask], tx[mask]) ly = k * MSELoss(y[mask], ty[mask]) - lw = (k * 0.7) * MSELoss(w[mask], tw[mask]) - lh = (k * 0.7) * MSELoss(h[mask], th[mask]) + lw = (k * 1) * MSELoss(w[mask], tw[mask]) + lh = (k * 1) * MSELoss(h[mask], th[mask]) # lconf = k * BCEWithLogitsLoss(pred_conf[mask], mask[mask].float()) - lconf = (k * 5) * BCEWithLogitsLoss(pred_conf, mask.float()) + lconf = (k * 10) * BCEWithLogitsLoss(pred_conf, mask.float()) - lcls = (k / 20) * CrossEntropyLoss(pred_cls[mask], torch.argmax(tcls, 1)) + lcls = (k / 10) * CrossEntropyLoss(pred_cls[mask], torch.argmax(tcls, 1)) # lcls = k * BCEWithLogitsLoss(pred_cls[mask], tcls.float()) else: lx, ly, lw, lh, lcls, lconf = FT([0]), FT([0]), FT([0]), FT([0]), FT([0]), FT([0]) diff --git a/utils/utils.py b/utils/utils.py index 314b12bf..55e7e64a 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -259,12 +259,12 @@ def build_targets(pred_boxes, pred_conf, pred_cls, target, anchor_wh, nA, nC, nG ty[b, a, gj, gi] = gy - gj.float() # Width and height (yolo method) - tw[b, a, gj, gi] = torch.log(gw / anchor_wh[a, 0]) - th[b, a, gj, gi] = torch.log(gh / anchor_wh[a, 1]) + # tw[b, a, gj, gi] = torch.log(gw / anchor_wh[a, 0]) + # th[b, a, gj, gi] = torch.log(gh / anchor_wh[a, 1]) # Width and height (power method) - # tw[b, a, gj, gi] = torch.sqrt(gw / anchor_wh[a, 0]) / 2 - # th[b, a, gj, gi] = torch.sqrt(gh / anchor_wh[a, 1]) / 2 + tw[b, a, gj, gi] = torch.sqrt(gw / anchor_wh[a, 0]) / 2 + th[b, a, gj, gi] = torch.sqrt(gh / anchor_wh[a, 1]) / 2 # One-hot encoding of label tcls[b, a, gj, gi, tc] = 1 @@ -436,8 +436,9 @@ def plot_results(): import matplotlib.pyplot as plt plt.figure(figsize=(16, 8)) s = ['X', 'Y', 'Width', 'Height', 'Objectness', 'Classification', 'Total Loss', 'Precision', 'Recall', 'mAP'] - for f in ('results.txt',): - results = np.loadtxt(f, usecols=[2, 3, 4, 5, 6, 7, 8, 9, 10]).T + for f in ('results.txt', + ): + results = np.loadtxt(f, usecols=[2, 3, 4, 5, 6, 7, 8, 9, 10]).T # column 16 is mAP for i in range(9): plt.subplot(2, 5, i + 1) plt.plot(results[i, :250], marker='.', label=f)