Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mAP calculations #7714

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Fix mAP calucation
  • Loading branch information
comlhj1114 committed May 6, 2022
commit ad25966c2ed636c2cdf4822618e74a916c65ce66
8 changes: 4 additions & 4 deletions utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def ap_per_class(tp, conf, pred_cls, target_cls, plot=False, save_dir='.', names

# Recall
recall = tpc / (n_l + eps) # recall curve
r[ci] = np.interp(-px, -conf[i], recall[:, 0], left=0) # negative x, xp because xp decreases
r[ci] = np.interp(-px, -conf[i], recall[:, 0], left=0, right=0) # negative x, xp because xp decreases

# Precision
precision = tpc / (tpc + fpc) # precision curve
p[ci] = np.interp(-px, -conf[i], precision[:, 0], left=1) # p at pr_score
p[ci] = np.interp(-px, -conf[i], precision[:, 0], left=0, right=0) # p at pr_score

# AP from recall-precision curve
for j in range(tp.shape[1]):
Expand Down Expand Up @@ -96,8 +96,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 = np.concatenate((recall, [recall[-1]+0.001]))
mpre = np.concatenate((precision, [0.0]))

# Compute the precision envelope
mpre = np.flip(np.maximum.accumulate(np.flip(mpre)))
Expand Down