Search

Search papers and lessons

Feature Pyramid Networks for Object Detection

Tsung-Yi Lin, Piotr Dollár, Ross Girshick et al. · 2016

The Feature Pyramid Network reuses a CNN's multi-scale maps and adds high-level meaning to each one, so detectors find both small and large objects at little extra cost.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Computer vision
  • Neural network basics
  • Linear algebra
  • Probability
  • ReadReady to readNot yet

TL;DR

An object detector has to find objects that are a few pixels wide and objects that fill the whole picture, and a single feature map is poor at both. Feature Pyramid Networks (FPN) take the maps a deep network already computes at several resolutions, and add a top-down path with lateral connections, so every level carries strong high-level meaning and precise location. The method adds little compute, and in the paper it raised the accuracy of a basic Faster R-CNN detector on COCO to a single-model state of the art.

Builds on: region proposal networks, convolutional networks · Leads to: Object Detection

Why it mattered

The paper made the feature pyramid a standard part of object detectors. Later systems, including Mask R-CNN and RetinaNet, took the FPN design as their multi-scale backbone. Its reported gains were concrete: on COCO, the proposal network's average recall at 1000 proposals rose from 48.3 to 56.3, a gain of 8.0 points, and small-object recall rose by 12.9 points. In detection, it raised the COCO average precision of Fast R-CNN from 31.9 to 33.9. The paper has been cited more than 29,000 times according to Semantic Scholar. Its main contribution was showing that a pyramid could come nearly free from the network the detector already had to run.

The problem

Objects in a photograph range from a few pixels to most of the frame. A detector has to find all of them with one fixed network.

The classic answer was a featurized image pyramid: shrink the photo several times, run the feature extractor on each copy, and detect on each one. This works, but the cost grows with the number of scales. It also makes training on every scale in one network impractical in memory, so the pyramid is often used only at test time, which creates a mismatch between training and testing.

Deep networks offer a cheaper route. A convolutional network shrinks its maps as it goes deeper, so its stages already produce maps at several resolutions. The problem is that the early maps are fine but semantically weak, and the late maps are coarse but semantically strong. Detectors that used one stage's map, or that attached heads to several stages without mixing them, suffered from that gap. The paper's question is how to make all the levels strong.

How it works

The pyramid is built from the backbone's own stages, using two paths and one kind of connection, a 1 by 1 convolution. Trace a one-dimensional toy first, where each map is a short row of numbers.

  1. Take two maps from the bottom-up path, the usual feed-forward pass. The coarse map is C=[1.0, 2.0]C = [1.0,\ 2.0], with two cells. The fine map is L=[0.5, −0.5, 1.0, 0.0]L = [0.5,\ -0.5,\ 1.0,\ 0.0], with four cells. Check: the fine map has twice as many cells, which matches the stride of two between stages.
  2. Start the top-down path at the coarse level. Its output is the coarse map itself, after a 1×11 \times 1 convolution, which here does nothing, so the top map is Mtop=[1.0, 2.0]M_{\text{top}} = [1.0,\ 2.0].
  3. Upsample the top map to the fine resolution by repeating each cell twice. That gives [1.0, 1.0, 2.0, 2.0][1.0,\ 1.0,\ 2.0,\ 2.0]. Check: four cells, the same values as before, each now covering two positions.
  4. Add the lateral map. The fine map LL passes through its own 1×11 \times 1 convolution to match the channel count, and then the two are added cell by cell: [1.0+0.5, 1.0−0.5, 2.0+1.0, 2.0+0.0]=[1.5, 0.5, 3.0, 2.0][1.0 + 0.5,\ 1.0 - 0.5,\ 2.0 + 1.0,\ 2.0 + 0.0] = [1.5,\ 0.5,\ 3.0,\ 2.0]. Check: each sum uses one cell from each input.
  5. The result is the fine-level pyramid map P=[1.5, 0.5, 3.0, 2.0]P = [1.5,\ 0.5,\ 3.0,\ 2.0]. It has the fine resolution, and each cell now carries the coarse map's meaning as well as its own location. A final 3×33 \times 3 convolution would smooth the upsampling artifacts, and the same steps repeat up the pyramid.

The structure is shown below. The bottom-up path is the network's normal forward pass. The top-down path reuses it in reverse, and the lateral arrows keep the precise positions.

