You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The calculation of Average Precision in compute_ap is wrong.
The current calculation outputs small AP since the integral range is narrower than [0, 1].
I think the correct calculation is as below.
Please let me know if my calculation is wrong.
def compute_ap(pred_annos, num_gt):
pred_annos = sorted(pred_annos, key=cmp_to_key(cmp))
num_tp = np.zeros(len(pred_annos))
for i in range(len(pred_annos)):
num_tp[i] = 0 if i == 0 else num_tp[i - 1]
if pred_annos[i]["type"] == "tp":
num_tp[i] += 1
# logger.debug("num tp = {}".format(num_tp))
precision = num_tp / np.arange(1, len(pred_annos) + 1) # Precision = TP / (TP + FP)
recall = num_tp / num_gt # Recall = TP / (TP + FN)
recall = np.concatenate([[0], recall, [1]])
precision = np.concatenate([precision, [precision[-1]]])
for i in range(len(pred_annos) - 1, 0, -1):
precision[i - 1] = max(precision[i], precision[i - 1])
dr = recall[1:] - recall[:-1]
ap = np.sum(precision * dr)
return ap
The text was updated successfully, but these errors were encountered:
The calculation of Average Precision in
compute_ap
is wrong.The current calculation outputs small AP since the integral range is narrower than [0, 1].
I think the correct calculation is as below.
Please let me know if my calculation is wrong.
The text was updated successfully, but these errors were encountered: