Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Oct 1, 2019
1 parent 9a48f23 commit 84f0df6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def compute_ap(recall, precision):
# Returns
The average precision as computed in py-faster-rcnn.
"""

# Append sentinel values to beginning and end
mrec = np.concatenate(([0.], recall, [1.]))
mpre = np.concatenate(([0.], precision, [0.]))
Expand All @@ -232,11 +233,15 @@ def compute_ap(recall, precision):
for i in range(mpre.size - 1, 0, -1):
mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i])

# Calculate area under PR curve, looking for points where x axis (recall) changes
i = np.where(mrec[1:] != mrec[:-1])[0]
# Integrate area under curve
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
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

# Sum (\Delta recall) * prec
ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1])
return ap


Expand Down

0 comments on commit 84f0df6

Please sign in to comment.