# Training Region-based Object Detectors with Online Hard Example Mining

Online hard example mining trains region-based detectors on their hardest candidates

Abhinav Shrivastava, Abhinav Gupta, Ross Girshick · arXiv · 2016-4-12

- **Problem** Background regions far outnumber objects when training region-based detectors. The classic bootstrapping loop does not fit end-to-end SGD training of Fast R-CNN.
- **Method** OHEM scores each candidate region with the current model on a shared feature map. It removes near-duplicates with NMS at IoU 0.7 and backpropagates only the highest-loss regions.
- **Results** On VOC 2007, OHEM raised VGG16 Fast R-CNN from 67.2% to 69.9% mAP with the paper's training schedule.

## Why hard examples matter for detector training

Turning object detection into classification of candidate regions leaves the training data dominated by background regions. The imbalance is extreme for sliding-window detectors such as DPM, where background examples can outnumber objects 100,000 to one, and object-proposal detectors still face a ratio of about 70:1. Bootstrapping, also called hard negative mining, handles this by growing the background set with windows that the current detector wrongly fires on.

The idea goes back to Sung and Poggio's face detection work in the mid-1990s, and later appeared with SVMs for pedestrian and object detection and with shallow networks and boosted trees.

Fast R-CNN and its descendants drop SVMs and train end to end with SGD, so the classic loop of freezing a model, mining examples and retraining does not fit. What the setting needs is hard example selection that happens within the stream of SGD updates.

## How the baseline Fast R-CNN samples RoIs

Fast R-CNN takes an image and its object proposals, runs a convolutional network once per image, and then applies RoI pooling and fully connected layers to each proposal. The loss for each RoI combines a classification log loss with a localization loss. Mini-batches are built hierarchically: a few images are drawn and a fixed number of RoIs is taken from each, so the convolutional computation is shared among them.

The baseline uses N = 2 images and B = 128 RoIs per mini-batch, so each image contributes B/N RoIs. A candidate is foreground when its IoU with a ground-truth box is at least 0.5, and background when its maximum IoU falls in the interval from bg lo up to 0.5.

A separate rule rebalances the classes by undersampling background RoIs, so that the foreground-to-background ratio is 1 : 3 and 25% of each mini-batch is foreground. The authors found this design important: removing the ratio or increasing it reduced accuracy by about 3 mAP points.

## Selecting hard RoIs inside each SGD step

OHEM keeps the alternation of hard example mining but shrinks each freeze to a single mini-batch. At iteration t the convolutional network computes a feature map for the image once, and then every candidate RoI from that image goes through RoI pooling, the fully connected layers and the loss. Only the forward computation is paid for all candidates, and most of it is shared through the feature map, so the extra work over the baseline stays modest.

The B/N RoIs with the largest loss are kept for the backward pass, so the update depends on the current model rather than on a fixed random draw.

Overlapping RoIs tend to have similar losses and can map to the same region of the feature map, so a plain top-k selection could keep the same region many times. OHEM applies non-maximum suppression to the losses: it keeps the highest-loss RoI and drops lower-loss RoIs that overlap it beyond an IoU threshold. That threshold is relaxed to 0.7, so only heavily overlapping RoIs are removed.

OHEM needs no foreground-to-background ratio, because a class that is neglected accumulates loss and is then sampled. An image whose foreground is easy, such as a canonical car view, can contribute only background RoIs, and an image with trivial background can contribute only foreground RoIs.

## Two copies of the RoI network

The obvious implementation puts the selection in the loss layer: compute every loss, zero the losses of the non-hard RoIs and backpropagate. This still allocates memory and runs a backward pass for all RoIs, even though most of them end with zero gradient.

The implementation keeps two RoI networks, and the read-only copy runs only a forward pass over all RoIs to compute their losses. Because the read-only copy stores no backward state, its memory cost comes from the forward pass alone. The hard RoI sampling module then picks the set Rhard-sel, and the regular RoI network runs forward and backward passes only on those RoIs.

Gradients from the selected RoIs are accumulated and passed into the convolutional network.

All RoIs from all N images form R, so the read-only copy processes \|R\| RoIs per step while the regular copy processes the standard batch of B. With N = 2 the set R has about 4000 RoIs and B is 128. The authors built this in Caffe, using gradient accumulation across N forward and backward passes of single-image mini-batches. Under these settings the design has a memory footprint similar to the naive version and runs more than 2× faster.

## Removing the background threshold

On VGGM, dropping the threshold cost 2.4 mAP points, while VGG16 stayed roughly level.

## Using one image per mini-batch

With N = 2, RoIs from one image can have correlated gradients, which may make training unstable. OHEM picks high-loss RoIs from the same image, so the authors expected correlation to be stronger and tested N = 1 to try to break the method. With N = 1, the baseline Fast R-CNN lost about one mAP point on VGG16, while OHEM stayed at roughly the same mAP.

The authors conclude that OHEM is robust when fewer images per batch are needed to reduce GPU memory use.

## Large batches versus selecting hard RoIs

