Sub topic 6
Two-Stage Detection: From R-CNN to Faster R-CNN
Assume you know convolutional neural networks, feature maps, classification, regression, and gradient-descent training. Basic familiarity with Intersection over Union (IoU) is also useful. A two-stage detector first proposes regions that might contain objects. It then classifies and refines those regions.
The idea behind two stages
Image classification answers, “What is in this image?” Object detection must also answer, “Where is each object?” A detector therefore predicts a class label and a bounding box for every object.
The first stage reduces the search space. Instead of asking a neural network to classify every possible box, it produces a smaller set of candidate regions. The second stage examines each candidate in more detail.
R-CNN: classify each proposal
The original R-CNN used an external algorithm called selective search to generate roughly 2,000 region proposals per image. For every proposal, R-CNN performed these steps:
- Warp the proposed region to a fixed image size.
- Run the region through a convolutional neural network.
- Use class-specific classifiers to predict its object category.
- Use a separate bounding-box regressor to adjust its coordinates.
- Apply non-maximum suppression (NMS) to remove duplicate detections.
This approach worked well, but it was slow. The convolutional network ran separately for every proposal. Training was also split into several stages, which made the system difficult to optimize.
Fast R-CNN: share the backbone
Fast R-CNN runs the convolutional network once on the entire image. This produces a feature map. It then projects each proposal onto that feature map and uses RoI pooling, or region-of-interest pooling, to extract a fixed-size feature for each proposal.
The extracted feature goes to two prediction heads:
- A classification head predicts the object class, including background.
- A box-regression head predicts coordinate corrections.
Sharing the convolutional computation makes Fast R-CNN much faster than R-CNN. However, it still depends on selective search. Proposal generation remains a separate, relatively slow step.
Faster R-CNN: learn the proposals
Faster R-CNN replaces selective search with a region proposal network (RPN). The RPN is a small neural network that runs on the shared backbone feature map.
At each feature-map location, the RPN evaluates reference boxes called anchors. For each anchor, it predicts:
- An objectness score: whether the anchor likely contains any object.
- Box offsets: how the anchor should move and resize.
The highest-scoring refined anchors become region proposals. The detector then extracts RoI features from those proposals and predicts their classes and final box adjustments.
| Detector | Proposal source | Shared image computation | Main limitation |
|---|---|---|---|
| R-CNN | Selective search | No | Very slow |
| Fast R-CNN | Selective search | Yes | Proposal generation is slow |
| Faster R-CNN | Learned RPN | Yes | More computation than many one-stage detectors |
Training and trade-offs
Faster R-CNN trains the RPN and the detection head with classification and box-regression losses. Anchors are matched to ground-truth boxes using IoU. Anchors with high overlap become positive examples, while low-overlap anchors usually become background examples.
The two-stage design lets the second stage spend more computation on a small number of promising regions. It often gives strong accuracy, especially for crowded scenes and small objects. The cost is higher latency and a more complex pipeline than single-stage detectors.
Exercise
Why was Faster R-CNN faster than Fast R-CNN even though both shared a convolutional backbone?
Show answer
Faster R-CNN learned proposals with an RPN, replacing the slower external selective-search step.