updates
This commit is contained in:
parent
50b1bb71be
commit
082fdebfc1
2
train.py
2
train.py
|
@ -341,7 +341,7 @@ if __name__ == '__main__':
|
||||||
parser.add_argument('--cfg', type=str, default='cfg/yolov3-spp.cfg', help='cfg file path')
|
parser.add_argument('--cfg', type=str, default='cfg/yolov3-spp.cfg', help='cfg file path')
|
||||||
parser.add_argument('--data', type=str, default='data/coco.data', help='coco.data file path')
|
parser.add_argument('--data', type=str, default='data/coco.data', help='coco.data file path')
|
||||||
parser.add_argument('--multi-scale', action='store_true', help='train at (1/1.5)x - 1.5x sizes')
|
parser.add_argument('--multi-scale', action='store_true', help='train at (1/1.5)x - 1.5x sizes')
|
||||||
parser.add_argument('--img-size', type=int, default=320, help='inference size (pixels)')
|
parser.add_argument('--img-size', type=int, default=416, help='inference size (pixels)')
|
||||||
parser.add_argument('--rect', action='store_true', help='rectangular training')
|
parser.add_argument('--rect', action='store_true', help='rectangular training')
|
||||||
parser.add_argument('--resume', action='store_true', help='resume training flag')
|
parser.add_argument('--resume', action='store_true', help='resume training flag')
|
||||||
parser.add_argument('--transfer', action='store_true', help='transfer learning flag')
|
parser.add_argument('--transfer', action='store_true', help='transfer learning flag')
|
||||||
|
|
|
@ -180,18 +180,25 @@ def ap_per_class(tp, conf, pred_cls, target_cls):
|
||||||
tpc = (tp[i]).cumsum()
|
tpc = (tp[i]).cumsum()
|
||||||
|
|
||||||
# Recall
|
# Recall
|
||||||
recall_curve = tpc / (n_gt + 1e-16)
|
recall = tpc / (n_gt + 1e-16) # recall curve
|
||||||
r.append(recall_curve[-1])
|
r.append(recall[-1])
|
||||||
|
|
||||||
# Precision
|
# Precision
|
||||||
precision_curve = tpc / (tpc + fpc)
|
precision = tpc / (tpc + fpc) # precision curve
|
||||||
p.append(precision_curve[-1])
|
p.append(precision[-1])
|
||||||
|
|
||||||
# AP from recall-precision curve
|
# AP from recall-precision curve
|
||||||
ap.append(compute_ap(recall_curve, precision_curve))
|
ap.append(compute_ap(recall, precision))
|
||||||
|
|
||||||
# Plot
|
# Plot
|
||||||
# plt.plot(recall_curve, precision_curve)
|
# fig, ax = plt.subplots(1, 1, figsize=(4, 4))
|
||||||
|
# ax.plot(np.concatenate(([0.], recall)), np.concatenate(([0.], precision)))
|
||||||
|
# ax.set_xlabel('YOLOv3-SPP')
|
||||||
|
# ax.set_xlabel('Recall')
|
||||||
|
# ax.set_ylabel('Precision')
|
||||||
|
# ax.set_xlim(0, 1)
|
||||||
|
# fig.tight_layout()
|
||||||
|
# fig.savefig('PR_curve.png', dpi=300)
|
||||||
|
|
||||||
# Compute F1 score (harmonic mean of precision and recall)
|
# Compute F1 score (harmonic mean of precision and recall)
|
||||||
p, r, ap = np.array(p), np.array(r), np.array(ap)
|
p, r, ap = np.array(p), np.array(r), np.array(ap)
|
||||||
|
@ -209,21 +216,18 @@ def compute_ap(recall, precision):
|
||||||
# Returns
|
# Returns
|
||||||
The average precision as computed in py-faster-rcnn.
|
The average precision as computed in py-faster-rcnn.
|
||||||
"""
|
"""
|
||||||
# correct AP calculation
|
# Append sentinel values to beginning and end
|
||||||
# first append sentinel values at the end
|
|
||||||
|
|
||||||
mrec = np.concatenate(([0.], recall, [1.]))
|
mrec = np.concatenate(([0.], recall, [1.]))
|
||||||
mpre = np.concatenate(([0.], precision, [0.]))
|
mpre = np.concatenate(([0.], precision, [0.]))
|
||||||
|
|
||||||
# compute the precision envelope
|
# Compute the precision envelope
|
||||||
for i in range(mpre.size - 1, 0, -1):
|
for i in range(mpre.size - 1, 0, -1):
|
||||||
mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i])
|
mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i])
|
||||||
|
|
||||||
# to calculate area under PR curve, look for points
|
# Calculate area under PR curve, looking for points where x axis (recall) changes
|
||||||
# where X axis (recall) changes value
|
|
||||||
i = np.where(mrec[1:] != mrec[:-1])[0]
|
i = np.where(mrec[1:] != mrec[:-1])[0]
|
||||||
|
|
||||||
# and sum (\Delta recall) * prec
|
# Sum (\Delta recall) * prec
|
||||||
ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1])
|
ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1])
|
||||||
return ap
|
return ap
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue