# C4 W3 Intersection over union function

Hey guys! In intersection over union function, how do we get our ground truth bounding box with which our output from algorithm is compared?

Jaccard Index, or Intersection-Over-Union (IOU), is a technique for comparing any two sets. Sometimes it is used in object detection as a measure of prediction accuracy. For that, you do need both predicted and ground truth bounding boxes for a given object. However, as is the case in the autonomous driving exercise, you can also use it to compare two predicted bounding boxes, in which case you donâ€™t use or need ground truth. Why compare two predicted bounding boxes? Duplicate pruning

Note: this course uses the set notation

J(A,B) = \frac {(A \cap B)}{(A \cup B)}

but you also see it written as

IoU = \frac{TP}{TP + FP + FN}

where TP, FP, and FN represent quadrants of the truth or confusion matrix. See for example tf.keras.metrics.IoU Â |Â  TensorFlow v2.12.0

2 Likes

Hey @Diwakar_B,
To add to Nomenâ€™s reply, in some datasets, the true bounding boxes are added to the images manually, thus creating supervised datasets, which we later use to train our Object Localization models. I hope this helps.

Cheers,
Elemento

1 Like

I donâ€™t disagree with this assertion.

However, IOU functions in general do not know whether the two boxes they are comparing are two predicted boxes or one predicted box plus one ground truth box. In this class, specifically, the application of IOU is in the context of non-max-suppression, which is comparing two predicted bounding boxes; ground truth ground boxes play no role.

This class uses a pre-trained YOLO model. Ground truth bounding boxes would have been required during that model training. However, to the best of my knowledge, they have never been included in the materials for this class.

Hey @ai_curious,
Thanks for pointing out the discrepancy. I didnâ€™t write my reply in the context of IoU. I wrote my reply in the context of â€śtrue bounding boxesâ€ť, as in how the true bounding boxes for the different datasets are figured out. I assumed that @Diwakar_B was referring to this context only; and he mentioned IoU just because we use that for comparing the true bounding boxes with the predicted ones in the lecture videos.

Cheers,
Elemento