IoU, or Intersection over Union, measures how much two shapes overlap. In computer vision, it tells us how well a model's predicted box matches the true box around an object. The higher the IoU, the better the prediction. It matters because it directly shows the quality of object detection or segmentation.
IoU (Intersection over Union) in Computer Vision - Model Metrics & Evaluation
IoU is not a confusion matrix but a ratio:
IoU = Area of Overlap / Area of Union
For example:
- Predicted box area = 40
- Ground truth box area = 50
- Overlap area = 30
IoU = 30 / (40 + 50 - 30) = 30 / 60 = 0.5
This means the predicted box covers half of the combined area of prediction and truth.
IoU helps decide if a detection counts as correct. Usually, a threshold like 0.5 is set:
- If IoU ≥ 0.5, prediction is a true positive (good match).
- If IoU < 0.5, prediction is a false positive (bad match).
Raising the threshold means stricter matching (higher precision, fewer false positives) but may miss some true objects (lower recall). Lowering it catches more objects (higher recall) but risks more wrong matches (lower precision).
Good IoU values are close to 1.0, meaning predicted and true boxes almost perfectly overlap.
- IoU ≥ 0.75: Excellent detection
- 0.5 ≤ IoU < 0.75: Acceptable detection
- IoU < 0.5: Poor detection, likely a false positive
For example, an IoU of 0.8 means the prediction is very accurate. An IoU of 0.3 means the prediction barely overlaps the true object.
- Using IoU alone ignores confidence scores; a high IoU but low confidence prediction might be ignored.
- IoU threshold choice affects evaluation; too high can unfairly penalize good detections.
- Small objects can have low IoU even with small shifts, making evaluation tricky.
- IoU does not capture class correctness; a box can overlap well but predict the wrong object type.
Your object detection model has an average IoU of 0.4 on test images. Is this good? Why or why not?
Answer: No, 0.4 IoU is below the common threshold of 0.5, meaning predictions often poorly overlap true objects. The model likely misses or poorly locates objects and needs improvement.
Practice
Solution
Step 1: Understand IoU definition
IoU measures how much two areas overlap compared to their total combined area.Step 2: Identify what IoU compares
It compares two bounding boxes or regions to see how well they match.Final Answer:
The overlap between two bounding boxes -> Option AQuick Check:
IoU = Overlap / Union [OK]
- Confusing IoU with distance metrics
- Thinking IoU measures brightness or color
- Assuming IoU can be greater than 1
Solution
Step 1: Recall IoU formula
IoU is defined as the intersection area divided by the union area of two boxes.Step 2: Match formula to options
Area(A ∩ B) / Area(A ∪ B) correctly shows IoU = Area of intersection over area of union.Final Answer:
Area(A ∩ B) / Area(A ∪ B) -> Option BQuick Check:
IoU = Intersection / Union [OK]
- Swapping numerator and denominator
- Adding areas instead of dividing
- Subtracting areas instead of dividing
Solution
Step 1: Calculate union area
Union = Area(A) + Area(B) - Intersection = 20 + 30 - 10 = 40.Step 2: Calculate IoU
IoU = Intersection / Union = 10 / 40 = 0.25.Final Answer:
0.25 -> Option AQuick Check:
IoU = 10/40 = 0.25 [OK]
- Forgetting to subtract intersection in union
- Using sum of areas as union
- Mixing up intersection and union values
def iou(area_a, area_b, intersection):
union = area_a + area_b + intersection
return intersection / union
print(iou(15, 25, 5))
What is the error in this code?Solution
Step 1: Check union calculation
Union should be area_a + area_b - intersection, not plus intersection.Step 2: Identify impact on IoU
Adding intersection inflates union, making IoU smaller than correct value.Final Answer:
Union is calculated incorrectly by adding intersection instead of subtracting -> Option DQuick Check:
Union = A + B - Intersection [OK]
- Adding intersection instead of subtracting
- Swapping numerator and denominator
- Returning union instead of IoU
Solution
Step 1: Understand IoU threshold meaning
Threshold 0.5 means IoU must be at least 0.5 to count as correct detection.Step 2: Compare IoU values to threshold
Box1 IoU = 0.6 > 0.5 (correct), Box2 IoU = 0.4 < 0.5 (incorrect).Final Answer:
Only Box1 is correct because its IoU is above 0.5 -> Option CQuick Check:
IoU ≥ 0.5 means correct detection [OK]
- Ignoring threshold and accepting all IoUs
- Confusing higher IoU as incorrect
- Using wrong threshold value
Ready to prove it?
Pass the test and this pattern moves unknown
