Paper commentary
PVT v2: Improved Baselines with Pyramid Vision Transformer
- Problem PVT v1 is costly at high input resolution, cuts images into non-overlapping patches and relies on a fixed-size position encoding, which limits its performance on vision tasks.
- Method Adds linear spatial reduction attention, overlapping patch embedding and a zero-padded depth-wise convolution in the feed-forward layer to PVT v1, then scales the result into six variants, B0 to B5.
- Results Reached 83.8 top-1 accuracy on ImageNet-1K with PVT v2-B5, and 46.1 AP with RetinaNet 1x using PVT v2-B4.
![Figure 4: Models’ GFLOPs under different input scales.
The growth rate of GFLOPs: ViT-Small/16 [8] >ViT-
Small/32 [8] >PVT v1-Small [33] >ResNet50 [14] >PVT
v2…](/papers/8488fb84-a671-4efb-b62f-a19ce6ddfa07/figures/figure-61ca6c3ac8dd5d1dd00e1dc7535719f5.png?thumb=512)
Figure 4 : Models’ GFLOPs under different input scales. The growth rate of GFLOPs: ViT-Small/16 [8] >ViT- Small/32 [8] >PVT v1-Small [33] >ResNet50 [14] >PVT v2-B2-Li (ours).
Original paper · CC BY 4.0 · Wenhai Wang, Enze Xie, Xiang Li, Deng-Ping Fan, Kaitao Song, Ding Liang, Tong Lu, Ping Luo, Ling Shao · PVT v2: Improved Baselines with Pyramid Vision Transformer · Original paper figure · Extracted the figure area from page 7 of the original PDF.Why PVT v1 needed changes
PVT v1 is a hierarchical pure Transformer backbone with four stages, and it showed that such a backbone can be as versatile as CNN counterparts and perform better on detection and segmentation. The authors name three limitations that the new work sets out to address. The second is that PVT v1 cuts an image into non-overlapping patches, which loses some of the local continuity of the image.
The third is a fixed-size position encoding, which makes it inflexible for images of arbitrary size.
These three issues are framed as limits on what PVT v1 can achieve on vision tasks, so the changes target the backbone itself rather than a particular detector or head. The authors report that the three changes are orthogonal to the PVT v1 framework, so each can be added to it without redesigning the framework.
Three changes, each tied to one limit
The three changes answer the three limits in turn. Linear spatial reduction attention lowers the cost of attention, overlapping patch embedding restores local continuity at the tokenization step, and the convolutional feed-forward network adds zero-padding position information so that the fixed-size position encoding can be dropped.
The overlapping patch embedding appears at the start of every stage of the pyramid. The overall pyramid, in which channel width grows and spatial resolution shrinks with depth, is kept from PVT v1.
The cumulative ablation adds the changes one after another, so the effect shown in each row has to be read against the row above it.
How linear SRA reduces attention cost
In PVT v1, SRA uses convolutions for spatial reduction, with the reduction ratio R setting how much the spatial grid is reduced. Linear SRA replaces that convolution with average pooling, which brings the spatial grid of the feature map down to a fixed P by P size before attention is computed. Because the pooled grid has a fixed size, the cost of this attention grows with the number of input positions rather than with the square of that number.
For an input of size h × w × c, the authors write the cost of SRA as follows. \[ \Omega(\text{SRA}) = 2h^2w^2cR^2 + hwc^2R^2 \] The cost of linear SRA is written as follows. \[ \Omega(\text{Linear SRA}) = 2hwP^2c \] In the SRA expression the h^2 w^2 term grows fastest as the input grows, while the linear SRA expression depends only on the number of positions hw, the channel count c and the pooled size P.
In the paper P is the pooling size of linear SRA and is set to 7, while R is the spatial reduction ratio of SRA. These formulas are the authors' accounting of attention cost; the measured GFLOPs are reported separately in the ablation and in the input-scale analysis.
Overlapping patches and zero-padded convolution
Overlapping patch embedding enlarges each patch window so that neighbouring windows share about half of their area, and the feature map is padded with zeros to keep its resolution. In practice it is a convolution with stride S, kernel size 2S − 1, padding S − 1 and c′ kernels, so the stride controls how far the token grid is downsampled. Table 1 sets the stride to 4 in stage 1 and to 2 in stages 2, 3 and 4.
The convolutional feed-forward network inserts a 3 × 3 depth-wise convolution with padding 1 between the first fully connected layer and the GELU activation. This convolution is where the fixed-size position encoding of ViT is dropped and zero padding supplies the position information instead. The GELU is the activation used by the layer; the convolution is a separate operation that sits in front of it.
The authors link the two zero-padded layers to variable-resolution input: because overlapping patch embedding and the convolutional feed-forward network carry positional information, the fixed-size embedding of PVT v1 is no longer needed. The experiments measure accuracy and detection AP with these layers in place, and they do not separately isolate the flexibility to changing input sizes.
The B0 to B5 family
PVT v2 comes in six sizes, B0 to B5, which differ in parameter count. The variants are produced by changing hyper-parameters rather than the design itself. The hyper-parameters are the stride Si, the output channels Ci, the number of encoder layers Li, the SRA reduction ratio Ri, the pooling size Pi, the head number Ni and the feed-forward expansion ratio Ei for each stage i.
Table 1 lists these settings for each variant, and the -Li suffix marks the version that uses linear SRA. The authors base the scaling on the ResNet pattern, in which the channel dimension increases and the spatial resolution shrinks as the layers go deeper, and they note that stage 3 carries most of the computation.
ImageNet-1K classification results
The authors trained every model on the training set so that the comparison is fair.
The text gives this gap as 3.6%, which is a difference of 3.6 points in top-1 accuracy.
The text describes this as 1.9% higher, which is the same 1.9-point difference.
The text gives the gap to Swin Transformer as 0.5 points. The introduction labels the same 83.8 figure as top-1 error, whereas the classification table and text read it as top-1 accuracy, so the reading here follows the table.
The authors describe PVT v2 as the state-of-the-art method on ImageNet-1K among the models in this comparison.
COCO detection against PVT v1
Detectors are trained on COCO train2017, which has 118k images, and evaluated on val2017, which has 5k images. The reported detection results use the 1x schedule of 12 epochs, a shorter image side of 800 pixels with a longer side of at most 1,333, a batch size of 16 on 8 V100 GPUs and AdamW with an initial learning rate of 1 × 10−4.
With RetinaNet, PVT v2-B4 reaches 46.1 AP against 42.6 for PVTv1-Large, which is 3.5 AP higher. The smaller pairs follow the same pattern: PVT v2-B2 reaches 44.6 AP against 40.4 for PVTv1-Small, and PVT v2-B1 reaches 41.2 AP against 36.7 for PVTv1-Tiny.
With Mask R-CNN under the same 1x setting, PVT v2-B4 reaches 47.5 APb against 42.9 APb for PVTv1-Large, which is 4.6 APb higher.
Comparison with Swin Transformer on COCO
The comparison keeps all settings the same as for Swin Transformer, including ImageNet-1K pre-training and the COCO fine-tuning strategy. It covers Cascade R-CNN, ATSS, GFL and Sparse R-CNN, and the GFLOPs in the table are computed at an input scale of 1280 by 800.
Under ATSS, PVT v2-B2 reaches 49.9 AP against 47.2 AP for Swin-T, which is 2.7 AP higher. The parameters are 33 M for PVT v2-B2 and 36 M for Swin-T, and the GFLOPs are 258 for PVT v2-B2 and 215 for Swin-T, so the text's description of similar cost holds for parameters but the table shows more computation for PVT v2-B2.
With GFL, PVT v2-B2 reaches 50.2 AP against 47.6 AP for Swin-T. With Cascade Mask R-CNN, PVT v2-B2 reaches 51.1 APb against 50.5 APb for Swin-T, and with Sparse R-CNN it reaches 50.1 AP against 47.9 AP.
The -Li variant trades a little accuracy for lower cost: on ATSS, PVT v2-B2-Li reaches 48.9 AP with 194 GFLOPs, against 49.9 AP with 258 GFLOPs for PVT v2-B2. The authors describe this as giving up a little performance for the reduction in computation.
Semantic segmentation on ADE20K
Semantic FPN is trained on ADE20K with the backbone initialized from ImageNet weights and the new layers initialized with Xavier, using AdamW with an initial learning rate of 1e-4 for 40k iterations at batch size 16 on 4 V100 GPUs. The learning rate follows a polynomial decay with power 0.9, training crops are 512 by 512, and test images are rescaled to a shorter side of 512 pixels.
PVT v2-B0 reaches 37.2 mIoU against 32.9 for ResNet18 and 35.7 for PVTv1-Tiny. PVT v2-B5 reaches 48.7 mIoU with 91.1 GFLOPs, above the 40.2 mIoU of ResNeXt101-64x4d, which has 103.9 GFLOPs.
The mIoU of PVT v2-B1, B2, B3 and B4 is above that of the PVT v1 counterpart at the same size: 42.5 against 35.7, 45.2 against 39.8, 47.3 against 41.6 and 47.9 against 42.1.
What each design contributes
The first row is PVT v1-Small, which reaches 79.8 top-1 accuracy and 40.4 AP with RetinaNet 1x, at 285.8 GFLOPs. Adding overlapping patch embedding raises top-1 accuracy to 81.1 and AP to 42.2, with GFLOPs moving from 285.8 to 288.6. The authors attribute the gain to overlapping patch embedding modelling local continuity of the image and feature map through the overlapping sliding window.
Adding the convolutional feed-forward network on top gives PVT v2-B2 at 82.0 top-1 accuracy and 44.6 AP, which is 0.9 points and 2.4 points above the overlapping-patch row. Its GFLOPs are 290.7 and its parameter count is 35.1 M, against 288.6 GFLOPs and 34.9 M for the row before.
Replacing SRA with linear SRA gives PVT v2-B2-Li 82.1 top-1 accuracy against 82.0, but its AP is 43.6 against 44.6. GFLOPs fall from 290.7 to 227.4, which the text gives as a 22% reduction, and the parameter count falls from 35.1 M to 32.3 M.
Each row adds one design to the previous row, so the table shows a sequence of cumulative steps and not the effect of each design removed alone. Within that sequence, the authors' statement that all three designs improve performance, parameter number or computation holds for the steps shown.
GFLOPs across input scales
Figure 4 plots GFLOPs against input scale for ViT-Small/16, ViT-Small/32, PVT v1-Small, ResNet50 and PVT v2-B2-Li. The caption orders the growth rates from fastest to slowest as ViT-Small/16, ViT-Small/32, PVT v1-Small, ResNet50 and PVT v2-B2-Li.
The authors state that the GFLOPs of PVT v2-B2-Li grow much more slowly than those of PVT v1-Small and at a rate similar to ResNet50, and they read this as addressing the high computational overhead caused by the attention layer. The figure shows GFLOPs only, so accuracy at these input scales is not plotted.
Limitations
The setup also describes a 3x schedule of 36 epochs, but no 3x result appears in the detection tables shown.
The ablation starts from PVT v1-Small and reports only ImageNet-1K top-1 accuracy and RetinaNet 1x AP on COCO.
The segmentation text attaches the 48.7 mIoU figure to PVT-Large, whereas Table 5 lists it for PVT v2-B5. The introduction calls the 83.8 figure a top-1 error, whereas Table 2 gives it as top-1 accuracy.
The Swin Transformer comparison lists 258 GFLOPs for PVT v2-B2 on ATSS against 215 for Swin-T, and the text describes the cost as similar. The input-scale analysis covers GFLOPs for five models and reports no accuracy at different input sizes, so the flexibility to variable-resolution input rests on the design argument.
Paper info
- Authors
- Wenhai Wang, Enze Xie, Xiang Li, Deng-Ping Fan, Kaitao Song, Ding Liang, Tong Lu, Ping Luo, Ling Shao
- Venue
- arXiv · Preprint
- First published
- 2021-6-25
- Added
- 2026-11-6
- Updated
- 2023-4-17
- Version
- v7
- arXiv
- 2106.13797
- DOI
- 10.1007/s41095-022-0274-8
- Category
- cs.CV
- Original paper terms
- CC BY 4.0
- What we show
- Paper info, commentary and permitted figures from the original paper
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Abstract
Transformer recently has presented encouraging progress in computer vision. In this work, we present new baselines by improving the original Pyramid Vision Transformer (PVT v1) by adding three designs, including (1) linear complexity attention layer, (2) overlapping patch embedding, and (3) convolutional feed-forward network. With these modifications, PVT v2 reduces the computational complexity of PVT v1 to linear and achieves significant improvements on fundamental vision tasks such as classification, detection, and segmentation. Notably, the proposed PVT v2 achieves comparable or better performances than recent works such as Swin Transformer. We hope this work will facilitate state-of-the-art Transformer researches in computer vision. Code is available at https://github.com/whai362/PVT.
Quote from the paper
Wenhai Wang, Enze Xie, Xiang Li, Deng-Ping Fan, Kaitao Song, Ding Liang, Tong Lu, Ping Luo, Ling Shao (2021). PVT v2: Improved Baselines with Pyramid Vision Transformer. arXiv:2106.13797v7. https://doi.org/10.1007/s41095-022-0274-8
BibTeX
@article{wang2021improved,
title = {{PVT v2: Improved Baselines with Pyramid Vision Transformer}},
author = {Wenhai Wang and Enze Xie and Xiang Li and Deng-Ping Fan and Kaitao Song and Ding Liang and Tong Lu and Ping Luo and Ling Shao},
year = {2021},
eprint = {2106.13797},
archivePrefix = {arXiv},
doi = {10.1007/s41095-022-0274-8},
url = {https://arxiv.org/abs/2106.13797v7}
}