Visual explainer
Object Detection with Anchors and YOLO
Decode grid-relative centers and anchor sizes into instance boxes, inspect overlap and class scores, then see why suppression can lose crowded objects.
Predict Each Instance
Object detection predicts where individual objects are and which category each belongs to. The scene has separate person and car boxes; a single image-level label would not identify their locations. A bounding rectangle includes background and does not trace an exact silhouette.
The original YOLO paper predicts boxes and class evidence in one network pass. Original YOLO has no anchor priors. The anchor equations below follow YOLOv2; they are not universal equations for every later model called YOLO. CNN image mechanics explains the feature maps behind the predictions.
Start From A Grid Cell
This teaching image is 160×160 pixels, divided into four rows and columns of 40-pixel cells. With zero-based column and row indices, center (60,100) belongs to cell (1,2), whose top-left corner is (40,80). Image x increases rightward and y downward.
A cell provides an origin for prediction; it does not crop the network's receptive field to that cell. The diagram's 4×4 grid simplifies arithmetic and is not the original network's output shape. Object-center ownership and assignment details depend on the detector.
Offer Several Shape Priors
An anchor is a reference width and height from which a predicted box can be decoded. These 40×20 and 20×40 priors share a center but offer different aspect ratios. A solid outline identifies the wide prior; dashes identify the tall one. The drawing zooms to four display units per image pixel.
YOLOv2 uses dimension priors estimated from training boxes. Priors increase the available shape hypotheses but also multiply prediction slots and assignment work. They are not detected objects or final box coordinates.
Decode The Center
YOLOv2 uses bx=cx+sigmoid(tx) and by=cy+sigmoid(ty) in grid-cell units. With tx=ty=0, sigmoid gives 0.5. At cell (cx,cy)=(1,2), center coordinates are (1.5,2.5) cells, or (60,100) pixels after multiplying by 40.
The enlarged cell shows the halfway offset from its top-left corner; the bracket spans 20 pixels. Bounding the center offsets helps constrain prediction during training. It does not bound width and height to remain inside the cell.
Decode Width And Height
YOLOv2's box-generation equations use bw=pw exp(tw) and bh=ph exp(th). Express prior dimensions in pixels here: pw=40, ph=20. Outputs tw=ln(1.5) and th=ln(2) give bw=60, bh=40.
Both outlines keep decoded center (60,100). Dashes identify the prior and the solid outer box identifies the result, on the same scale. The box can extend across cell boundaries. Exponential decoding ensures positive size but can produce excessive dimensions for poorly trained offsets.
Compare With A Target
For this assignment illustration, keep the decoded 60×40 box and compare a centered 40×40 target. The smaller rectangle is entirely inside the larger. Intersection area is 40×40=1,600; union is 2,400+1,600−1,600=2,400, so intersection over union (IoU) is 2/3.
Hatching marks the shared area; rounded corners are drawing style, while the calculation uses ordinary rectangular boxes. IoU can help choose which prediction slot should learn a target. Assignment rules vary: choosing the best prior or predictor is different from declaring every IoU above one fixed threshold positive. Training uses assigned box targets and class/objectness losses; drawing priors alone does not train a detector.
Score A Class-specific Box
Take a confidence value 0.8 and conditional class evidence 0.75. Their product is 0.8×0.75=0.6. On one 0–1 length scale, the final bar retains three quarters of the confidence bar. Scoring and overlap answer different questions: class support versus geometric agreement.
In the original YOLO formulation, confidence combines object presence with predicted IoU; multiplying by the conditional class probability gives a class-specific detection score. YOLOv2's paper also describes its objectness target with IoU. Do not automatically read 0.6 as a calibrated probability of correctness, or transfer this exact scoring rule to another implementation.
Preserve Small-object Evidence
The two crops and outlined object have identical image sizes. A 16-pixel object spans half a stride-32 cell width but one stride-16 cell width. The finer grid supplies more spatial prediction locations at additional computation and memory cost.
This is a general scale comparison. YOLOv2's passthrough brings finer features into its coarser prediction map; it is not the same as attaching separate output heads at both pictured resolutions. Broader multi-scale detectors may predict at several resolutions. No finer grid can restore image detail lost before capture.
Suppress Duplicate Boxes
Now use two same-class 40×40 candidates separated horizontally by 10 pixels. Their intersection is 30×40=1,200; union is 1,600+1,600−1,200=2,000, so IoU is 0.6. With scores A=0.9, B=0.8 and a hard NMS threshold of 0.5, keep A and suppress B because 0.6>0.5.
The dashed outline on the right is a rejected candidate retained only to explain the decision. This greedy step repeats over remaining candidates. The NMS visual examines the selection loop; class-aware and class-agnostic policies differ.
Where It Breaks
Keep exactly the previous boxes, scores and threshold, but let them describe two distinct nearby people. The same overlap rule still removes B. Both people remain in the physical scene; the amber dashed box marks the lost detection. Geometry alone cannot tell this case from two duplicate predictions.
Raising the NMS threshold can preserve crowded instances while retaining more duplicates. Better localization, crowd-aware postprocessing or a different detector design may be needed; no one threshold settles both cases. Coarse feature maps, missing small-object detail and unsuitable training distributions add further limits. Anchors are one parameterization choice, not a requirement for all object detectors.
The Quick Version
- Detection predicts categories and boxes for individual instances.
- Grid cells supply local prediction origins.
- Anchors provide reference shapes, not finished detections.
- YOLOv2 bounds center offsets with a sigmoid.
- Exponential offsets scale prior width and height.
- IoU compares geometric overlap with a target.
- Confidence and class evidence can form class-specific scores.
- Finer grids retain more small-object prediction locations.
- Greedy NMS suppresses overlapping lower-scoring candidates.
- Hard NMS can discard real instances in crowds.