Evaluate predictions and bounding boxes
Score how well a predicted box matches the truth with IoU, and evaluate a detector.
- Calculate intersection over union (IoU) from box coordinates
- Decide when a detection counts as correct
- Explain precision and recall for detectors
A detector’s box is almost never pixel-perfect, so how close is close enough? The standard measure is intersection over union (IoU): the area where the predicted and true boxes overlap, divided by the area they cover together. It runs from 0 (no overlap) to 1 (identical boxes).
1intersection = 40
2union = 100
3iou = intersection / union
4print(round(iou, 2))0.4
Try it
Up to 15 XPGuess the IoU
Green is the true box, blue the prediction. Guess the IoU range before revealing it. Most people overestimate: watch how quickly IoU drops when a box is shifted or too big.
What is the IoU (intersection over union)?
Computing IoU from coordinates
With corner coordinates, the overlap is itself a box: its left edge is the larger of the two left edges, its right edge the smaller of the two right edges (same for top and bottom). If the edges cross, there is no overlap. Then union = area A + area B − intersection - subtracting the intersection so it isn’t counted twice.
Evaluating a detector
A predicted box counts as a true positive if its IoU with an unmatched true box of the same class passes a threshold (0.5 is common); otherwise it is a false positive. True objects nobody found are false negatives. From these come precision and recall, and the standard summary, mean average precision (mAP), averages precision over recall levels, classes and often several IoU thresholds.
Key takeaways
IoU = overlap area ÷ combined area; 1 means identical boxes.
A detection is correct when IoU passes a threshold (often 0.5) for an unmatched true box.
Precision, recall and mAP summarize a detector - but always check results by subgroup.
Lesson quiz
6 questions · pass with 5 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Practice: apply computer vision with Python
Use small pixel arrays to explore vision concepts, run your code against sample images, and connect each result to the larger computer vision idea.
Calculate box overlap
Read intersection area and union area as two numbers. Print IoU to two decimal places. The union area is positive.
- Partial overlap
- Perfect overlap
Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.
IoU from two boxes
Read two boxes, one per line, as corners x1 y1 x2 y2. Print their IoU rounded to 2 decimals (0.0 when they don’t overlap).
- Half shifted
- Identical
- Apart
Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…