Anchor Boxes Concept
What you'll learn: How anchor boxes provide pre-defined reference shapes that help object detectors predict bounding boxes across different scales and aspect ratios.
The Problem: Objects Come in All Shapes and Sizes
When detecting objects in images, we face a challenge: objects vary dramatically in size (a car vs a person) and shape (a bus is wide, a bottle is tall). How do we teach a neural network to predict bounding boxes for such diverse objects?
What Are Anchor Boxes?
Anchor boxes (also called "priors" or "default boxes") are pre-defined bounding box templates placed at various locations across an image. Think of them as "starter shapes" that the network refines into precise predictions.
Instead of predicting a bounding box from scratch, the network asks: "Which anchor box is closest to my object, and how should I adjust it?"
The Analogy
Imagine you're a tailor with a set of pre-made clothing templates: small, medium, large, and in different cuts (slim, regular, wide). When a customer arrives, you:
- Pick the closest-fitting template
- Make small adjustments to perfect the fit
Anchor boxes work the same way—they're templates the detector adjusts rather than creating boxes from nothing.
How They Work
Anchor boxes are defined by:
- Multiple scales (e.g., 32×32, 64×64, 128×128 pixels) to handle different object sizes
- Multiple aspect ratios (e.g., 1:1, 1:2, 2:1) to handle different shapes
The network predicts offsets to adjust each anchor box's position and size, transforming the closest anchor into an accurate bounding box. This dramatically simplifies the learning problem compared to predicting raw coordinates.
Key Takeaway: Anchor boxes provide reference priors at different scales and aspect ratios, allowing object detectors to predict boxes as refinements of templates rather than absolute coordinates—making detection more efficient and accurate.