Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions val.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down