Computer Vision Lab Algorithms The feature pyramid (FPN)
The feature pyramid (FPN)
It builds a pyramid of semantically strong feature maps at all resolutions with a top-down path and lateral connections.
This content was prepared automatically from documented sources and its human scientific review is not yet complete. If you find an error, let us know.
Mathematical formula
P_\ell = \mathrm{Conv}_{3\times3}\big(\mathrm{Conv}_{1\times1}(C_\ell) + \mathrm{Up}_{2}(P_{\ell+1})\big)Explanation
Deep layers are semantically rich but low-resolution, and shallow ones are high-resolution but semantically weak. FPN upsamples the deep map ×2 and adds it to the shallower map after a 1×1 convolution, then a 3×3 convolution reduces the effect of upsampling. The result is 256-channel features at every level, on each of which objects of a suitable size are detected.
Detailed explanation
Intuition
Objects appear at very different sizes. The old solution was to build a pyramid of images at different resolutions and pass each one through the network, which is costly. FPN exploits the natural pyramid inside the network itself (the ResNet stages), and fixes its weakness: shallow layers are precise but semantically poor. So a top-down path is added that carries semantics to all levels.
How it works step by step
- The bottom-up path: the backbone stages
C_2,\dots,C_5with strides of 4, 8, 16 and 32. - Lateral connections: a 1×1 convolution to unify the channels to 256.
- The top-down path: upsample
P_{\ell+1}×2 (nearest neighbour) and add it to the lateral connection. - A 3×3 convolution on each result to reduce the effect of upsampling.
- Assign each object or region to a level according to its size.
Mathematical formulation
P_\ell = \mathrm{Conv}_{3\times3}\Big(\mathrm{Conv}_{1\times1}(C_\ell) + \mathrm{Up}_{2}(P_{\ell+1})\Big),\qquad k = \big\lfloor 4 + \log_2(\sqrt{wh}/224)\big\rfloorComputational complexity
A modest addition to compute compared with the backbone, but it enables detection on high-resolution maps.
Advantages
- A large improvement for small objects.
- A general, near-standard component in detectors and segmentation.
Limitations
- Extra memory for the high-resolution levels.
- One-directional fusion; PANet and BiFPN added extra paths.
When do you use it?
In almost every multi-scale detector or segmentation model.
Code example (PyTorch)
from torchvision.ops import FeaturePyramidNetwork
fpn = FeaturePyramidNetwork([256, 512, 1024, 2048], 256)Applications
Most modern detectors: Faster/Mask R-CNN, RetinaNet, FCOS, and multi-scale segmentation.
Limitations
Extra memory and compute on the high-resolution levels.
References
- T.-Y. Lin, P. Dollár, R. Girshick, K. He, B. Hariharan, S. Belongie (2016).Feature Pyramid Networks for Object Detection. arXiv:1612.03144 (CVPR 2017). doi:10.48550/arXiv.1612.03144