The alternative is to skip selection and train on all RoIs, relying on easy examples having low loss so that they contribute little to the gradient. This comparison uses Fast R-CNN with B = 2048 and bg lo = 0, with N taking the values 1 and 2. The learning rate was raised to 0.003 for VGG16 and 0.004 for VGGM to suit the larger batch.

Compared with B = 128, the large batch raised mAP of both VGG16 and VGGM by about 1 point. OHEM stayed more than 1 point ahead of training on all RoIs. Because the gradients are computed on fewer RoIs, the authors note that training with OHEM is faster than the large-batch setting.

## Training loss on a common RoI set

Losses reported by each method on its own sampled RoIs would not be comparable, so the authors evaluated model snapshots on the whole VOC07 trainval set. Snapshots were taken every 20k steps and their average loss over all RoIs was computed, which does not depend on the sampling scheme. Among the baseline variants, bg lo = 0 gives the highest training loss, and bg lo = 0.1 gives a much lower one.

OHEM reaches the lowest training loss of the methods compared, below the bg lo = 0.1 heuristic. Lower training loss indicates better optimization; detection quality is measured separately by mAP.

## Time and memory cost

Table 2 reports time per iteration and peak memory on an Nvidia Titan X GPU. For VGGM, Fast R-CNN takes 0.13 s per iteration with 2.6G of memory, and OHEM takes 0.22 s with 3.6G. The authors summarize the VGGM overhead as 0.09 s per iteration and 1G more memory, and give 0.43 s more per iteration for VGG16.

For VGG16, the standard Fast R-CNN takes 0.60 s per iteration with 11.2G. With gradient accumulation over two forward and backward passes, the baseline uses 6.4G at 0.57 s, while OHEM uses 8.7G at 1.00 s. The authors judge the added training time acceptable, since Fast R-CNN is already fast to train.

## PASCAL VOC results with plain Fast R-CNN

On VOC 2007 with the 07 trainval set, OHEM raised VGG16 Fast R-CNN from 67.2% to 69.9% mAP, with both runs using the paper's training schedule. With the 07+12 training set, the same comparison moved from 70.0% to 74.6%.

On VOC 2012 test, trained on VOC12 trainval, OHEM moved mAP from 65.7% to 69.8%. With the 07++12 training set, OHEM reached 71.9% against 68.4% for Fast R-CNN, a gain of 3.5 points.

Gains varied across categories: the authors report that bottle, chair and tvmonitor improved the most, consistently across the PASCAL splits. The authors state that why these classes benefit most is an open question.

## Adding multi-scale testing and iterative box regression

Multi-scale training picks one shortest-side scale at random per image, and testing runs on several scales, with training scales of 480, 576, 688, 864 and 900 and test scales of 480, 576, 688, 864 and 1000, capped at a maximum dimension of 1000. Iterative bounding-box regression runs localization again on relocalized boxes, followed by NMS at an IoU threshold of 0.3 and weighted voting with boxes at IoU of 0.5 or more.

Multi-scale in both training and testing raised baseline Fast R-CNN from 67.2% to 68.6% mAP, and the authors note that using it only at training time gives little benefit. The authors report higher mAP with OHEM in every variant of the two additions, and describe 75.1% as the best reported for methods trained on VOC07 data.

## Comparison with MR-CNN on VOC

With the 07+12 training set on VOC 2007 test, OHEM reached 78.9% mAP against 78.2% for MR-CNN. The authors note that MR-CNN used selective search and edge boxes during training, whereas OHEM here uses only selective search boxes. The multi-scale setup also differs, with OHEM using fewer scales than MR-CNN.

On VOC 2012 test with the 07++12 training set, OHEM reached 76.3% against 73.9% for MR-CNN. The MR-CNN numbers are the values listed in the comparison tables.

## MS COCO results

The table marks the Fast R-CNN column as taken from the leaderboard, so it is a reported value rather than a run under this paper's settings. The authors state that both Fast R-CNN and OHEM were trained on the MS COCO train set.

At IoU 0.5, OHEM reached 42.5 AP50 against 35.9, a gain of 6.6 points. For medium-sized objects, AP rose from 18.8 to 23.7, and the authors use this to argue that hard example mining helps with smaller objects.

Adding multi-scale training and testing raised OHEM to 24.4% AP and 44.4% AP50. Training on the full trainval set reached 25.5% AP and 45.9% AP50, and the table footnote marks this as trained on trainval. A variant of this approach placed 4th overall in the 2015 MS COCO Detection Challenge.

## Limits of the evidence

OHEM adds computation and memory: about 0.09 s per iteration and 1G more memory for VGGM, and more for VGG16.

All OHEM experiments are built on Fast R-CNN; the authors state that OHEM can train any region-based ConvNet detector, but this paper does not test other detectors. Robustness to fewer images per batch is shown only for N = 1. The authors leave open why some categories gain more than others.

## Paper info

