← Master Index
Vol. 07 Module 7.3 Lecture

YOLO

Popular Vision Models

How This Lesson Fits the Module

So far the models classify a whole image. Real applications need to know what is present and where—the object detection task from Module 7.2. Early detectors ran a classifier over thousands of region proposals (slow). YOLO (“You Only Look Once,” Redmon et al., 2016) reframed detection as a single regression over a grid—fast enough for real-time video.

R-CNN family — propose regions, then classify each (accurate, slow) YOLO (2016) — one network predicts all boxes + classes at once (real-time) YOLOv5–v8+ — anchor-free heads, modern backbones, easy training

Learning Objectives

By the end of this lesson, students should be able to:

  • Explain YOLO’s single-shot, grid-based detection formulation.
  • Describe bounding-box regression, objectness, and class prediction per cell.
  • Explain the role of non-maximum suppression (NMS) and IoU.
  • Contrast one-stage (YOLO) vs two-stage (R-CNN) detectors.
  • Run inference with a modern YOLO via the ultralytics package.
  • Interpret detection metrics like mAP.
Definition — YOLO (One-Stage Detector)

YOLO divides the input image into an S×S grid. Each cell predicts a fixed number of bounding boxes (x, y, w, h), an objectness score (probability a box contains an object), and class probabilities—all in a single forward pass. This “look once” design makes it a one-stage detector, trading a little accuracy for large speed gains.

How Single-Shot Detection Works

A CNN backbone (often a ResNet-style or custom CSPDarknet network) produces a feature grid. A detection head outputs, per cell, box coordinates + objectness + class scores. Because everything is one pass, YOLO reaches 30–150+ FPS. Overlapping duplicate boxes are then removed with non-maximum suppression using Intersection-over-Union (IoU).

AspectTwo-stage (Faster R-CNN)One-stage (YOLO)
Region proposalsSeparate proposal networkNone—dense grid
SpeedSlower (~5–15 FPS)Real-time (30–150+ FPS)
AccuracyOften higher on small objectsVery competitive, improving
Best useOffline, high-precisionVideo, robotics, edge, live

Running YOLO in PyTorch (Ultralytics)

Modern YOLO models ship in the ultralytics package, built on PyTorch. Inference and training are a few lines.

# pip install ultralytics from ultralytics import YOLO # Load a pretrained model (n=nano, s=small, m, l, x) model = YOLO("yolov8n.pt") # Inference on an image -> boxes, classes, confidences results = model("street.jpg") for r in results: for box in r.boxes: cls = model.names[int(box.cls)] conf = float(box.conf) xyxy = box.xyxy[0].tolist() # [x1, y1, x2, y2] print(f"{cls}: {conf:.2f} at {xyxy}") # Fine-tune on a custom dataset (YOLO-format labels) model.train(data="my_data.yaml", epochs=50, imgsz=640)
Module 7.2 Tie-In YOLO is the workhorse implementation of the object detection task. Its backbone stacks the same convolutions and pooling you learned in 7.1.
Common Misconception: “YOLO looks at each object individually.”

Reality: YOLO looks at the whole image once. It predicts every box in parallel from a single feature grid—that global context is why it makes fewer background false positives than sliding-window detectors, and why it is fast.

Critical Mistake — Forgetting NMS / Wrong Confidence Threshold

Raw YOLO output contains many overlapping boxes for the same object. Without non-maximum suppression you get duplicate detections; with too high a confidence threshold you miss real objects. Tune conf and iou thresholds per application rather than leaving defaults blindly.

Knowledge Check

  1. Short Answer: What does YOLO stand for? Answer: You Only Look Once.
  2. True/False: YOLO is a two-stage detector. Answer: False—it is one-stage.
  3. Multiple Choice: Each grid cell predicts: (a) only a class, (b) boxes + objectness + class, (c) only pixels, (d) a caption. Answer: (b).
  4. Short Answer: What technique removes duplicate overlapping boxes? Answer: Non-maximum suppression (NMS).
  5. True/False: YOLO can run in real time on video. Answer: True.
  6. Multiple Choice: IoU measures: (a) learning rate, (b) box overlap, (c) channel count, (d) FLOPs. Answer: (b).
  7. Short Answer: Name one advantage of one-stage over two-stage detectors. Answer: Much faster / real-time inference.
  8. True/False: Modern YOLO models are distributed via the ultralytics PyTorch package. Answer: True.
  9. Multiple Choice: The standard detection accuracy metric is: (a) BLEU, (b) mAP, (c) perplexity, (d) F0.5. Answer: (b).
  10. Short Answer: Which task from Module 7.2 does YOLO implement? Answer: Object detection.

Key Takeaways

  • YOLO reframes detection as one regression over a grid—a single forward pass.
  • Each cell predicts boxes, objectness, and class probabilities.
  • NMS with IoU cleans up overlapping predictions.
  • One-stage design trades slight accuracy for real-time speed.
  • Next: Mask R-CNN adds pixel-level masks to detection.
Trainer’s Guide

Demo: Run yolov8n on a webcam feed live in class—students immediately grasp “real-time” detection.

Exercise: Have students sweep the confidence and IoU thresholds on one image and observe precision/recall trade-offs directly.

Progress We can now find objects in real time. Next we go a level finer—from boxes to per-pixel masks. Continue to Mask R-CNN.