CSE445Computer Vision
Tutorials/Object Detection/Faster R-CNN: Region Proposal Network
OD-04Intermediate 120 min

Faster R-CNN: Region Proposal Network

Dissect the Faster R-CNN architecture: how the RPN shares backbone features, generates anchors, scores objectness, regresses box deltas, and feeds proposals into the detection head.

PyTorchtorchvisionMatplotlib

Code Structure Note

These notes are provided only to help students understand the code structure. Students should review, optimize, and adapt the code before using it in assignments, projects, or experiments.

Topics Covered
  1. 1Region Proposal Network (RPN): 3×3 sliding window, k anchor boxes per location
  2. 2Anchor design: scales × aspect ratios, total anchor count across the feature map
  3. 3RPN training: binary objectness loss (BCE) + smooth-L1 regression loss
  4. 4RoI pooling and RoI Align: bilinear interpolation for sub-pixel accuracy
  5. 5Feature Pyramid Network (FPN): lateral connections for multi-scale proposal assignment

Learning Objectives

  • Explain the RPN's dual role: objectness classifier and box delta regressor for each anchor
  • Calculate the total number of anchors generated by an RPN over a 38×50 feature map
  • Compare RoI Pooling and RoI Align and explain when misalignment matters
  • Trace a full Faster R-CNN forward pass: image → backbone → RPN → RoI → head → NMS

Key Takeaways

  • RPN turns region proposals into a learned, GPU-resident operation — <10 ms vs. 2 s for selective search
  • Anchors tile every feature map location with k (scale × ratio) prior boxes
  • RoI Align fixes the quantisation error in RoI Pooling and is essential for Mask R-CNN
  • FPN creates a feature hierarchy so small objects are detected from high-resolution early maps

Tutorial Infographic

Notebook Resources

Jupyter Notebook

Student action area

Use this section to practice the tutorial code. Kaggle opens the prepared notebook, Colab lets you experiment in your own runtime, and the .ipynb download is best for local editing or submission.

Kaggle: follow the official tutorial notebook.
Colab: modify and rerun quickly.
IPYNB: keep a local copy.

Hands-On Exercises

  1. 1Load torchvision `fasterrcnn_resnet50_fpn` and run inference on 10 COCO val images
  2. 2Visualise the top-50 RPN proposals (before NMS) overlaid on a sample image
  3. 3Compute anchors for a single feature map level (stride=16, 3 scales × 3 ratios) in NumPy
  4. 4Fine-tune Faster R-CNN on a 200-image custom dataset and report mAP@50 before and after

Tools & Libraries

PyTorchtorchvisionMatplotlib