- **Authors**: Abhinav Shrivastava, Abhinav Gupta, Ross Girshick
- **Venue**: arXiv · Preprint
- **First published**: 2016-4-12
- **Added**: 2026-11-12
- **Updated**: 2016-4-12
- **Version**: v1
- **arXiv**: 1604.03540
- **Category**: cs.CV · cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1604.03540v1) · [PDF ↗](https://arxiv.org/pdf/1604.03540v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Abhinav Shrivastava, Abhinav Gupta, Ross Girshick (2016). Training Region-based Object Detectors with Online Hard Example Mining. arXiv:1604.03540v1. https://arxiv.org/abs/1604.03540v1

**BibTeX**

```
@misc{shrivastava2016training,
  title = {{Training Region-based Object Detectors with Online Hard Example Mining}},
  author = {Abhinav Shrivastava and Abhinav Gupta and Ross Girshick},
  year = {2016},
  eprint = {1604.03540},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1604.03540v1}
}
```

## Other paper commentary

- [Unsupervised Learning of Visual Features by Contrasting Cluster Assignments](https://refivu.com/en/papers/8f949bbf-9733-4844-b3ee-a88f5313c480-unsupervised-learning-of-visual-features-by-contrasting.md)
- [PWC-Net: CNNs for Optical Flow Using Pyramid, Warping, and Cost Volume](https://refivu.com/en/papers/ad6f8625-4b03-4079-ad4e-a2126c614f62-pwc-net-cnns-for-optical-flow-using-pyramid.md)
- [VMamba: Visual State Space Model](https://refivu.com/en/papers/4032560e-3e65-4a0f-b564-34cb12bd1c92-vmamba-visual-state-space-model.md)
- [Speed/accuracy trade-offs for modern convolutional object detectors](https://refivu.com/en/papers/d59f0ced-71a6-4425-a177-e2e9ad7b8370-speed-accuracy-trade-offs-for-modern-convolutional-object.md)
- [Building Machines That Learn and Think Like People](https://refivu.com/en/papers/1c62e17f-b645-4165-8400-ffcbcd4abc96-building-machines-that-learn-and-think-like-people.md)
- [EnlightenGAN: Deep Light Enhancement without Paired Supervision](https://refivu.com/en/papers/1b24a8a7-0c9f-4dc7-b6db-20e08b8a1feb-enlightengan-deep-light-enhancement-without-paired.md)
- [Adversarial Autoencoders](https://refivu.com/en/papers/8e20edb4-f017-4781-86f9-478c6059260f-adversarial-autoencoders.md)
- [Abstractive Text Summarization Using Sequence-to-Sequence RNNs and Beyond](https://refivu.com/en/papers/7a55aaf9-654e-4a97-8efc-d0b4a9fccb7a-abstractive-text-summarization-using-sequence-to-sequence.md)
- [A Comprehensive Overview of Large Language Models](https://refivu.com/en/papers/4e2425c0-8669-49f7-80be-dd35ce0a70b2-a-comprehensive-overview-of-large-language-models.md)
- [CvT: Introducing Convolutions to Vision Transformers](https://refivu.com/en/papers/4d0c84cf-05bb-4f74-822e-0b8fbc635203-cvt-introducing-convolutions-to-vision-transformers.md)
- [Stable Video Diffusion: Scaling Latent Video Diffusion Models to Large Datasets](https://refivu.com/en/papers/82291bd9-5c41-4b81-bfde-a025a948f4b9-stable-video-diffusion-scaling-latent-video-diffusion-models.md)
- [The Curious Case of Neural Text Degeneration](https://refivu.com/en/papers/71a193c3-9d38-4eb3-b0de-39d943c746b0-the-curious-case-of-neural-text-degeneration.md)

## Terms in this paper

- [Stochastic Gradient Descent](https://refivu.com/en/terms/a49650824022-stochastic-gradient-descent)
- [Object detection](https://refivu.com/en/terms/113bfdb14049-object-detection)
- [mAP](https://refivu.com/en/terms/477dad058d88-map)
- [non-maximum suppression](https://refivu.com/en/terms/a710b7d63bcd-non-maximum-suppression)
- [Hard Negative Mining](https://refivu.com/en/terms/fa1aacdee448-hard-negative-mining)
- [PASCAL VOC 2007](https://refivu.com/en/terms/ff90fa43ba1c-pascal-voc-2007)
- [selective search](https://refivu.com/en/terms/d7b58bb84ff0-selective-search)
- [VGG16](https://refivu.com/en/terms/6492e9fd5cf1-vgg16)
- [OHEM](https://refivu.com/en/terms/539047a448da-ohem)
- [bootstrapping](https://refivu.com/en/terms/1b26e51a5096-bootstrapping)
- [SPPnet](https://refivu.com/en/terms/ec14b0a291a8-sppnet)
- [COCO AP](https://refivu.com/en/terms/39c430921533-coco-ap)
- [MR-CNN](https://refivu.com/en/terms/5b61d794948b-mr-cnn)
- [VGG CNN M 1024](https://refivu.com/en/terms/1034773cc313-vgg-cnn-m-1024)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/3c16d5fe-9eb6-4481-9b4d-f4eefd0171ee-training-region-based-object-detectors-with-online-hard)
