Sub topic 4
The YOLO Idea: Detection in a Single Pass
Prerequisites
Assume you know basic Python, images as arrays of pixels, convolutional neural networks, and the idea of training a neural network with a loss function. This chapter focuses on how YOLO frames detection. It does not cover the details of box coordinates or output decoding.
From classification to detection
Image classification answers one question about the whole image: “Which class is present?” For example, a classifier might label an image as bus.
Object detection answers three questions for each object:
- What class is this object?
- Where is it?
- How confident is the model?
A detector therefore returns several predictions. Each prediction contains a box, a confidence score, and class scores. The box identifies a region of the image. The scores estimate whether an object is present and which class it belongs to.
Older detection systems often used multiple stages. A region proposal method first suggested possible object locations. A classifier then examined each suggested region. This approach could be accurate, but it required separate processing for many regions.
YOLO, which means “You Only Look Once,” treats detection as one prediction problem. The image passes through the neural network once. The network produces predictions for many locations and object sizes in one forward pass.
The single-stage prediction idea
Conceptually, the model divides the image into locations. At each location, it predicts candidate objects. A prediction can be represented as:
| Prediction part | Meaning |
|---|---|
| Box values | The object’s position and size |
| Objectness | How likely a real object is in the box |
| Class scores | Which class the object belongs to |
The original YOLO design used a grid over the image. The cell containing an object’s center was responsible for predicting that object. Modern YOLO models use several feature-map scales instead of one simple grid. Fine-resolution maps help with small objects, while coarse maps provide wider context for large objects.
The important idea remains the same: one shared network computes image features and predicts candidate boxes and classes together.
def detector_forward(image):
features = backbone(image)
features = neck(features)
predictions = detection_head(features)
return predictionsThis is a conceptual forward pass. The backbone extracts visual features, the neck combines information from different resolutions, and the head converts those features into detection predictions.
Why one pass matters
A single-stage design usually gives YOLO low latency. The same feature computation supports all candidate objects, so the cost does not grow as sharply as it would when separately classifying many proposed regions. This makes YOLO useful for video, robotics, and other applications that need frequent predictions.
Speed introduces trade-offs. A detector may miss very small, crowded, or unusual objects. The model must learn both localization and classification from the same features. Later processing also has to remove duplicate candidates. That processing is called non-maximum suppression.
The phrase “single pass” does not mean that the model returns one box. It means that one network evaluation produces many candidate boxes at once. A later filtering step selects the final detections.
Exercise
Exercise
Why can YOLO detect several objects even though the image enters the network only once?
Show answer
The network predicts candidates at many spatial locations and feature-map scales during the same forward pass. Each candidate can describe a different object.