A detector sees the same car many times

Modern detectors don't output one box per object. They make thousands of predictions across the image, and several of them land on the same car, each slightly shifted, each with its own score. Drawn as they are, you'd get a pile of overlapping rectangles and a count that's far too high.

Non-maximum suppression, NMS, is the clean-up step that turns that pile into one box per object. It runs after the model on every frame, and its one setting has a big effect on how the system counts.

IoU: how much two boxes overlap

To decide whether two boxes are the same object, NMS measures their overlap as intersection over union: the area they share divided by the area they cover together. Two identical boxes score 1.0, two boxes that don't touch score 0.

In the figure, the gauge shows the real numbers. One box shares 52,920 square pixels with the best box out of 91,072 covered together, an IoU of 0.581. Above the 0.5 threshold, so it's treated as a duplicate and dropped. Another only reaches 0.351 and stays.

The threshold decides crowded scenes

With the threshold at 0.5, the six boxes in the figure become two. Lower it to 0.3 and only one survives: NMS is aggressive and merges anything that overlaps a little. Raise it to 0.7 and four survive: NMS is cautious and keeps boxes that are probably duplicates.

That matters most where objects really do overlap. People in a queue, parcels on a busy belt, cars in a car park. A low threshold merges two real people into one; a high one counts the same person twice. The right value depends on how crowded your scene really is.

What I check in production

  • Tune the IoU threshold together with the confidence threshold, on footage from the real site.
  • Look specifically at crowded moments, where most counting errors come from.
  • Use class-aware NMS when different object types can overlap, so a person isn't suppressed by a forklift.
  • Measure NMS time too. With thousands of candidates on a small edge device, it can cost real milliseconds.
  • Check the tracker downstream: it can smooth over a duplicate box that NMS let through.