Why a scorer gave 125 perfect boxes only 80.20%
Picture 125 objects, each outlined by hand. A computer draws a second set of boxes. Every box lands exactly on its hand-drawn counterpart. You might expect a perfect score. The standard report gave us 80.20%.
The headline calculation allowed at most 100 boxes. We changed the settings so it could count all 125. In one report, the headline score still said 80.20%, while the score labeled AP50 reached 100%. The two calculations were counting different numbers of boxes.
Our test used one picture with 125 reference boxes. None of them overlapped. For each box we made a prediction that matched it exactly. Then we tried three settings in pycocotools 2.0.10, the software for the Common Objects in Context (COCO) evaluation. We changed how many predictions the scorer could consider for this picture and object category. At a limit of 100 it kept the 100 predictions with the highest confidence. Each row in the table shows a set of three limits tried on the same boxes.
Start with the first 100 boxes. Every one of them matched an object, so all the boxes the scorer considered were correct. That gives 100% precision. Those boxes accounted for 100 of the 125 objects in the picture. The share of objects found, called recall, was 80%.
To calculate average precision (AP), COCO checks a series of recall levels. At each level it uses the best precision achieved there or at higher recall. The headline AP also combines several rules for how closely a predicted box must overlap the reference box. AP50 uses just one rule. The overlap must cover at least half the area covered by the two boxes together, counting the overlap only once.
The standard summary expects the default limits. For its headline AP (stats[0]), it asks for the result at 100 boxes. For AP50 (stats[1]), it asks for the result at the third limit on the list, whatever that limit is. The last column below checks AP directly at the highest limit in each row. COCO summary code · Version of pycocotools tested
| Detection cap grid | Headline AP from stats[0] | AP50 from stats[1] | AP at the highest cap, from the precision array |
|---|---|---|---|
| 1, 10, 100 | 80.20% | 80.20% | 80.20% |
| 1, 10, 125 | Unavailable (-1) | 100.00% | 100.00% |
| 1, 100, 125 | 80.20% | 100.00% | 100.00% |
Take the first row. All 100 predictions the program counted were correct. That gives perfect precision up to 100 of the 125 objects, or 80% recall. To calculate AP, COCO samples precision at 101 recall levels, from 0% to 100% in one-point steps. The first 81 levels, including 0% and 80%, got a 1. The final 20 got a 0 because recall never reached them. The average was 81/101, or 80.20%.
What if the limit is 125? In the second row we replaced 100 with 125. AP50 could credit every box, but the headline field still asked for the missing 100-box result. It displayed -1, meaning unavailable. In the third row we kept both limits. This time the headline AP used 100 boxes and reported 80.20%, while AP50 used 125 and reported 100%. The last column confirms that AP itself reached 100% when calculated at 125. Because every prediction matched exactly, all the overlap rules accepted it. In this example the two scores differ solely because their limits differ.
When you report AP at a custom limit, give the limit alongside the score and check which result the summary actually selected. Detectron2 provides a way to ask for AP at the specific limit you intend to report. Detectron2’s custom-limit implementation
The choice of pictures can also change a detector’s score. See what happens when images without the target object are left out.