Object detectors such as OWLv2 return many overlapping boxes for the same object. Intersection over Union measures how much two boxes overlap, and Non-Maximum Suppression uses it to keep one box per object.
Intersection Over Union
For boxes given as corners :
- intersection width , and the same for height
- IoU is 0 for boxes that do not touch and 1 for identical boxes
- it also scores detections against ground truth, where IoU of at least 0.5 often counts as correct
Non-Maximum Suppression
Steps:
- drop boxes below a score threshold (for example 0.3)
- sort the rest by score, highest first
- keep the top box, then remove every remaining box whose IoU with it is at least a threshold (for example 0.5)
- repeat with the next highest remaining box
Choices:
- class-aware NMS only lets boxes of the same label suppress each other
- the IoU threshold trades duplicates (too high) against losing objects that really overlap (too low)
- soft-NMS lowers the scores of overlapping boxes instead of deleting them, which helps in crowded scenes
Top-1 Per Query
- NMS cannot reduce detections to one per label, because boxes on two different objects do not overlap
- when a scene is known to hold at most one of each object, keeping only the best box per label does that job
- turn it off as soon as a scene can hold two objects with the same label
Keep Filtering Separate From The Model
- return every raw box from the detector and filter afterwards
- the filter code can then be unit tested without the model, and the number of boxes after each step can be logged