flowchart TB
  subgraph BU["Bottom-up pathway"]
    C2[C2 stride 4] --> C3[C3 stride 8] --> C4[C4 stride 16] --> C5[C5 stride 32]
  end
  subgraph TD["Top-down pathway"]
    C5 --> P5[P5]
    P5 -->|upsample x2| P4[P4]
    P4 -->|upsample x2| P3[P3]
    P3 -->|upsample x2| P2[P2]
  end
  C4 -. lateral 1x1 .-> P4
  C3 -. lateral 1x1 .-> P3
  C2 -. lateral 1x1 .-> P2

Each level then gets its own detection head, and all the heads share parameters. Because every level has the same channel count and the same meaning, one head works at all scales, just as one classifier works on every copy of a featurized image pyramid.

The cost is small. The top-down path adds a few cheap convolutions and additions, and nothing has to be run again on a resized image. The extra cost is the few convolutions added to the network, so the paper reports only a small slowdown relative to the single-scale baseline.

The math

Definition

Definition: Feature Pyramid Network

Let {C2,C3,C4,C5}\{C_2, C_3, C_4, C_5\} be the outputs of the last residual block of each ResNet stage, with strides 4, 8, 16 and 32 pixels. A feature pyramid {P2,P3,P4,P5}\{P_2, P_3, P_4, P_5\} with a fixed channel count d=256d = 256 is defined by the top-down recursion

M5=conv⁡1×1(C5),Ml=conv⁡1×1(Cl)+up⁡2(Ml+1),l=4,3,2,M_5 = \operatorname{conv}_{1\times1}(C_5), \qquad M_l = \operatorname{conv}_{1\times1}(C_l) + \operatorname{up}_{2}(M_{l+1}), \quad l = 4, 3, 2,Pl=conv⁡3×3(Ml),l=2,3,4,5.P_l = \operatorname{conv}_{3\times3}(M_l), \qquad l = 2, 3, 4, 5.

Here up⁡2\operatorname{up}_2 doubles the spatial size by nearest-neighbour upsampling, and ++ is element-wise addition.

Read the recursion in words: start with the coarsest map, and at each level the output is the lateral map plus the upsampled output of the level above. The final 3×33 \times 3 convolution produces the map the heads use.

Step 2 in symbols: the top map

Step 2 had no upsampled input at the top, so M5M_5 is just the lateral map of C5C_5. In the toy, the 1×11 \times 1 convolution was the identity, so Mtop=C=[1.0, 2.0]M_{\text{top}} = C = [1.0,\ 2.0].

Step 3 in symbols: the upsampling

Nearest-neighbour upsampling by a factor of 2 maps a cell mjm_j to the two cells mjm_j and mjm_j at the finer level. For the toy, up⁡2([1.0, 2.0])=[1.0, 1.0, 2.0, 2.0]\operatorname{up}_2([1.0,\ 2.0]) = [1.0,\ 1.0,\ 2.0,\ 2.0].

Step 4 in symbols: the lateral merge

The merge is Ml=conv⁡1×1(Cl)+up⁡2(Ml+1)M_l = \operatorname{conv}_{1\times1}(C_l) + \operatorname{up}_{2}(M_{l+1}). For the toy this is [0.5, −0.5, 1.0, 0.0]+[1.0, 1.0, 2.0, 2.0]=[1.5, 0.5, 3.0, 2.0][0.5,\ -0.5,\ 1.0,\ 0.0] + [1.0,\ 1.0,\ 2.0,\ 2.0] = [1.5,\ 0.5,\ 3.0,\ 2.0]. The 1×11 \times 1 convolution matters in real networks, because ClC_l may have anywhere from 256 to 2048 channels in a ResNet while d=256d = 256. A 1×11 \times 1 convolution maps each spatial position's channel vector to 256 numbers, so the addition is defined.

Step 5 in symbols: anchors and heads on the pyramid

For region proposals, the paper gives each level one anchor size, with areas {322,642,1282,2562,5122}\{32^2, 64^2, 128^2, 256^2, 512^2\} on {P2,P3,P4,P5,P6}\{P_2, P_3, P_4, P_5, P_6\}. The level P6P_6 is a stride-two subsampling of P5P_5, added only to cover the largest anchor. Each anchor is labelled by its intersection over union with a ground-truth box: positive for the highest-overlap anchor of each box and for any overlap above 0.7, negative for overlaps below 0.3.

Assigning regions to levels

For region-based detection, each region of interest is assigned to a level by its size. For a region of width ww and height hh in the input image,

