Intersection over Union
Calculate intersection over union, interpret overlap thresholds, and understand why correct class labels and matching rules also matter.
Intersection over Union explained visually
Calculate intersection over union, interpret overlap thresholds, and understand why correct class labels and matching rules also matter.
What you will learn
Locate objects, represent boxes, filter predictions, evaluate detections, and compare detector designs.
Define intersection and union
Two boxes surround the same bicycle. One was drawn by a human annotator. The other was predicted by a model. They look close, but how close is close enough?
A common way to compare them is intersection over union, usually called I O U.
The intersection is the area the two boxes share. The union is the total area covered by either box, counting the shared region only once. We divide the intersection area by the union area.
Work through the area calculation
Let’s work through an example. Our reference box has an area of one hundred square units. The predicted box also has an area of one hundred. Their overlap covers sixty square units.
If we simply add the two box areas, we get two hundred. But that counts the overlap twice. So we subtract sixty, leaving a union of one hundred and forty.
Sixty divided by one hundred and forty is about zero point four three. That is the intersection over union for these boxes.
Require correct classes and matching rules
For ordinary boxes with positive area, the score runs from zero to one. Zero means no overlapping area. One means the boxes match exactly.
Notice that this score measures geometry. It does not tell us whether the predicted class is correct. A perfectly placed box labeled dog is still the wrong detection if the object is a bicycle.
During evaluation, we can require the predicted class to match and the overlap score to meet a chosen threshold. A threshold of zero point five accepts less precise alignment than a threshold of zero point seven five.
Those thresholds are evaluation choices, not universal laws. We also need matching rules so that several predictions do not all receive credit for the same reference object.
Understand sensitivity for small objects
One more useful detail: moving a box by a few pixels can have a much bigger effect on a tiny object than on a large one.
Next, we’ll examine confidence scores, which answer a different question from box overlap.
Quick check: test your understanding
What is IoU when both areas are 100 and their overlap is 60?
60 / (100 + 100 − 60) = 60 / 140 ≈ 0.43.
Does IoU measure whether a class label is correct?
No. It measures geometric overlap.
Which matching threshold requires tighter alignment: 0.50 or 0.75?
0.75, using the same class and matching rules.
Accessible referenceLesson 65 transcript323 words · Matches the published narration and captionsOpen transcript
Two boxes surround the same bicycle. One was drawn by a human annotator. The other was predicted by a model. They look close, but how close is close enough?
A common way to compare them is intersection over union, usually called I O U.
The intersection is the area the two boxes share. The union is the total area covered by either box, counting the shared region only once. We divide the intersection area by the union area.
Let’s work through an example. Our reference box has an area of one hundred square units. The predicted box also has an area of one hundred. Their overlap covers sixty square units.
If we simply add the two box areas, we get two hundred. But that counts the overlap twice. So we subtract sixty, leaving a union of one hundred and forty.
Sixty divided by one hundred and forty is about zero point four three. That is the intersection over union for these boxes.
For ordinary boxes with positive area, the score runs from zero to one. Zero means no overlapping area. One means the boxes match exactly.
Notice that this score measures geometry. It does not tell us whether the predicted class is correct. A perfectly placed box labeled dog is still the wrong detection if the object is a bicycle.
During evaluation, we can require the predicted class to match and the overlap score to meet a chosen threshold. A threshold of zero point five accepts less precise alignment than a threshold of zero point seven five.
Those thresholds are evaluation choices, not universal laws. We also need matching rules so that several predictions do not all receive credit for the same reference object.
One more useful detail: moving a box by a few pixels can have a much bigger effect on a tiny object than on a large one.
Next, we’ll examine confidence scores, which answer a different question from box overlap.