YOLO (Object Detection)

YOLO — "You Only Look Once" — is a family of single-stage object detectors that predict bounding boxes and class labels for an entire image in one forward pass of a convolutional network. Introduced by Redmon et al. in 2015, it reframed detection as dense regression rather than "propose regions, then classify each", which made real-time detection practical. The lineage has since passed through many authors and organizations (YOLOv2/v3, v4, Ultralytics YOLOv5/v8/v11, YOLOX, YOLOv7, YOLOv9, YOLOv10 and others), all sharing the same backbone-neck-head structure.


1. One-Stage vs Two-Stage Detection

Two-Stage (Faster R-CNN) vs One-Stage (YOLO) TWO-STAGE Image Backbonefeatures Region ProposalsRPN, ~1000 boxes RoI Classify+ box refine Boxes ONE-STAGE (YOLO) Image Backbone + Neck + Dense Headevery cell predicts box, objectness, class Threshold + NMSpost-processing Boxes

Two-stage detectors (R-CNN, Fast/Faster R-CNN, Mask R-CNN) first generate candidate regions and then classify and refine each one. They are accurate, especially for small objects, but the per-region stage costs time. One-stage detectors (YOLO, SSD, RetinaNet, FCOS) predict everything densely from feature maps in a single network evaluation, trading a little localization precision for much higher throughput. Later YOLO versions closed most of the accuracy gap, which is why YOLO-style models dominate real-time and edge deployments.

2. The Grid Formulation

S x S Grid: The Cell Containing the Center Is Responsible dog Each cell / anchor predicts a vector: [ tx, ty, tw, th, objectness, p(class 1) ... p(class K) ] bx = (sigmoid(tx) + cx) * stride center offset inside the cell bw = anchor_w * exp(tw) anchor-based (v2 to v7) or: distances to box edges (l, t, r, b) anchor-free (YOLOX, v8+) Output tensor per scale: S x S x A x (5 + K), with A anchors per cell Yellow cell holds the object center; green is the predicted box

The original YOLO divided the image into a 7x7 grid; the cell containing an object's center predicted its box coordinates, a confidence, and class probabilities. YOLOv2 added anchor boxes (prior shapes clustered from the training set) so each cell could predict several objects of different aspect ratios, with the network outputting offsets relative to the anchor. Modern versions (YOLOX, YOLOv8 and later) are typically anchor-free: each location directly regresses distances to the four box edges, which removes anchor tuning and simplifies the head.

3. Backbone, Neck and Head

Backbone - Neck - Multi-Scale Heads Backbone (CNN) C3: stride 8 C4: stride 16 C5: stride 32 Neck (FPN + PAN) top-down: upsample deep, semantic features bottom-up: push precise localization back down Head P3small objects Head P4medium objects Head P5large objects decoupled cls + box branches

The backbone (Darknet-53 in v3, CSPDarknet in v4/v5/v8, other CSP/ELAN-style CNNs later) extracts features at several strides. The neck fuses them: a Feature Pyramid Network passes high-level semantics down to high-resolution maps, and a Path Aggregation Network passes fine localization back up. The head runs at three scales; at a 640x640 input, stride 8, 16 and 32 give 80x80, 40x40 and 20x20 prediction grids, covering small, medium and large objects. Recent heads are decoupled: separate convolution branches for classification and box regression, which converges faster than one shared branch.

4. Loss Functions and Label Assignment

The training loss is a weighted sum of three parts:

Label assignment — deciding which predictions are positives for each ground-truth box — matters as much as the loss. Early versions used the single best anchor; YOLOX introduced SimOTA (dynamic assignment by cost), and YOLOv8 uses a task-aligned assigner that combines classification score and IoU. YOLOv10 trains with one-to-one matching in addition to one-to-many so the model can be deployed without NMS.

5. IoU and Non-Maximum Suppression

IoU and Non-Maximum Suppression A ∩ B IoU = |A ∩ B| / |A ∪ B| 0.92 kept, 0.81 and 0.77 removed 1. Drop boxes below conf threshold 2. Sort by score, take the top box 3. Remove same-class boxes with IoU > threshold (e.g. 0.45-0.7) 4. Repeat on what remains

Dense heads produce many overlapping predictions for the same object. Non-maximum suppression greedily keeps the highest-scoring box and removes others whose Intersection-over-Union with it exceeds a threshold. Its two knobs — confidence threshold and IoU threshold — directly trade recall against duplicate detections and should be tuned on validation data. NMS is sequential and data-dependent, which is awkward for some accelerators; that is the motivation for NMS-free designs like YOLOv10 and transformer-based DETR detectors.

6. Python Example

The Ultralytics package is the most common way to train and run YOLO models. Dataset configuration is a small YAML file listing image directories and class names; labels are one text file per image with class cx cy w h normalized to [0, 1].

from ultralytics import YOLO      # pip install ultralytics

# Inference with pretrained COCO weights
model = YOLO("yolov8n.pt")        # n/s/m/l/x = increasing size
results = model.predict("street.jpg", conf=0.25, iou=0.5, imgsz=640)
for r in results:
    for box in r.boxes:
        cls = r.names[int(box.cls)]
        x1, y1, x2, y2 = box.xyxy[0].tolist()
        print(f"{cls:12s} {float(box.conf):.2f}  ({x1:.0f},{y1:.0f})-({x2:.0f},{y2:.0f})")

# Fine-tune on a custom dataset (data.yaml: path, train, val, names)
model = YOLO("yolov8s.pt")
model.train(data="data.yaml", epochs=100, imgsz=640, batch=16, patience=20)
metrics = model.val()             # mAP50 and mAP50-95 on the val split
print(metrics.box.map50, metrics.box.map)

# Export for deployment
model.export(format="onnx")       # also: engine (TensorRT), openvino, coreml, tflite

Licensing differs across implementations (Ultralytics code and weights are AGPL-3.0 with a commercial option, while some other YOLO variants use permissive licenses), so check before shipping a product.

7. Evaluation: mAP

Detection quality is reported as mean Average Precision. For each class, predictions are sorted by confidence and matched to ground truth at a given IoU threshold; AP is the area under the resulting precision-recall curve, and mAP averages over classes. mAP@0.5 uses a lenient 0.5 IoU match; COCO-style mAP@0.5:0.95 averages over thresholds 0.50 to 0.95 in steps of 0.05 and rewards tight localization. Always report latency together with the hardware, batch size, input size and whether NMS time is included.

8. Trade-offs and Pitfalls