Walk me through how modern object detection works
Written by the mlprep team · Updated
Walk me through how modern object detection works. How would you frame the space of approaches?
Object detection has two jobs: locate every object in an image (a bounding box regression problem) and classify each one. It's harder than classification because the number of objects is unknown and they can appear anywhere.
Two-stage detectors: the R-CNN family#
Two-stage detectors split the problem: first propose candidate regions, then classify them.
R-CNN used selective search to generate ~2000 region proposals, warped each to a fixed size, ran a CNN on each, and classified with SVM. Slow (47 seconds/image).
Fast R-CNN ran the CNN once on the full image to get a feature map, then used RoI pooling to extract fixed-size features for each proposal from the shared feature map. Much faster.
Faster R-CNN replaced selective search with a Region Proposal Network (RPN) — a small convolutional network that slides over the feature map and at each location predicts whether an anchor box contains an object and refines the box coordinates. Anchors are predefined boxes of different scales and aspect ratios centered at each grid location. The RPN shares the backbone with the detector, making the whole pipeline end-to-end trainable.
One-stage detectors: YOLO#
YOLO divides the image into an S×S grid. Each cell predicts B bounding boxes (each with x, y, w, h, confidence) and C class probabilities directly in a single forward pass. No region proposal step.
The tradeoff: faster but historically less accurate on small objects and crowded scenes, because each grid cell can only predict a fixed number of boxes. Modern YOLO versions (v7, v8, v9) close this gap significantly with feature pyramids, better anchor strategies, and anchor-free designs.
Feature Pyramid Networks#
Both families now use FPN — the backbone produces feature maps at multiple scales, and predictions happen at each scale. Small objects are detected at high-resolution early layers, large objects at low-resolution deep layers.
Anchor-free detectors#
Recent work (FCOS, CenterNet, DETR) drops anchor boxes entirely. DETR uses a transformer encoder-decoder: the encoder processes image features, the decoder uses learned object queries and cross-attention to directly predict a fixed set of boxes. No anchors, no NMS — elegant but slower to converge.
You mentioned NMS to deduplicate detections. Can you walk through exactly how non-maximum suppression works and where it breaks down?
After a detector produces hundreds or thousands of overlapping candidate boxes, NMS picks the best ones.
The algorithm#
- Sort all boxes by confidence score (highest first).
- Take the highest-confidence box — add it to the output.
- Compute IoU between this box and all remaining boxes.
- Suppress (remove) any remaining box with IoU above threshold τ (typically 0.5).
- Repeat with the next highest-confidence remaining box.
IoU is the intersection area divided by the union area — 0 for non-overlapping boxes, 1 for identical boxes.
Where it breaks down#
Overlapping objects of the same class: if two people are standing close together, their bounding boxes may overlap with IoU > 0.5. NMS will suppress the lower-confidence detection even though it's a real object. This is the classic failure mode.
Threshold sensitivity: high τ keeps more boxes (more false positives from duplicates). Low τ is more aggressive (misses close objects). There's no universally correct value.
Soft-NMS#
Instead of hard suppression, Soft-NMS decays the confidence score of overlapping boxes as a function of IoU:
s_i = s_i · e^(-IoU(M, b_i)² / σ)
Boxes that heavily overlap with the selected box have their scores reduced, not zeroed out. They can still make it through if they're confident enough, which helps recover the second person in an overlapping pair. It's a drop-in replacement for NMS with measurable gains on crowded scenes.
Class-agnostic NMS#
Standard NMS runs per-class — a person and a car can overlap without suppressing each other. Class-agnostic NMS suppresses across classes, which can be too aggressive when objects of different classes are co-located (e.g., a person holding a phone).
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
Object detection = bounding box regression + classification, done simultaneously. Two-stage detectors (Faster R-CNN) propose regions then classify; one-stage (YOLO) predict directly from a grid. Anchor boxes define the space of candidate shapes the model refines. NMS deduplicates predictions greedily by confidence + IoU; it fails when distinct objects overlap.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- How would you adapt an object detection pipeline to detect very small objects in high-resolution satellite imagery?
- What is the precision-recall tradeoff in detection and how does mAP summarize it?
- How does DETR's approach eliminate the need for anchor boxes and NMS, and what does it trade off?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
Explain transfer learning — when to freeze vs fine-tune, and common failure modes
Walk me through how CNNs work
Walk me through two-tower models for retrieval — architecture, tradeoffs, and limits
How does multi-task learning work for ranking — and what are the failure modes?