Faster R-CNN

Faster R-CNN (Ren et al., 2015) consolidated the modern era of Object Detection, evolving directly from fast-r-cnn to integrate all process steps into a single, unified end-to-end network.

The Evolutionary Context

Historically, the pipeline evolved by attempting to eliminate computational performance bottlenecks:

  • R-CNN: Passed 2,0002,000 image crops one by one through the neural network. (Infeasible and slow).
  • Fast R-CNN (and spp-net): Passed the image only once through the network, reusing the generated feature map using roi-pooling. This solved the network bottleneck but exposed a new problem: the generation of Region Proposals (Selective Search algorithm running on CPU) became the bottleneck, taking 2\sim 2 seconds per image.

The Trump Card: Region Proposal Network (RPN)

The stroke of genius in Faster R-CNN was to throw away Selective Search and replace it with a fully convolutional Region Proposal Network (RPN).

The RPN is a tiny network that slides a 3×33 \times 3 window (sliding window) over the convolutional feature map generated by the backbone. Each window is encoded into a short vector (256256-d for the ZF backbone, 512512-d for VGG-16) that feeds two sibling layers. At each position, the network uses the concept of Anchor Boxes (pre-defined reference boxes at various scales and aspect ratios) to predict:

  1. Objectness Score: A number indicating the probability of any object being there (background vs. object).
  2. Bounding Box Regression: Precise adjustments (deltas) in x,y,w,hx, y, w, h to perfectly frame the anchor around the object’s mass.

Anchor Boxes and Translation Invariance

Anchors are reference boxes centered at each sliding-window position. The paper uses 3 scales (areas of 1282128^2, 2562256^2 and 5122512^2 pixels) and 3 aspect ratios (1:11{:}1, 1:21{:}2, 2:12{:}1), totaling k=9k = 9 anchors per position — roughly 20,00020{,}000 anchors per image. Thus, the classification layer has 2k2k outputs (object/background per anchor) and the regression layer has 4k4k (the deltas per anchor).

The design is translation invariant: if the object moves in the image, the same function predicts the proposal at the new location. This contrasts with earlier methods (MultiBox), whose k-means-fixed anchors required an output layer with an order of magnitude more parameters (2727M vs. 2.42.4M with VGG-16) — and more overfitting risk on small datasets like PASCAL VOC.

⚠️ Practical pitfall: anchors that cross the image boundary must be ignored during training (they do not contribute to the loss). Without this, their large, hard-to-correct error terms prevent convergence. At test time, boundary-crossing boxes are simply clipped to the image limits.

Anchor Labeling

During training, each anchor receives a binary label:

  • Positive: the anchor with the highest IoU with a ground-truth box, or any anchor with IoU >0.7> 0.7 with any ground-truth box.
  • Negative: a non-positive anchor with IoU <0.3< 0.3 for all ground-truth boxes.
  • Ignored: everything in between does not contribute to the loss.

Since negatives dominate, each mini-batch samples 256256 anchors per image keeping up to a 1:11{:}1 positive-to-negative ratio.

The loss function of the RPN is also multi-task, optimizing these two outputs simultaneously:

L({pi},{ti})=1NclsiLcls(pi,pi)+λ1NregipiLreg(ti,ti)L(\{p_i\}, \{t_i\}) = \frac{1}{N_{cls}} \sum_i L_{cls}(p_i, p_i^*) + \lambda \frac{1}{N_{reg}} \sum_i p_i^* L_{reg}(t_i, t_i^*)

Eq. 1: Loss Function of the Region Proposal Network (RPN).

Where:

  • ii: index of the anchor being evaluated in a mini-batch.
  • pip_i: predicted probability that anchor ii is an object.
  • pip_i^*: binary ground truth (11 if the anchor is an object, 00 if it is background). An anchor is positive if it has a high IoU.
  • tit_i: vector representing the 4 predicted parameterized bounding box coordinates.
  • tit_i^*: ground truth vector containing the target coordinate adjustments.
  • LclsL_{cls}: classification loss function (log loss over two classes).
  • LregL_{reg}: spatial regression loss function (Smooth L1).
  • Ncls,NregN_{cls}, N_{reg}: normalization terms.
  • λ\lambda: balancing hyperparameter.
  • The term piLregp_i^* L_{reg} ensures that regression loss is activated only for positive anchors (pi=1p_i^* = 1).

End-to-End Unification

The catch is that the RPN shares the same convolutional feature map as the final detection network. In other words, generating region proposals became a practically cost-free process (taking only 10\sim 10 milliseconds).

The proposals generated by the RPN go through Non-Maximum Suppression (NMS, with a fixed IoU of 0.70.7) to eliminate redundancy, and only the top 300300 proposals ranked by objectness score move forward. They are then sent to an roi-pooling layer, which extracts fixed vectors to pass through the final layers, where the network classifies (is it a dog or a car?) and makes the final refinement of the bounding box.

4-Step Alternating Training

Training RPN and Fast R-CNN jointly from scratch does not converge trivially, because the detector depends on fixed proposals. The paper’s pragmatic solution is alternating optimization:

  1. Train the RPN alone (initialized with ImageNet pre-trained weights).
  2. Train Fast R-CNN separately, using the proposals from the step-1 RPN — the two networks do not share convolutions yet.
  3. Reinitialize the RPN with the detector’s weights, freeze the shared convolutions and fine-tune only the RPN-specific layers. The networks now share features.
  4. Fine-tune only Fast R-CNN’s fully-connected layers, keeping the convolutions frozen. The result: a single unified network.

Results and Ablation Lessons

With VGG-16, the system reaches 5 fps (198ms per image, versus 1830ms for the Selective Search pipeline) with 73.2%73.2\% mAP on PASCAL VOC 2007 — and 17 fps with the ZF backbone. The paper’s ablation experiments are worth as much as the final numbers:

  • Without the cls layer (no objectness ranking), mAP collapses from 56.8%56.8\% to 44.6%44.6\% with 100 proposals — the confidence score is what guarantees top-of-ranking quality.
  • Without the reg layer (raw anchors, no regression), mAP drops to 52.1%52.1\% — anchors alone are not enough; regression is what refines the positions.
  • Two-stage beats one-stage: emulating the OverFeat style (dense windows in a single stage) drops mAP by 4.8\sim 4.8 points, justifying the proposal → detection cascade.

References and tools


Related: fast-r-cnn · spp-net · roi-pooling · ablation-study · evolucao-mask-rcnn

Built with Eleventy · search by Lunr.js