Techniqueadvanced
Feature pyramid network
Also called FPN.
Build a pyramid of feature maps with strong semantics at every scale by a top-down path with lateral connections, and detect objects on each level.
A feature pyramid network (FPN) turns one convolutional network into a pyramid of feature maps, one for each scale, that all carry strong, high-level features. A classification network computes maps of falling resolution: the early maps are fine but carry low-level features such as edges, and the late maps carry the meaning of the image at a coarse stride. FPN adds a top-down path. It starts at the coarsest map, upsamples it by 2 again and again, and at each step adds the map of the same size from the bottom-up path through a convolution, the lateral connection. The result is a map at each stride, 4 to 32 pixels for to , that is both fine and semantic. A detector then works on each level with one shared head: small objects on the fine levels, large ones on the coarse levels. With Faster R-CNN it raised the COCO results of single models at little extra cost, and it is the backbone of Mask R-CNN, RetinaNet and most later detectors.
In plain words
A detector must find both small and large objects. The old answer was to shrink the photo several times and run the detector on each copy, an image pyramid, which is slow. A network already makes maps at several sizes inside, but the big early maps know only about edges and colours, while the small late maps know about objects but are too coarse to place small things. FPN fixes this by passing the meaning back down. It takes the small late map, makes it twice as large, and adds the matching earlier map to it. It repeats this down to the largest map. Every map in the result now knows about objects and is sharp at its own size. Small objects are found on the large maps and large objects on the small maps.
When it applies
The technique needs a backbone network with stages of stride , such as a ResNet with outputs at strides 4, 8, 16 and 32. It applies to any task that has to find things over a wide range of sizes in one image: object detection, instance segmentation, semantic and panoptic segmentation, and keypoint detection. The upsampling by 2 needs the map sizes of the levels to differ by a factor of exactly 2, so the input is padded to a multiple of the largest stride. FPN is a part of the network and is trained with it; it is not a separate algorithm that runs on a fixed network.
The template
FPN(C_2, ..., C_5) ▷ C_l has stride 2^l, any number of channels- 1
P_5 ← conv1×1(C_5) to d channels - 2
for l = 4 down to 2 - 3
P_l ← UPSAMPLE2(P_{l+1}) + conv1×1(C_l) ▷ nearest neighbor upsampling by 2 - 4
for l = 2, ..., 5: P_l ← conv3×3(P_l) ▷ reduces the aliasing of the upsampling - 5
P_6 ← subsample P_5 by 2 ▷ only for the proposal stage - 6
apply one head with shared weights to every level P_l - 7
for a region of interest of size w × h, pool it from P_k with k = clamp(⌊4 + log2(√(wh) / 224)⌋, 2, 5)
All levels have the same number of channels, in the paper, so that one head with shared weights fits on every level. The lateral and output convolutions are plain linear layers; the paper reports that adding nonlinearities to them made little difference.
Anchors on the levels. For the region proposal network, the paper puts anchors of one area on each level, on to , each with the ratios 1:2, 1:1 and 2:1, so 15 anchor shapes in all and 3 per position. The labels follow the IoU rule of Faster R-CNN, now over the anchors of all levels together.
Region to level (line L7). For the second stage, an RoI of size in image pixels is pooled from level with . The constant 224 is the input size of ImageNet pretraining, so an RoI of that size goes to , the level of stride 16 that single-scale Faster R-CNN used. The level drops by one each time the side halves. The paper's formula has no clamp; implementations clamp to the levels that exist.
Classic examples
- Faster R-CNN with FPN. The RPN works on to and the second stage pools from to by the rule of line L7. The paper reports COCO test-dev AP 36.2 with ResNet-101 for a single model.
- Mask R-CNN. Mask R-CNN uses the same FPN and the same level rule for its box and mask heads, with RoIAlign in place of RoI pooling.
- RetinaNet. The one-stage detector of the focal loss paper uses levels to and 9 anchors per position, with one classification and one box head shared across the levels.
- Segmentation heads. Panoptic FPN merges all levels into one map at stride 4 for semantic segmentation. Encoder-decoder networks such as U-Net have the same shape of top-down path with skip connections, but predict only on the finest level.
Variations
- No top-down path. The single shot multibox detector predicts on the maps of the bottom-up path directly and adds new coarser layers on top. The FPN paper notes that it does not use the earlier maps of higher resolution, which matter for small objects.
- Bottom-up path again. PANet adds a second bottom-up path after the top-down one, so that fine localization reaches the coarse levels by a short path.
- Weighted and repeated merging. BiFPN of EfficientDet repeats top-down and bottom-up merging several times and learns a weight for each input of a sum. NAS-FPN finds the connections by architecture search.
- Merge by concatenation. Some detectors, such as YOLOv3, concatenate the upsampled map with the lateral map instead of adding them.
- Image pyramid of features. Featurized image pyramids run the whole network on each scale of an image pyramid; they are more accurate in some settings but several times slower, and FPN aims to get most of the gain at the cost of one pass.
Pitfalls
- Map sizes that do not match. With an input side that is not a multiple of 32, a stride-2 stage rounds and the upsampled map is one cell larger or smaller than the lateral map. Pad the input or crop the upsampled map.
- No convolution after the merge. Nearest neighbor upsampling repeats each value in a block; the paper adds the convolution to reduce this aliasing.
- Different channel counts. A shared head needs the same on every level; the lateral convolutions exist for this as much as for mixing.
- Level rule without a clamp. For an RoI of side 32 the formula gives , a level that does not exist. Clamp to the levels of the network.
- Anchors on the wrong level. The anchor size of a level should match the stride of the level; one anchor size per level with 3 shapes is what the paper uses, and more scales per level, as in RetinaNet, are a separate choice.
- Cost of the finest level. has 16 times the cells of ; heads that are heavy per cell, such as dense one-stage heads, often start at .
Exercises
- An RoI is pixels. Which level does the rule of line L7 choose? Answer: , so , the level of stride 8.
- An RoI is . Which level? Answer: , , so .
- An RoI is . Answer: , , so ; a slightly larger RoI of gives exactly .
- Show that nearest neighbor upsampling by 2 followed by a average pooling of stride 2 gives back the original map, and that the reverse order does not. Answer: each block after upsampling holds four copies of one value, whose mean is that value; average pooling first loses the differences inside each block, which upsampling cannot restore.
- A ResNet input of pixels gives which sizes of to ? Answer: , , , and , where subsamples with stride 2 and rounds up.
- How many anchors does the RPN of the paper place on an input? Answer: 3 per position on each level, so .
References
- Tsung-Yi Lin, Piotr Dollar, Ross Girshick, Kaiming He, Bharath Hariharan and Serge Belongie, Feature pyramid networks for object detection, CVPR 2017, Section 3, Feature pyramid networks (bottom-up pathway, top-down pathway with nearest neighbor upsampling by 2, 1 x 1 lateral connections, a 3 x 3 convolution on each merged map, d = 256); Section 4.1, FPN for RPN (one anchor area from 32^2 to 512^2 on P2 to P6, 3 ratios, 15 anchors, P6 by subsampling P5); Section 4.2, FPN for Fast R-CNN (Eq. 1, the level k = floor(k0 + log2(sqrt(wh)/224)) with k0 = 4); Section 5, Experiments (COCO test-dev AP 36.2 with ResNet-101)
- Tsung-Yi Lin, Piotr Dollar, Ross Girshick, Kaiming He, Bharath Hariharan and Serge Belongie, Feature pyramid networks for object detection, arXiv 1612.03144, the same sections
- Tsung-Yi Lin, Priya Goyal, Ross Girshick, Kaiming He and Piotr Dollar, Focal loss for dense object detection, ICCV 2017 (arXiv 1708.02002), Section 4, RetinaNet detector (an FPN with levels P3 to P7 as the backbone of a one-stage detector)
- Shaoqing Ren, Kaiming He, Ross Girshick and Jian Sun, Faster R-CNN: towards real-time object detection with region proposal networks, IEEE Transactions on Pattern Analysis and Machine Intelligence 39(6), 2017, 1137-1149, Section 3.1.1, Anchors (the single-scale feature map with multi-scale anchors that FPN replaces)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag SWG7ZE Edit this page History Report an error Markdown