I found this to be a good resource for better understanding NMS
In a nutshell, here’s the NMS algorithm for one class
- Instantiate an empty list, call it
outputs = []
- Sort all bounding boxes by descending score and call the list
bboxes
. - Select the bounding box with the largest score from
bboxes
and put it intooutputs
. - Computer the intersection over union between the highest score bounding box with other bounding boxes in
bboxes
. Remove bounding boxes frombboxes
if IoU is 0.5 or higher. (The IoU threshold is a hyperparameter). - If
bboxes
is not empty, we repeat the process from step 3. - At last, we return
outputs
that contains the non-overlapping bounding boxes (as per the IoU threshold).
When there are multiple objects to be detected then you perform NMS independently for each class, ranking bounding boxes by score within one class.