Non-max suppression algorithm for bounding boxes
NMS is used in many object detection approaches that using bounding boxes in order to remove redundant bounding boxes. E.g. YOLO uses it.
For any object we have almost certainly generated multiple anchor boxes that cover it. Each anchor box has its own probability of containing an object.
For the final detection, we only want to keep one box.
- Pick a probability threshold
- Remove all boxes with probability < threshold
- While there are predicted boxes
- Pick the box with the largest probability
- Discard all boxes with IoU >= 0.5 of the max probability box
Note that of course you can have multiple object. This procedure only removes overlapping boxes, so if you have two boxes for two objects they'll stay.