online hard example mining

OHEM (Online Hard Example Mining) is a training method that selects the hardest examples within each mini-batch for backpropagation — performing a forward pass on all examples, ranking by loss, and backpropagating only through the top-K hardest examples.

How OHEM Works

  • Forward Pass: Compute loss for all examples in the mini-batch.
  • Rank: Sort examples by loss (descending) — highest-loss examples are hardest.
  • Select: Keep only the top-K (or top ratio) of examples for backpropagation.
  • Backward: Compute gradients only for the selected hard examples.

Why It Matters

  • Object Detection: OHEM was proposed for Fast R-CNN to handle the extreme foreground/background imbalance in region proposals.
  • No Heuristics: Unlike fixed sampling ratios, OHEM automatically selects the batch composition.
  • Background Reduction: In detection, 99%+ of proposals are background — OHEM ensures the model learns from the few hard examples.

OHEM is training only on the hardest cases per batch — automatically focusing each gradient update on the most informative examples.

Go deeper with CFSGPT

Get AI-powered deep-dives, save terms, and run advanced simulations — free account.

Create Free Account