MetaAnchor: Learning to Detect Objects with Customized Anchors

Tong Yang, Xiangyu Zhang, Zeming Li, Wenqiang Zhang, Jian Sun

TL;DR

MetaAnchor is a novel framework that replaces fixed, predefined anchor boxes in object detectors with a dynamic "anchor function generator." By using a weight-prediction mechanism to generate detection parameters on-the-fly from arbitrary box priors, it makes detectors more robust to anchor settings, more efficient with parameters, and significantly better at generalizing across different datasets.

The Problem with Fixed Anchors

Most modern object detectors (like RetinaNet, SSD, or Faster R-CNN) rely heavily on anchors. Think of anchors as "hints"—a set of predefined boxes of various sizes and aspect ratios tiled across the image. The network’s job is to look at these hints, decide if an object is inside them, and tweak the box coordinates to fit the object perfectly.

However, this standard "enumeration" strategy has three major flaws:

  1. Manual Tuning: Anchors must be carefully designed (via hand-crafting or clustering) to match the dataset. If your anchors don't match the objects (e.g., using square anchors for tall pedestrians), performance drops significantly.
  2. Parameter Bloat: Adding more anchors to cover more shapes usually requires adding more independent parameters to the model, which can lead to overfitting.
  3. Distribution Shift: A model trained on one dataset (e.g., COCO) might fail on another (e.g., a specialized face dataset) because the "optimal" anchor shapes differ, requiring the whole model to be retrained.

The MetaAnchor Method

To solve these issues, the authors introduce the MetaAnchor module. Instead of learning a fixed set of weights for a fixed set of anchors, they learn an Anchor Function Generator ($\mathcal{G}$).

Here is how the mechanism works:

  • The Input: The generator receives a "prior" ($b_i$), which is simply a vector describing a box's height and width.
  • The Mechanism: The generator acts as a small sub-network (a hypernetwork) that takes this box description and predicts the weights ($\theta_{cls}$ and $\theta_{reg}$) for the classification and regression layers of the detector.
  • The Formula: The authors use a residual form: $\theta = \theta^* + \mathcal{R}(b_i; w)$. Here, $\theta^*$ represents shared base parameters, and $\mathcal{R}$ is a small two-layer network that tweaks those parameters based on the specific box shape.
  • Dynamic Inference: Because the weights are generated directly from the box description, you can theoretically feed any box shape into the model at test time. The model will generate the appropriate detection function for that shape without needing retraining.

Key Insights

  • Weight Sharing on Steroids: In traditional models, a $3 \times 3$ anchor and a $5 \times 5$ anchor have completely different weights. In MetaAnchor, they share the same generator. This means every training sample, regardless of its size, helps train the entire anchor mechanism, leading to much better robustness.
  • Customization at Inference: Since the model can handle arbitrary priors, the authors implemented a "greedy search" at inference time. They can test various anchor configurations on a small validation set and pick the best ones for the specific task at hand without touching the model's underlying weights.
  • Bridging the Gap: MetaAnchor is particularly good at "filling in the blanks." If a certain object size is rare in the training data, the generator can still produce a competent detection function for it by interpolating from the sizes it has seen.

Key Results

The researchers evaluated MetaAnchor primarily using COCO and PASCAL VOC 2007.

  • Consistent Gains: When applied to RetinaNet on COCO, MetaAnchor consistently outperformed the baseline by 0.2% to 0.8% mmAP, with even larger gains observed in $AP_{50}$.
  • Robustness to "Drops": In a stress test where 1/6th of the bounding box distributions were manually "erased" from the training set, MetaAnchor's performance dropped significantly less than standard RetinaNet (e.g., 23.0 vs 20.8 AP).
  • Transferability: A MetaAnchor model trained on COCO and tested on VOC 2007 achieved 83.3% mAP, outperforming the standard RetinaNet baseline and demonstrating superior transfer ability.
  • Versatility: The authors also integrated MetaAnchor into YOLOv2, boosting its performance on COCO from 18.9 to 21.2 mmAP.

Limitations and Future Work

  • Two-Stage Detectors: While MetaAnchor improves the "proposal" stage of two-stage detectors (like Faster R-CNN), the authors noted it has less impact on the final results. This is because the second stage of these models is already designed to be somewhat anchor-agnostic.
  • Inference Overhead: While the generator is small, calculating weights on-the-fly or performing a "greedy search" for optimal anchors adds a layer of computational complexity compared to simple fixed-weight convolutions.
  • Future Directions: The authors suggest exploring more complex designs for the generator $\mathcal{G}$ and applying the "meta" approach to other parts of the detection pipeline beyond just anchors.

Summary updated

BibTeX
@inproceedings{yang2018metaanchor,
  author = {Tong Yang and Xiangyu Zhang and Zeming Li and Wenqiang Zhang and Jian Sun},
  title = {{MetaAnchor: Learning to Detect Objects with Customized Anchors}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2018},
}
Figure