diff --git a/utils/metrics.py b/utils/metrics.py index e17747b703fa..44b279d35c48 100644 --- a/utils/metrics.py +++ b/utils/metrics.py @@ -103,8 +103,8 @@ def compute_ap(recall, precision): """ # Append sentinel values to beginning and end - mrec = np.concatenate(([0.0], recall, [1.0])) - mpre = np.concatenate(([1.0], precision, [0.0])) + mrec = recall + mpre = precision # Compute the precision envelope mpre = np.flip(np.maximum.accumulate(np.flip(mpre))) @@ -113,7 +113,7 @@ def compute_ap(recall, precision): method = 'interp' # methods: 'continuous', 'interp' if method == 'interp': x = np.linspace(0, 1, 101) # 101-point interp (COCO) - ap = np.trapz(np.interp(x, mrec, mpre), x) # integrate + ap = np.interp(x, mrec, mpre, right=0).mean() # integrate with rect else: # 'continuous' i = np.where(mrec[1:] != mrec[:-1])[0] # points where x axis (recall) changes ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1]) # area under curve diff --git a/val.py b/val.py index f4f4bab7e92d..68b40b645db6 100644 --- a/val.py +++ b/val.py @@ -214,7 +214,13 @@ def run( targets[:, 2:] *= torch.tensor((width, height, width, height), device=device) # to pixels lb = [targets[targets[:, 0] == i, 1:] for i in range(nb)] if save_hybrid else [] # for autolabelling t3 = time_sync() - out = non_max_suppression(out, conf_thres, iou_thres, labels=lb, multi_label=True, agnostic=single_cls) + out = non_max_suppression(out, + conf_thres, + iou_thres, + labels=lb, + multi_label=True, + agnostic=single_cls, + max_det=100) dt[2] += time_sync() - t3 # Metrics @@ -227,7 +233,7 @@ def run( if npr == 0: if nl: - stats.append((correct, *torch.zeros((3, 0), device=device))) + stats.append((correct, *torch.zeros((2, 0), device=device), labels[:, 0])) continue # Predictions