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
- Select the bounding box with the largest score from
bboxesand put it into
- Computer the intersection over union between the highest score bounding box with other bounding boxes in
bboxes. Remove bounding boxes from
bboxesif IoU is 0.5 or higher. (The IoU threshold is a hyperparameter).
bboxesis not empty, we repeat the process from step 3.
- At last, we return
outputsthat 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.