arXiv(opens in a new tab)MedicineAug 2017Cited by 14 papers on PaperVantage

Manuscript Offprint

arXiv:1708.02002

Focal Loss for Dense Object Detection

Tsung-Yi Lin, Priya Goyal, Ross B. Girshick, Kaiming He, Piotr Dollár

Abstract

The highest accuracy object detectors to date are based on a two-stage approach popularized by R-CNN, where a classifier is applied to a sparse set of candidate object locations. In contrast, one-stage detectors that are applied over a regular, dense sampling of possible object locations have the potential to be faster and simpler, but have trailed the accuracy of two-stage detectors thus far. In this paper, we investigate why this is the case. We discover that the extreme foreground-background class imbalance encountered during training of dense detectors is the central cause. We propose to address this class imbalance by reshaping the standard cross entropy loss such that it down-weights the loss assigned to well-classified examples. Our novel Focal Loss focuses training on a sparse set of hard examples and prevents the vast number of easy negatives from overwhelming the detector during training. To evaluate the effectiveness of our loss, we design and train a simple dense detector we call RetinaNet. Our results show that when trained with the focal loss, RetinaNet is able to match the speed of previous one-stage detectors while surpassing the accuracy of all existing state-of-the-art two-stage detectors. Code is at: https://github.com/facebookresearch/Detectron.

CEttFLttt

Figure 1: We propose a novel loss we term the Focal Loss that adds a factor (1−pt)γ(1-p_{\textrm{t}})^{\gamma} to the standard cross entropy criterion. Setting γ>0\gamma>0 reduces the relative loss for well-classified examples (pt>.5p_{\textrm{t}}>.5), putting more focus on hard, misclassified examples. As our experiments will demonstrate, the proposed focal loss enables training highly accurate dense object detectors in the presence of vast numbers of easy background examples.

AP time [A] YOLOv2† [27] 21.6 25 [B] SSD321 [22] 28.0 61 [C] DSSD321 [9] 28.0 85 [D] R-FCN‡ [3] 29.9 85 [E] SSD513 [22] 31.2 125 [F] DSSD513 [9] 33.2 156 [G] FPN FRCN [20] 36.2 172 RetinaNet-50-500 32.5 73 RetinaNet-101-500 34.4 90 RetinaNet-101-800 37.8 198 †Not plotted ‡Extrapolated time

Figure 2: Speed (ms) versus accuracy (AP) on COCO test-dev. Enabled by the focal loss, our simple one-stage RetinaNet detector outperforms all previous one-stage and two-stage detectors, including the best reported Faster R-CNN [28] system from [20]. We show variants of RetinaNet with ResNet-50-FPN (blue circles) and ResNet-101-FPN (orange diamonds) at five scales (400-800 pixels). Ignoring the low-accuracy regime (AP<<25), RetinaNet forms an upper envelope of all current detectors, and an improved variant (not shown) achieves 40.8 AP. Details are given in §5.

1 Introduction

Current state-of-the-art object detectors are based on a two-stage, proposal-driven mechanism. As popularized in the R-CNN framework [11], the first stage generates a sparse set of candidate object locations and the second stage classifies each candidate location as one of the foreground classes or as background using a convolutional neural network. Through a sequence of advances [10, 28, 20, 14], this two-stage framework consistently achieves top accuracy on the challenging COCO benchmark [21].

Despite the success of two-stage detectors, a natural question to ask is: could a simple one-stage detector achieve similar accuracy? One stage detectors are applied over a regular, dense sampling of object locations, scales, and aspect ratios. Recent work on one-stage detectors, such as YOLO [26, 27] and SSD [22, 9], demonstrates promising results, yielding faster detectors with accuracy within 10-40% relative to state-of-the-art two-stage methods.

This paper pushes the envelop further: we present a one-stage object detector that, for the first time, matches the state-of-the-art COCO AP of more complex two-stage detectors, such as the Feature Pyramid Network (FPN) [20] or Mask R-CNN [14] variants of Faster R-CNN [28]. To achieve this result, we identify class imbalance during training as the main obstacle impeding one-stage detector from achieving state-of-the-art accuracy and propose a new loss function that eliminates this barrier.

