diff --git a/utils/utils.py b/utils/utils.py index 31532d9f20..4ed84a2c8c 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -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.])) @@ -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