Skip to content
tezvyn:

Intersection over Union (IoU): How Good is Your Bounding Box?

Source: ultralytics.comEasyHow cards are made

Intersection over Union (IoU): How Good is Your Bounding Box?

Intersection over Union (IoU) scores how well a predicted box matches the real one by dividing their overlap area by their total area. It's vital for object detection in self-driving cars and medical imaging.

Why it exists

In computer vision, knowing an object is a 'car' isn't enough; we need to know where it is. Simple classification accuracy doesn't measure spatial precision. Intersection over Union (IoU) was created to quantify how well a predicted bounding box aligns with the actual, human-labeled ground truth box.

The mental model

Think of IoU as a Venn diagram for two rectangles: a predicted box and a ground truth box. IoU is the ratio of their overlapping area (the intersection) to the total area they both cover (the union). The resulting score is always between 0 (no overlap) and 1 (a perfect, pixel-for-pixel match).

How it works

The formula is simple: Area of Intersection / Area of Union. This ratio is scale-invariant, meaning it assesses performance fairly whether the object is a massive building or a tiny insect. During evaluation, engineers set an IoU threshold, commonly 0.5. If a prediction's IoU score is above this threshold, it's a 'True Positive'; if not, it's a 'False Positive'. This decision is a prerequisite for calculating aggregate metrics like Mean Average Precision (mAP).

When to use it

IoU is critical in three main areas. First, for model evaluation: it's the standard for scoring object detection accuracy. Second, during model training: advanced loss functions like GIoU and CIoU use this principle to help the model learn to place boxes better. Third, during inference: a technique called Non-Maximum Suppression (NMS) uses IoU to find and remove duplicate, overlapping detections of the same object, cleaning up the final output.

When not to use it

IoU measures spatial overlap, not classification correctness. A high IoU score is meaningless if the box is labeled incorrectly (e.g., a box around a dog is labeled 'cat'). Always use IoU in conjunction with classification metrics. It is not applicable for tasks without spatial localization, like pure image classification.

One canonical example

A ground truth box for a person is at coordinates [100, 100, 200, 200]. A model predicts a slightly offset box at [110, 110, 210, 210]. The area where they overlap is 8100 pixels (90x90). The total area covered by both is 11900 pixels. The IoU is 8100 / 11900, or approximately 0.68. If the evaluation threshold was 0.5, this would count as a correct detection.

Interview question

In object detection, what does an Intersection over Union (IoU) score primarily evaluate?

  • a.The total count of distinct objects identified in an image.
  • b.The degree of spatial overlap between two bounding boxes.Correct
  • c.The accuracy of the object's assigned class label.
  • d.The computational efficiency of the detection model.
Why?

IoU is designed to quantify how well a predicted bounding box spatially aligns with a ground truth box. It does not measure the correctness of the classification label, which is a common misconception, as stated in the card: 'IoU measures spatial overlap, not classification correctness.'

Just read this? Test yourself on what you have been reading.

Read the original → ultralytics.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on computer vision — each one lists the topics its interview covers.

See open roles