Foundations to Frontier
Tests
E. Deep Learning › E9 Object Detection Architectures

Feature Pyramid Network (FPN)

Feature Pyramid Networks (Lin et al., 2017) give a detector strong features at every scale for little extra cost. A top-down pathway upsamples the deepest, most semantic feature map and adds it, through 1 × 1 lateral connections, to each finer backbone stage. The result is a pyramid P2–P5 (plus P6) whose levels all carry high-level semantics. Proposals and RoIs are assigned to the level that matches their size. Adding FPN to Faster R-CNN raised COCO AP and especially recall of small objects. This page covers the pathway, lateral connections, anchors per level and the level-assignment rule. In the exercises you build the top-down pathway, then show that FPN gives every RoI from 64 px up 16 cells per side and lets one-size-per-level anchors cover 88% of objects instead of 51%.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Strong features at every size

A CNN’s early layers keep fine detail but know little about what they see; its last layers know what things are but have blurred away small details. Small objects need both. A Feature Pyramid Network carries the deep, well-informed features back down to the fine layers: it upsamples them step by step and adds them to the earlier, sharper maps. Each object is then handled at the level of the pyramid that suits its size: small objects on fine maps, large ones on coarse maps.

Detection lab
216 anchors; 0 positive (IoU ≥ 0.5); best IoU with the ground truth 0.46 — no positive anchor, so the best one is also assigned (highlighted)
Why engineers care

Drones and satellites see objects at wildly different sizes, from a person a few pixels tall to a large building. FPN is the standard way detectors and segmenters handle that range, and it appears in almost every modern detector.

📝 Quick check (Level 0)
0/3 answered
  1. 1. FPN carries deep features…
  2. 2. Small objects are handled on…
  3. 3. FPN mainly helps with…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Backbone stages C2–C5 (ResNet) have strides 4, 8, 16 and 32.
  • Top-down pathway:
    • P5 = 1 × 1 conv(C5);
    • P_k = 1 × 1 conv(C_k) + 2× upsample(P_(k+1));
    • then a 3 × 3 conv on each to reduce aliasing;
    • all levels have 256 channels, and P6 is a stride-2 subsampling of P5.
  • Parameters per level:
    • lateral 1 × 1 from 2,048 channels: 524,544;
    • 3 × 3 smoothing at 256 channels: 590,080 (with biases).
  • Anchors: one area per level, 32² on P2 up to 512² on P6, with 3 ratios.
  • RoI level rule: k = ⌊4 + log₂(√(wh)/224)⌋, clipped to 2–5. A 224 × 224 RoI goes to P4 (stride 16); a 112 × 112 RoI to P3.
  • Cells per side: a 128-pixel RoI lands on P3 (stride 8), 16 cells; a 512-pixel RoI on P5 (stride 32), also 16 cells.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Level of a 224 × 224 RoI:
  2. 2. Channels on every FPN level:
  3. 3. Anchors on P2 have area…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

FPN in code

Exercise 1.

  • The top-down pathway produced maps of 16 × 16 down to 2 × 2, all of the same width.
  • Each level equalled its lateral projection plus the upsampled coarser level.
  • The level rule sent RoIs of 32, 112, 224, 448 and 1,000 pixels to P2, P3, P4, P5 and P5.

Practice.

  • torchvision’s torchvision.ops.FeaturePyramidNetwork and the *_fpn detection models implement FPN. Mask R-CNN, RetinaNet (E9-10) and FCOS (E9-11) all use it.
  • The RPN head is shared across levels, which keeps it small and consistent across scales.
  • RoIAlign pools from the assigned level.
  • Variants: PANet adds a bottom-up path; BiFPN (EfficientDet) uses weighted bidirectional fusion; NAS-FPN found a pathway by search.