Class imbalance is addressed in R-CNN-like detectors by a two-stage cascade and sampling heuristics. The proposal stage (e.g., Selective Search [35], EdgeBoxes [39], DeepMask [24, 25], RPN [28]) rapidly narrows down the number of candidate object locations to a small number (e.g., 1-2k), filtering out most background samples. In the second classification stage, sampling heuristics, such as a fixed foreground-to-background ratio (1:3), or online hard example mining (OHEM) [31], are performed to maintain a manageable balance between foreground and background.

In contrast, a one-stage detector must process a much larger set of candidate object locations regularly sampled across an image. In practice this often amounts to enumerating ∼\scriptstyle\sim100k locations that densely cover spatial positions, scales, and aspect ratios. While similar sampling heuristics may also be applied, they are inefficient as the training procedure is still dominated by easily classified background examples. This inefficiency is a classic problem in object detection that is typically addressed via techniques such as bootstrapping [33, 29] or hard example mining [37, 8, 31].

In this paper, we propose a new loss function that acts as a more effective alternative to previous approaches for dealing with class imbalance. The loss function is a dynamically scaled cross entropy loss, where the scaling factor decays to zero as confidence in the correct class increases, see Figure 1. Intuitively, this scaling factor can automatically down-weight the contribution of easy examples during training and rapidly focus the model on hard examples. Experiments show that our proposed Focal Loss enables us to train a high-accuracy, one-stage detector that significantly outperforms the alternatives of training with the sampling heuristics or hard example mining, the previous state-of-the-art techniques for training one-stage detectors. Finally, we note that the exact form of the focal loss is not crucial, and we show other instantiations can achieve similar results.

To demonstrate the effectiveness of the proposed focal loss, we design a simple one-stage object detector called RetinaNet, named for its dense sampling of object locations in an input image. Its design features an efficient in-network feature pyramid and use of anchor boxes. It draws on a variety of recent ideas from [22, 6, 28, 20]. RetinaNet is efficient and accurate; our best model, based on a ResNet-101-FPN backbone, achieves a COCO test-dev AP of 39.1 while running at 5 fps, surpassing the previously best published single-model results from both one and two-stage detectors, see Figure 2.

References (34)

  • Inside-outside net: Detecting objects in context with skip pooling and recurrent neural networks
  • Loss max-pooling for semantic image segmentation
  • R-FCN: Object detection via region-based fully convolutional networks
  • Histograms of oriented gradients for human detection
  • Integral channel features
  • Scalable object detection using deep neural networks
  • The PASCAL Visual Object Classes (VOC) Challenge
  • Cascade object detection with deformable part models
  • C.-Y. Fu, W. Liu, A. Ranga, A. Tyagi, and A. C. Berg. DSSD: Deconvolutional single shot detector. arXiv:1701.06659, 2016. (opens arXiv in a new tab)
  • Rich feature hierarchies for accurate object detection and semantic segmentation
  • The elements of statistical learning
  • Mask R-CNN
  • Spatial pyramid pooling in deep convolutional networks for visual recognition
  • Deep residual learning for image recognition
  • Speed/accuracy trade-offs for modern convolutional object detectors
  • ImageNet classification with deep convolutional neural networks
  • Backpropagation applied to handwritten zip code recognition
  • SSD: Single shot multibox detector
  • Fully convolutional networks for semantic segmentation
  • Learning to segment object candidates
  • Lin, R. Collobert, and P. Dollár
  • You only look once: Unified, real-time object detection
  • YOLO9000: Better, faster, stronger
  • Faster R-CNN: Towards real-time object detection with region proposal networks
  • Human face detection in visual scenes
  • Overfeat: Integrated recognition, localization and detection using convolutional networks
  • Training region-based object detectors with online hard example mining
  • Beyond skip connections: Top-down modulation for object detection (opens arXiv in a new tab)
  • Inception-v4, inception-resnet and the impact of residual connections on learning
  • Selective search for object recognition
  • Original approach for the localisation of objects in images
  • Rapid object detection using a boosted cascade of simple features
  • Aggregated residual transformations for deep neural networks
  • Edge boxes: Locating object proposals from edges