k=⌊k0+log⁡2 ⁣(wh224)⌋,k = \left\lfloor k_0 + \log_2\!\left(\frac{\sqrt{wh}}{224}\right) \right\rfloor,

with k0=4k_0 = 4, clamped to the levels 2 to 5. A region of 224×224224 \times 224 goes to P4P_4. A region of 112×112112 \times 112 has log⁡2(0.5)=−1\log_2(0.5) = -1, so k=3k = 3, and a region of 448×448448 \times 448 has log⁡2(2)=1\log_2(2) = 1, so k=5k = 5. Small regions use fine maps, and large regions use coarse maps.

Results

The paper reports its ablations on COCO, comparing each design with a single-scale baseline trained the same way.

Region proposals. The single-scale RPN on C4C_4 reached an average recall at 1000 proposals (AR at 1k) of 48.3. The full FPN reached 56.3, a gain of 8.0 points. Small-object recall went from 32.0 to 44.9, a gain of 12.9 points.

Ablations of the two paths. The authors compare variants with and without the top-down path and with and without the lateral connections. Their reading is that both the semantic enrichment and the precise locations are needed, and that removing either one costs accuracy.

Detection. Fast R-CNN with FPN reached 33.9 COCO average precision, against 31.9 for a ResNet baseline with the usual single-scale head.

Final model. With a ResNet-101 backbone the paper reports 36.2 average precision on the COCO test-dev split, which at the time was a single-model result above the competition entries it compared with. The authors also note that FPN can extend to instance-segmentation proposals.

Limits. The experiments use ResNet backbones and one main detector family, so the paper shows the design works there but does not test every architecture. The gains are reported on one benchmark, COCO, so the result should not be read as a general law for all detection tasks.

Reading guide

Read the paper in this order, with the lessons next to it.

  • The motivation. You need image pyramids for the featurized pyramid that FPN replaces, and Object Detection for the goal of finding boxes.
  • The method. You need Convolutional Neural Network for the stride and channel ideas. The walkthrough above traces the top-down merge, and the definition in the math section is the exact form.
  • The proposal and detection heads. You need Region Proposal Network and Anchor Box to follow the anchor sizes and labels, and the region-of-interest assignment rule from the math section.
  • The experiments. You need ResNet for the backbone and Faster R-CNN for the detector the ablations build on.
  • The U-Net family. U-Net is the related skip-connection design. It is safe to skip on a first read.

Check yourself

QuestionIn one sentence, what does the top-down path add to the bottom-up pyramid, and what do the lateral connections add on top of that?Show answer

The top-down path brings strong high-level meaning from the coarse maps down to the fine maps by upsampling and adding. The lateral connections add back the precise locations that the fine bottom-up maps still have, because the coarse maps lost them during downsampling.

QuestionIn the toy example, the coarse map is [1.0, 2.0][1.0,\ 2.0] and the lateral map is [0.5, −0.5, 1.0, 0.0][0.5,\ -0.5,\ 1.0,\ 0.0]. What is the merged map MM at the fine level, and why does the first cell read 1.5?Show answer

The coarse values are upsampled to [1.0, 1.0, 2.0, 2.0][1.0,\ 1.0,\ 2.0,\ 2.0], and the merged map is [1.5, 0.5, 3.0, 2.0][1.5,\ 0.5,\ 3.0,\ 2.0]. The first cell reads 1.5 because it adds the upsampled coarse value 1.01.0 to the lateral value 0.50.5 at the same position.

QuestionA region of interest is 448×448448 \times 448 pixels. Using the paper's rule with k0=4k_0 = 4, which pyramid level should it be assigned to, and why does that make sense?Show answer

The square root of the area is 448448, and log⁡2(448/224)=log⁡2(2)=1\log_2(448 / 224) = \log_2(2) = 1. So k=⌊4+1⌋=5k = \lfloor 4 + 1 \rfloor = 5, which is P5P_5. A large region spans many cells even on a coarse map, so it is read from a coarse level, where its size in cells stays manageable.

QuestionWhy would a top-down pyramid with no lateral connections hurt localization, even though its top-down path still carries strong meaning?Show answer

Each level of the top-down path has been downsampled and upsampled several times, so its positions are coarse, even though its meaning is strong. The lateral connections pass the precise positions from the fine bottom-up maps directly into the merged maps. Without them the detector knows what an object is at each level but has lost where its edges lie, so the proposals it scores are less accurate.

Sources

Read the full paper

Tsung-Yi Lin, Piotr Dollár, Ross Girshick et al., 2016. arXiv:1612.03144