fpn = torchvision.ops.FeaturePyramidNetwork(in_channels_list=[256, 512, 1024, 2048], out_channels=256)
pyramid = fpn(OrderedDict(c2=c2, c3=c3, c4=c4, c5=c5))      # P2..P5, all 256 channels
🐍 Exercise 1: the top-down pathway
Implement 2× upsampling, lateral 1 × 1 connections, FPN's top-down pathway and the RoI level rule.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The RPN head across FPN levels is…
  2. 2. PANet adds…
  3. 3. EfficientDet's FPN variant:

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why a pyramid of features.

  • Image pyramids give strong features at every scale but multiply the compute.
  • A single deep map is strong but coarse.
  • The backbone’s own hierarchy (as in SSD, E9-6) is multi-scale, but its fine levels are semantically weak.

FPN gives every level both properties at low cost:

  • the top-down pathway brings in semantics;
  • the lateral connections bring in precise localisation.

Scale normalisation. Assigning each RoI to a level in proportion to its size means each is pooled from a map where it spans a similar number of cells (exercise 2). The detector head then sees objects at a nearly constant relative resolution, like an image pyramid at a fraction of the cost.

Results.

  • With FPN, the RPN’s average recall over 1,000 proposals rose by 8.0 points, and by 12.9 for small objects.
  • Faster R-CNN with ResNet-101-FPN reached 36.2 AP on COCO test-dev as a single model, the best at the time.
  • The paper reported an inference time of about 0.15 s per image on a GPU.
📝 Quick check (Level 3)
0/3 answered
  1. 1. SSD's multi-scale maps are…
  2. 2. FPN raised RPN recall for small objects by about…
  3. 3. Assigning RoIs by size gives…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

What does the pyramid buy?

History.

  • T.-Y. Lin, P. Dollár, R. Girshick, K. He, B. Hariharan and S. Belongie (2017) introduced FPN at CVPR.
  • W. Liu et al. (2016) used multi-scale backbone maps in SSD; O. Ronneberger et al. (2015) used a similar top-down structure in U-Net for segmentation.
  • Later variants include PANet (S. Liu et al., 2018), NAS-FPN (G. Ghiasi et al., 2019) and BiFPN (M. Tan et al., 2020).

Exercise 2. These are calculations, not training runs:

  1. For square RoIs of 16 to 512 pixels, the cells per side on a single stride-16 map, and on the FPN level the rule assigns.
  2. For 400 objects of 16 to 400 pixels in a 512 × 512 image, anchor coverage with Faster R-CNN’s 9 anchors on one map, and with FPN’s 3 anchors per level on P2–P6.
RoI side cells per side, single map FPN level cells per side there
16 1 P2 4
32 2 P2 8
64 4 P2 16
128 8 P3 16
256 16 P4 16
512 32 P5 16
anchors count covered at IoU 0.5 at 0.7 small objects at 0.5
single level, 9 anchors 9,216 0.505 0.255 0.000
FPN, 3 per level (P2–P6) 65,472 0.883 0.395 0.706
  • FPN normalises scale. Every RoI from 64 px up spans 16 cells. Below that, the finest level (stride 4) still gives 4–8 cells, against 1–2 on a single map.
  • Coverage rises sharply, especially for small objects (71% against 0%), because the fine P2 level carries small anchors.
  • The cost: 7 times more anchors, mostly on P2. Real detectors keep this manageable by sampling anchors in training and keeping only top-scoring ones per level at inference.
🐍 Exercise 2 (research): what does the pyramid buy?
Compare RoI resolution and anchor coverage between a single feature map and an FPN pyramid.

FPN in AI, robotics and aerospace

  • Aerial and satellite detection: FPN-based detectors handle the extreme size range of objects in overhead imagery, from small vehicles to large ships.
  • Driving: pedestrians and signs far away appear tiny; FPN levels keep them detectable.
  • Segmentation: Panoptic FPN and similar designs reuse the pyramid for pixel-level tasks in robot perception.

References

  1. T.-Y. Lin, P. Dollár, R. Girshick, K. He, B. Hariharan, S. Belongie (2017). “Feature pyramid networks for object detection.” Proc. CVPR.
  2. S. Liu, L. Qi, H. Qin, J. Shi, J. Jia (2018). “Path aggregation network for instance segmentation.” Proc. CVPR.
  3. M. Tan, R. Pang, Q. V. Le (2020). “EfficientDet: scalable and efficient object detection.” Proc. CVPR.