Back to Tutorials
Deep Learning
Intermediate

Object Detection: Boxes, Overlap and Cut-offs

Score a box by its overlap with the truth, then tune a detector’s confidence and non-maximum suppression thresholds and watch objects appear, vanish and double up.

10 minInteractive: drag, click and try things as you read


Image classification says what is in a picture. Object detection says what and where: a box around every person, dog and bicycle, each with a label and a confidence. It’s what lets a phone blur faces, a shop count customers and a car see pedestrians. A detector actually produces hundreds of overlapping guesses, and two settings decide which ones you see. Detection is a pile of guesses and two cut-offs, and the cut-offs trade missed objects against false alarms. Here you’ll score a box by hand, then tune those cut-offs and watch objects appear, vanish and double up.

What a detector outputs#

Each detection is three things: a class (“dog”), a box given by its corners in pixels, and a confidence between 0 and 1 for how sure the model is that the box holds that class.

YOLO, short for “You Only Look Once”, was introduced by Joseph Redmon and colleagues in 2016. Earlier detectors first proposed regions that might hold an object, then classified each one. YOLO instead runs the whole image through one network once: the image is turned into grids of features at a few sizes, and every grid position predicts boxes and class scores at the same time. That made it fast enough for live video. The best-known versions today come from the company Ultralytics; its newest, YOLO26, came out in January 2026. Every version, though, ends the same way: with far more candidate boxes than objects.

Is this box right?#

To score a detector you need a rule for when a predicted box counts as finding an object. The standard one is intersection over union (IoU): the area where the predicted and true boxes overlap, divided by the area covered by either. 1 is a perfect match, 0 is no overlap. A detection usually counts as correct when IoU is at least 0.5 and the class is right.

Predict first

A predicted box is exactly the right size but shifted sideways by a third of its width. What’s its IoU with the true box?

Try it
A made-up park scene. The true boxes are ours; IoU is computed live as you drag. Switch to the bird to see the same slip on a small object.

Slide the box 12 pixels to the right and the dog still scores 0.78. Do the same to the bird and it scores 0.45: a miss. The same pixel error costs a small object far more of its area, which is why small objects are the hardest part of detection and why detectors are compared on them separately. And a box that’s too big is punished as hard as one that’s off target: twice as wide and tall scores 0.25. IoU judges a box by how much of it is wrong, so small objects need pixel-perfect boxes.

The 0.5 cut-off comes from the PASCAL VOC benchmark. The COCO benchmark, which most papers report today, averages the score over ten cut-offs from 0.5 to 0.95, so a box that’s merely close earns less than one that’s tight. That number is written mAP50-95.

From hundreds of boxes to a handful#

Two steps turn a detector’s raw output into the boxes you see:

  1. The confidence cut. Throw away every box less sure than a threshold. Ultralytics uses 0.25 by default.
  2. Non-maximum suppression (NMS). Sort the rest by confidence. Keep the surest box, delete every box of the same class that overlaps it by more than a second threshold (0.7 by default), then repeat with the surest box left. The idea: heavily overlapping boxes are the same object found twice.

Predict first

Two people stand side by side, and their true boxes overlap with an IoU of 0.41. You set NMS to remove any box overlapping a surer one by more than 0.3. What happens?

Try it
The raw boxes are made up to behave like a detector’s output: a few tight, confident boxes and a spray of looser, less confident ones around each object, scattered guesses on the background, and one confident mistake. The confidence cut, NMS and the scoring are computed live.

With the defaults, the detector finds all six objects and makes one mistake: the tree trunk, taken for a person with confidence 0.43. Try to remove it by raising the confidence threshold and you lose the bird first (0.41), then the person behind the bench (0.48). No threshold gives you everything with no mistakes: that’s the trade between recall (how many real objects you find) and precision (how many of your boxes are real). The chart traces both as the threshold falls; the area under it is the average precision, 0.98 here.

Now turn NMS off. Each object is found five times, and 25 of the 31 boxes are wrong. Push NMS to 0.9 and looser duplicates survive; pull it down to 0.3 and the second person vanishes. Average precision falls to 0.50 with no NMS and 0.88 with strict NMS. There’s no perfect threshold: set it by what a miss costs compared with a false alarm. A system that warns a driver about pedestrians should accept false alarms; one that counts birds for a survey shouldn’t count a tree trunk.

On a real photo#

The same two settings behave the same way on real output. On the sample photo of a bus that Ultralytics uses in its documentation, YOLO26’s smallest model with the defaults finds the bus and four people. Raise the NMS threshold to 0.95 and three extra person boxes survive, duplicates of people already found. Lower the confidence threshold to 0.05 and it adds guesses like a “stop sign” at 0.13 and a “handbag” at 0.08.

To detect your own kinds of object, such as a part on a production line or a weed in a field, you label boxes on your own images (tools like Label Studio or Roboflow help) and fine-tune a pretrained model on them. Then check it the way the figures do: IoU against boxes you labelled by hand, and precision and recall at the threshold you plan to use.

In code#

Free and local, with pip install ultralytics:

from ultralytics import YOLO

model = YOLO("yolo26n.pt")  # downloads the smallest model the first time
results = model("https://ultralytics.com/images/bus.jpg", conf=0.25, iou=0.7, verbose=False)

for box in results[0].boxes:
    name = model.names[int(box.cls)]
    x1, y1, x2, y2 = box.xyxy[0].tolist()
    print(f"{name:7} {float(box.conf):.2f}  ({x1:.0f}, {y1:.0f}) to ({x2:.0f}, {y2:.0f})")
# bus     0.88  (0, 230) to (803, 751)
# person  0.87  (49, 398) to (240, 902)
# person  0.86  (223, 405) to (345, 861)
# person  0.85  (670, 394) to (810, 879)
# person  0.66  (0, 553) to (60, 871)

What to remember

  • A detector predicts many boxes, each with a class and a confidence; a confidence cut and non-maximum suppression decide which ones you see.
  • IoU (overlap ÷ area covered by either) judges each box; 0.5 is the usual cut-off, and small objects need very precise boxes to pass it.
  • Raising thresholds trades found objects for fewer false alarms; NMS that’s too strict deletes real objects standing close together.

Keep going

Sign in to save your place and keep a learning streak. Free, with Google.