Skip to main content
Object Detection

Object Detection

The Detection Problem

Image classification answers “what is in this image?” Object detection answers the much harder question: “what objects are in this image, and where exactly is each one?” This combines two sub-problems into one: Object detection = classification + localization For each object in an image, we need:
  • What: Class label (car, person, dog…)
  • Where: Bounding box (x,y,w,h)(x, y, w, h) specifying the tight rectangle around the object
The difficulty: the number of objects is variable (one image might have 3 cars, another might have 50 people), the objects can be any size and at any location, and they can overlap. This is fundamentally harder than classification because the model must make a variable number of structured predictions, not just pick one label.
When choosing a detection framework, the single most important question is: what is your latency budget? If you need real-time (under 30ms), start with YOLO or a single-stage anchor-free method. If accuracy matters more than speed (e.g., medical imaging), Faster R-CNN or DETR with a strong backbone is worth the extra latency. For a production-ready starting point, the torchvision or ultralytics YOLO libraries get you to a working system in under 50 lines of code.

Detection Paradigms

Two-Stage Detectors

The two-stage approach mirrors how humans scan a scene: first, quickly identify regions that might contain objects (“there is something interesting in the top-left corner”), then look closely at each candidate to determine what it is and refine its location. This “coarse then fine” strategy is slower but typically more accurate than single-stage methods. Generate proposals (stage 1) then classify and refine (stage 2):

YOLO: Single-Stage Detection

YOLO took a radically different approach from the two-stage pipeline: forget proposals entirely, and predict everything in one shot. This is like glancing at a scene and instantly knowing what is where, rather than carefully scanning each region. The result: dramatically faster inference at a modest accuracy cost.

YOLOv1 Core Concepts

YOLOv3 Architecture


Anchor-Free Detection

Anchor boxes are powerful but come with baggage: you need to manually design anchor sizes and ratios, you generate thousands of anchors per image (most are negative), and you need complex matching logic to assign ground truth boxes to anchors. Anchor-free methods cut through all of this by predicting objects directly from feature map locations.
A common pitfall when switching from anchor-based to anchor-free detectors: the evaluation metrics (mAP) can look similar on COCO, but the failure modes are different. Anchor-free methods tend to struggle more with overlapping objects of very different sizes at the same location (e.g., a person holding a phone), while anchor-based methods struggle more with objects whose aspect ratios do not match any predefined anchor. Examine your failure cases qualitatively, not just the headline mAP number.

FCOS (Fully Convolutional One-Stage)


DETR: Detection Transformer

DETR (2020) was a paradigm shift: it reframes detection as a set prediction problem. Instead of generating thousands of proposals and filtering with NMS (non-maximum suppression), DETR uses a fixed set of learned “object queries” and a transformer to directly output the final set of detections. No anchors, no NMS, no hand-crafted components. The training uses the Hungarian algorithm for optimal matching between predictions and ground truth, treating detection like a bipartite matching problem.

Comparison


Exercises

Implement GIoU, DIoU, and CIoU losses:
Implement multi-scale training for YOLO:
  • Randomly resize input during training
  • Adjust anchor scales accordingly
  • Handle variable batch sizes
Implement Soft-NMS for better overlapping object handling:

What’s Next?

Semantic Segmentation

Per-pixel classification with U-Net, DeepLab

Hyperparameter Tuning

Systematic optimization of training configs