Is Sampling Heuristics Necessary in Training Deep Object Detectors

Joya Chen, Dong Liu, Tong Xu, Shiwei Wu, Shilong Zhang, Bin Luo, Xuezheng Peng, Enhong Chen

Abstract

In training deep object detectors, the problem of foreground-background imbalance has been addressed by several heuristic methods, such as online hard example mining (OHEM), Focal Loss, and gradient harmonizing mechanism (GHM). These methods either re-sample the training examples (i.e. hard sampling), or re-weight them discriminatively (i.e. soft sampling). In this paper, we challenge the necessity of such hard/soft sampling heuristics in training deep object detectors. First, without hard/soft sampling, we reveal that the scale and the stability of the classification loss greatly influence the final accuracy. Thus, we propose a guided loss scaling technique to control the classification loss during training, without using any hyper-parameter. We also propose to optimally initialize the model to ensure the stability of the classification loss. Moreover, we propose an adaptive thresholding technique to refine predictions during inference. These three ingredients constitute our Sampling-Free mechanism, which is fully data diagnostic and avoids the laborious hyper-parameter search for hard/soft sampling. We verify the effectiveness of our Sampling-Free mechanism in training one-stage, two-stage, multi-stage, and anchor-free object detectors, where our method always achieves higher accuracy on COCO and PASCAL VOC datasets. We also use the Sampling-Free mechanism for instance segmentation to demonstrate its generalization ability.

Introduction

Object detection involves evaluating tens of thousands of candidate locations (anchors or points), yet only a tiny fraction typically contain objects. This creates an extreme foreground-background (fg-bg) imbalance, often reaching ratios of 1:1000. Standard training using vanilla Cross-Entropy loss often fails because the cumulative gradient from the massive volume of background samples overwhelms the learning signal from the few foreground objects.

To mitigate this, traditional detectors rely on heuristic sampling:

  • Hard Sampling: Selecting a small, balanced subset of samples (e.g., OHEM).
  • Soft Sampling: Re-weighting samples so "easy" background examples contribute less to the gradient (e.g., Focal Loss).

While effective, these heuristics require extensive hyperparameter tuning and can create a mismatch between training and inference distributions. This research investigates whether accurate detectors can be trained using standard loss functions without these complex sampling tricks.

The Sampling-Free Mechanism

The proposed Sampling-Free mechanism allows models to train on all samples equally by addressing the root cause of failure: unreasonable classification gradient magnitude.

The Sampling-Free approach maintains all training samples without heuristic filtering, ensuring consistency between training and inference.

The mechanism consists of three core components:

  1. Optimal Bias Initialization: Instead of random initialization, the final layer is initialized based on the specific foreground-to-background ratio of the dataset. This ensures the initial loss is minimized, providing stability from the very first iteration.
  2. Guided Loss Scaling: Since localization loss is naturally stable (applying only to foreground samples), it is used as a "guide" to dynamically scale the classification loss. This prevents the classification task from drowning out the localization task without requiring manual hyperparameter search.
  3. Adaptive Thresholding: Predictions are refined during inference using an adaptive thresholding technique to ensure high-quality detections across different scenarios.

Experimental Results

The Sampling-Free mechanism was evaluated on MS COCO and PASCAL VOC across various detector architectures, consistently outperforming traditional heuristics:

  • One-Stage (RetinaNet): Achieved 37.0 AP on COCO, surpassing the Focal Loss baseline (36.4 AP).
  • Two-Stage (Faster R-CNN): Reached 38.4 AP, a significant improvement over the standard biased sampling baseline of 36.8 AP.
  • Anchor-Free (FCOS): Improved accuracy by 0.5 AP over the Focal Loss version.
  • Instance Segmentation: Applied to Mask R-CNN, the method improved both box and mask AP, demonstrating strong generalization.

Beyond accuracy, the method is more efficient; in Faster R-CNN, it reduced memory costs by eliminating the complex operations required for biased sampling.

Conclusion

This work demonstrates that complex sampling heuristics are not a fundamental requirement for training deep object detectors. By focusing on gradient stability and scale through optimal initialization and guided loss scaling, models can achieve state-of-the-art performance using standard distributions. This "data diagnostic" approach simplifies the training pipeline and maintains statistical consistency between training and inference.

Summary updated

Abstract

In training deep object detectors, the problem of foreground-background imbalance has been addressed by several heuristic methods, such as online hard example mining (OHEM), Focal Loss, and gradient harmonizing mechanism (GHM). These methods either re-sample the training examples (i.e. hard sampling), or re-weight them discriminatively (i.e. soft sampling). In this paper, we challenge the necessity of such hard/soft sampling heuristics in training deep object detectors. First, without hard/soft sampling, we reveal that the scale and the stability of the classification loss greatly influence the final accuracy. Thus, we propose a guided loss scaling technique to control the classification loss during training, without using any hyper-parameter. We also propose to optimally initialize the model to ensure the stability of the classification loss. Moreover, we propose an adaptive thresholding technique to refine predictions during inference. These three ingredients constitute our Sampling-Free mechanism, which is fully data diagnostic and avoids the laborious hyper-parameter search for hard/soft sampling. We verify the effectiveness of our Sampling-Free mechanism in training one-stage, two-stage, multi-stage, and anchor-free object detectors, where our method always achieves higher accuracy on COCO and PASCAL VOC datasets. We also use the Sampling-Free mechanism for instance segmentation to demonstrate its generalization ability. Code is released at: this https URL
BibTeX
@article{chen2021is,
  author = {Joya Chen and Dong Liu and Tong Xu and Shiwei Wu and Shilong Zhang and Bin Luo and Xuezheng Peng and Enhong Chen},
  title = {{Is Sampling Heuristics Necessary in Training Deep Object Detectors}},
  journal = {IEEE Trans. Image Process.},
  year = {2021},
  doi = {10.1109/tip.2021.3106802},
}
Figure