← CS Lab AI & Machine Learning / IoU & NMS Open standalone ↗

IoU scores how much two boxes overlap as one number from 0 to 1; NMS uses that score to thin a pile of detections down to one box per object. Two tiny ideas that hold modern object detection together.

Where you meet it

What it does

IoU (Intersection over Union) turns "how well do these two rectangles line up?" into a single comparable number. NMS (Non-Maximum Suppression) is the cleanup that runs after detection: it walks the boxes from most to least confident and throws away any that overlap a box it already kept.

Dividing by the union is what makes IoU fair — a box that's too big is punished exactly as much as one that's too small.

How it works

IoU is the shared area divided by the combined area. The combined area — the union — is both boxes added together minus the overlap, because otherwise the shared part gets counted twice:

IoU   = intersection / union
union = area(A) + area(B) − intersection   # subtract the overlap once
# 0.0 = no touch   0.5 = the usual "match" bar   1.0 = identical

NMS then uses that number as a duplicate test: sort every box by confidence, keep the top one, delete every remaining box whose IoU with it is above a threshold, then repeat on what's left. A high threshold is stricter about calling two boxes "the same", so more survive; a low threshold prunes hard.

Watch out

  • The threshold is a trade-off, not a truth. Too high and duplicates slip through; too low and NMS deletes a real second object that genuinely overlaps the first — two people standing close.
  • NMS is greedy and runs per class. Once a confident box is kept it can suppress a correct neighbour — and a wrong-but-confident box suppresses the right one.
  • IoU is 0 the moment two boxes stop touching, no matter how near they were. It can't tell a near-miss from a wild miss, which makes it a poor training loss on its own.

Two boxes in, one number out — and almost every detector leans on it twice: once to judge, once to de-duplicate.

Go deeper

IoU misst als eine einzige Zahl von 0 bis 1, wie stark sich zwei Boxen überlappen; NMS nutzt diese Zahl, um einen Haufen Detektionen auf eine Box pro Objekt einzudampfen. Zwei winzige Ideen, die moderne Objekterkennung zusammenhalten.

Wo es vorkommt

Was es tut

IoU (Intersection over Union) macht aus „wie gut decken sich diese zwei Rechtecke?" eine einzige vergleichbare Zahl. NMS (Non-Maximum Suppression) ist das Aufräumen danach: Es geht die Boxen von der sichersten zur unsichersten durch und wirft jede weg, die zu stark mit einer schon behaltenen überlappt.

Das Teilen durch die Vereinigung macht IoU fair — eine zu große Box wird genauso bestraft wie eine zu kleine.

Wie es funktioniert

IoU ist die gemeinsame Fläche geteilt durch die Gesamtfläche. Die Gesamtfläche — die Vereinigung — sind beide Boxen zusammen minus die Überlappung, sonst zählt der geteilte Teil doppelt:

IoU          = Schnittfläche / Vereinigung
Vereinigung  = Fläche(A) + Fläche(B) − Schnittfläche   # Überlappung einmal abziehen
# 0.0 = kein Kontakt   0.5 = übliche „Treffer"-Schwelle   1.0 = identisch

NMS benutzt diese Zahl dann als Duplikat-Test: alle Boxen nach Konfidenz sortieren, die oberste behalten, jede übrige Box mit IoU über einer Schwelle löschen, dann auf dem Rest wiederholen. Eine hohe Schwelle ist strenger damit, zwei Boxen „gleich" zu nennen, also überleben mehr; eine niedrige räumt hart auf.

Worauf achten

  • Die Schwelle ist ein Kompromiss, keine Wahrheit. Zu hoch, und Duplikate rutschen durch; zu niedrig, und NMS löscht ein echtes zweites Objekt, das sich legitim überlappt — zwei Menschen dicht beieinander.
  • NMS ist gierig und läuft pro Klasse. Ist eine sichere Box erst behalten, kann sie einen korrekten Nachbarn unterdrücken — und eine falsche, aber sichere Box unterdrückt die richtige.
  • IoU ist 0, sobald zwei Boxen sich nicht mehr berühren — egal wie knapp. Es unterscheidet Beinahe-Treffer nicht vom totalen Fehlschlag und taugt allein schlecht als Trainings-Loss.

Zwei Boxen rein, eine Zahl raus — und fast jeder Detektor stützt sich zweimal darauf: einmal zum Bewerten, einmal zum Entdoppeln.

Mehr dazu

Next up
AI & Machine LearningYOLO Grid AI & Machine LearningViola-Jones Detector All concepts →