Precision-Recall Curve Points
You are given detection results (whether each detection matched a ground truth object) and need to compute precision and recall at each detection to construct a PR curve.
Detections should be processed in order of decreasing confidence (highest first).
For each detection processed:
- Precision = True Positives / Total Detections So Far
- Recall = True Positives / Total Ground Truth Objects
Where:
- TP = detections that matched a ground truth
- FP = detections that didn't match (false alarms)
- num_gt = total ground truth objects
Round precision and recall to 4 decimal places.
Example
matches = [True, False, True] num_gt = 3
[(1.0, 0.3333), (0.5, 0.3333), (0.6667, 0.6667)]
- Inputs:
matcheslists the three detections from most to least confident: a hit, a false alarm, then another hit.num_gt= 3 means three real objects exist in the image, whether or not anything found them. - After detection 1 (hit): TP out of detection, so precision and recall .
- After detection 2 (false alarm): TP stays , but detections have now been made, so precision falls to . Recall is still , because a false alarm finds no new object.
- After detection 3 (hit): TP out of detections, so precision and recall .
- Output: one (precision, recall) pair per detection, rounded to 4 decimal places:
[(1.0, 0.3333), (0.5, 0.3333), (0.6667, 0.6667)]. - Notice that recall can only rise or stay flat as you go down the list, while precision can drop and recover. That is why PR curves zigzag. Recall here never reaches : one object was never detected.
Constraints
- matches: list of booleans, True if detection matched ground truth, False otherwise
- Detections are already sorted by confidence (highest first)
- num_gt: total number of ground truth objects
- Return list of (precision, recall) tuples