wikillm

Paper · 2021-06-25 · cs.CV

PVT v2: Improved Baselines with Pyramid Vision Transformer

PVT v2 upgrades the Pyramid Vision Transformer backbone with three changes: attention whose keys and values are average-pooled to a fixed 7x7 grid (linear cost), overlapping patch embedding, and a 3x3 depthwise conv inside the feed-forward block. B5 reaches 83.8% ImageNet top-1 and B4 reaches 46.1 RetinaNet AP on COCO (author-reported).

Vision Transformer (ViT) backbonesEfficient vision backbonesObject detectionSemantic segmentationvision-backbonetransformerattentiondense-predictionimage-classificationobject-detectionsemantic-segmentation

arXivPDFCodeMarkdown19 min read

AI-compiled by claude-haiku-5-5 on 2026-10-24, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

Vision transformers cut an image into patches and let every patch look at every other patch. That works well, but the cost grows quickly with the image size, and the original pyramid version of this idea cut the image into patches that never touch each other. This paper keeps the same pyramid design and fixes three things.

First, the expensive "every patch looks at every patch" step is made cheap by first squeezing the patch grid down to a small fixed-size summary, so the work grows in step with the image instead of with its square. Second, the patches are cut so that neighbours overlap, which keeps local detail that hard cuts lose. Third, a small local filter is added inside the block that processes each token, which gives the network a sense of position without a fixed position table.

The authors present the result as a stronger set of baselines rather than a new idea. It improves image classification and the detection and segmentation tasks built on top of the backbone, and it is meant to be a reference point for later work on vision transformers.

TL;DR

PVT v2 is a four-stage pyramid vision transformer backbone. It changes the attention to pool keys and values to a 7x7 grid, which makes its cost linear in the number of image tokens §3.2 eq. 2, uses overlapping patch embedding §3.3, and adds a 3x3 depthwise convolution in the feed-forward block §3.4. Author-reported results include 83.8% ImageNet-1K top-1 for the largest model tab. 2 and 46.1 RetinaNet AP on COCO tab. 3. Use it when you need a transformer backbone for dense prediction; check the Pitfalls section before reproducing the training recipe.

Problem

PVT v1 has three limits, according to the authors §3.1:

  • Its cost is high on high-resolution input, such as images whose shorter side is 800 pixels §3.1.
  • It splits the image into non-overlapping patches, which loses some local continuity §3.1.
  • Its position encoding has a fixed size, which does not suit inputs of other sizes §3.1.

The authors keep PVT v1's four-stage pyramid and fix these three limits §3.1. They state that the three changes are orthogonal to the PVT v1 framework §1.

Method

The network has four stages. Each stage starts with an overlapping patch embedding that downsamples the feature map by a stride S, followed by L encoder blocks. Resolution shrinks and channel count grows with depth, as in a ResNet §3.5. Stage 3 holds most of the computation §3.5.

Attention: linear spatial reduction (linear SRA). In PVT v1 the keys and values are shrunk by a strided convolution with ratio R. Here they are shrunk by average pooling to a fixed P x P grid, with P = 7 in all stages §3.2. The complexity of the original SRA is given by eq. 1 and that of linear SRA by eq. 2, with h x w x c the input size, R the reduction ratio and P the pool size §3.2. The attention cost no longer depends on the square of the image size. The queries still use every token pvt_v2.py.

\Omega(\mathrm{SRA}) = \frac{2h^2w^2c}{R^2} + hwc^2R^2 eq. 1

\Omega(\mathrm{Linear\ SRA}) = 2hwP^2c eq. 2

Overlapping patch embedding. Adjacent patches overlap by half their area, and the map is padded with zeros so that the resolution is kept §3.3. The authors implement this as a convolution with stride S, kernel size 2S-1 and padding S-1, producing an output of h/S x w/S §3.3. Stage 1 uses S = 4 and stages 2 to 4 use S = 2. The released code uses kernel 7 with stride 4 and padding 3 in stage 1, and kernel 3 with stride 2 and padding 1 in later stages pvt_v2.py pvt_v2.py.

Convolutional feed-forward network (CFFN). A 3x3 depthwise convolution with padding 1 sits between the first fully connected layer and the GELU of the feed-forward block §3.4 fig. 2. The authors use it to replace the fixed position encoding of PVT v1, since zero padding gives the network positional information §3.4.

Scaling. The series B0 to B5 changes the stage widths, the feed-forward expansion ratios (B5 uses 4 everywhere) and the depths; head counts and the reduction ratios are the same across variants §3.5 tab. 1. The linear variant B2-Li swaps the reduction ratio for the pooling size P tab. 1. The code builds the same variants with the same numbers [code: classification/pvt_v2.py#L329-L401].

Pseudocode. The paper gives no algorithm box. The sketch below follows the text and the released code. Lines marked as code-only are not described in the text.

Pseudocode
# Overlapping patch embedding, the downsampling step between stages  [§3.3]
# Input:  feature map (B, C_in, H, W); stride S
# Output: tokens (B, N, C) and the new size height_out, width_out
def overlap_patch_embed(feature_map, stride, out_dim):
    # Kernel 2S-1 and padding S-1, so neighbouring patches overlap  [§3.3]
    # [code: classification/pvt_v2.py#L185-L186]
    projected = conv2d(
        feature_map, out_dim, kernel=2 * stride - 1,
        stride=stride, padding=stride - 1,
    )
    height_out, width_out = projected.shape[-2:]  # ceil(H/S), ceil(W/S)
    tokens = flatten_to_tokens(projected)  # (B, N, C)
    return layer_norm(tokens), height_out, width_out
Pseudocode
# Linear spatial reduction attention  [§3.2] [eq. 2]
# Keys and values come from a fixed P x P grid, so their count is P^2 = 49
def linear_sra(tokens, height, width):
    # Put the tokens back on their grid  [code: classification/pvt_v2.py#L111]
    grid = to_grid(tokens, height, width)  # (B, C, H, W)
    # Average-pool to P x P, with P = 7  [§3.2]
    # [code: classification/pvt_v2.py#L77]
    pooled = adaptive_avg_pool(grid, output_size=7)  # (B, C, 7, 7)
    # Code only, not in the text: 1x1 conv, LayerNorm, GELU
    # [code: classification/pvt_v2.py#L78-L80]
    reduced = gelu(layer_norm(conv1x1(pooled)))  # (B, C, 7, 7)
    summary = flatten_to_tokens(reduced)  # (B, 49, C)
    # Queries use all N tokens; keys and values use the 49 summary tokens
    # [§3.2]
    queries = linear_q(tokens)  # (B, N, C)
    keys_values = linear_kv(summary)  # (B, 49, 2C)
    return multi_head_attention(queries, keys_values)  # scale = head_dim^-0.5
Pseudocode
# Convolutional feed-forward network  [§3.4]
# Input:  tokens (B, N, C); height and width of the grid
# Output: tokens (B, N, C)
def conv_ffn(tokens, height, width, linear_variant):
    # Expand the width with the first linear layer  [tab. 1]
    # [code: classification/pvt_v2.py#L43]
    hidden = fc1(tokens)  # (B, N, E*C)
    # Code only, linear variants (B2-Li): ReLU after fc1
    # [code: classification/pvt_v2.py#L44-L45]
    if linear_variant:
        hidden = relu(hidden)
    # 3x3 depthwise conv, padding 1, gives local continuity and position
    # [§3.4]
    hidden = depthwise_conv3x3(to_grid(hidden, height, width))
    hidden = flatten_to_tokens(hidden)
    # GELU, then the second linear layer  [§3.4]
    # [code: classification/pvt_v2.py#L47-L49]
    return fc2(gelu(hidden))
Pseudocode
# One encoder block, residual  [§3.2] [§3.4]
# Shown for linear variants. Other variants use the strided-conv SRA with
# ratio R instead  [§3.2] [eq. 1] [code: classification/pvt_v2.py#L72-L75]
# Code only: pre-norm residual layout
# [code: classification/pvt_v2.py#L163-L164]
def encoder_block(tokens, height, width, linear_variant):
    # Attention branch with the residual connection  [§3.2]
    tokens = tokens + linear_sra(layer_norm(tokens), height, width)
    # Feed-forward branch with the residual connection  [§3.4]
    tokens = tokens + conv_ffn(
        layer_norm(tokens), height, width, linear_variant,
    )
    return tokens

Stochastic depth is applied to both residual branches in the code; the paper does not describe it. See the Hyperparameters section for the rates.

Hyperparameters

Architecture (the same numbers for all tasks). Each cell gives C (channels), R (SRA reduction ratio), P (pool size for linear SRA), N (heads), E (FFN expansion ratio) and L (blocks). Stride S is 4 in stage 1 and 2 in stages 2 to 4 for every variant tab. 1.

StageB0B1B2B2-LiB3B4B5
1 (H/4)C 32, R 8, N 1, E 8, L 2C 64, R 8, N 1, E 8, L 2C 64, R 8, N 1, E 8, L 3C 64, P 7, N 1, E 8, L 3C 64, R 8, N 1, E 8, L 3C 64, R 8, N 1, E 8, L 3C 64, R 8, N 1, E 4, L 3
2 (H/8)C 64, R 4, N 2, E 8, L 2C 128, R 4, N 2, E 8, L 2C 128, R 4, N 2, E 8, L 3C 128, P 7, N 2, E 8, L 3C 128, R 4, N 2, E 8, L 3C 128, R 4, N 2, E 8, L 8C 128, R 4, N 2, E 4, L 6
3 (H/16)C 160, R 2, N 5, E 4, L 2C 320, R 2, N 5, E 4, L 2C 320, R 2, N 5, E 4, L 6C 320, P 7, N 5, E 4, L 6C 320, R 2, N 5, E 4, L 18C 320, R 2, N 5, E 4, L 27C 320, R 2, N 5, E 4, L 40
4 (H/32)C 256, R 1, N 8, E 4, L 2C 512, R 1, N 8, E 4, L 2C 512, R 1, N 8, E 4, L 3C 512, P 7, N 8, E 4, L 3C 512, R 1, N 8, E 4, L 3C 512, R 1, N 8, E 4, L 3C 512, R 1, N 8, E 4, L 3

Source: tab. 1. The code uses the same stage widths, heads and ratios pvt_v2.py. Depths differ for stage 2 of B2, B2-Li and B3; see Paper vs code.

Other architecture values:

NameValueWhereNotes
Overlap patch kernel / stride / padding, stage 17 / 4 / 3§3.3 pvt_v2.pykernel 2S-1, padding S-1 per the text
Overlap patch kernel / stride / padding, stages 2-43 / 2 / 1§3.3 pvt_v2.py
Linear SRA pool size P7§3.2 pvt_v2.pyfixed in all stages
Attention biasqkv bias onpvt_v2.pypaper not stated; code uses qkv_bias=True
LayerNorm epsilon1e-6 in the model constructorspvt_v2.pypaper not stated; the patch-embedding norm uses the PyTorch default
Headglobal mean over tokens, then one linear layerpvt_v2.pypaper not stated; no class token
Dropoutnot stated; code default 0.0main.py
Weight inittruncated normal, std 0.02 for linear layerspvt_v2.pypaper not stated

Classification training on ImageNet-1K §4.1:

NameValueWhereNotes
Epochs300§4.1 main.pyfrom scratch
Batch size128§4.1 main.pythe code's batch is per process; see Pitfalls
Hardware8 V100 GPUs§4.1
OptimizerAdamW, momentum 0.9§4.1beta2 and epsilon not stated; code epsilon 1e-8 main.py
Initial learning rate1e-3§4.1code default is 5e-4, scaled by batch x GPUs / 512 main.py main.py
Weight decay5e-2§4.1 main.pysame value in code
Schedulecosine§4.1 main.py
Warmup5 epochs, from 1e-6main.pypaper not stated
Minimum learning rate1e-5main.pypaper not stated
Stochastic depth0.1 for B0, B1, B2 and B2-Li; 0.3 for B3, B4 and B5pvt_v2_b2.py pvt_v2_b3.py pvt_v2_b5.pypaper not stated
Gradient clippingnone for B0, B1, B2 and B2-Li; norm 1.0 for B3, B4 and B5pvt_v2_b3.py pvt_v2_b5.pypaper not stated
Random crop, horizontal flipyes§4.1
Label smoothing0.1main.pypaper names it, value not stated
Mixup / CutMixalpha 0.8 / 1.0; switch probability 0.5; applied with probability 1.0main.pypaper names mixup only; CutMix not mentioned
Random erasingprobability 0.25, pixel mode§4.1 main.py
AutoAugment-style policyrand-m9-mstd0.5-inc1; colour jitter 0.4main.pynot in the paper
Repeated augmentation sampleron by defaultmain.py main.pynot in the paper
Evaluationresize shorter side to 256, centre-crop 224§4.1 datasets.pypaper states only the 224 crop

Object detection on COCO §4.2:

NameValueWhereNotes
Datatrain2017 (118k images), evaluate on val2017 (5k)§4.2
Backbone initImageNet-1K weights; new layers Xavier§4.2
Batch size16 (2 per GPU on 8 GPUs)§4.2 [code: detection/configs/base/datasets/coco_detection.py#L32]
OptimizerAdamW§4.2
Learning rate, RetinaNet 1x1e-4§4.2 retinanet_pvt_v2_b2_fpn_1x_coco.py
Learning rate, Mask R-CNN 1x2e-4 in codemask_rcnn_pvt_v2_b2_fpn_1x_coco.pypaper says 1e-4
Learning rate, 3x configs1e-4 (Mask R-CNN, ATSS, GFL, Cascade); about 1.8e-5 for Sparse R-CNNmask_rcnn_pvt_v2_b2_fpn_3x_mstrain.py sparse_rcnn_pvt_v2_b2_fpn_300_proposals_crop_mstrain_480-800_3x_coco.pySparse R-CNN value is 0.000025 / 1.4
Weight decay1x: 1e-4; 3x: 5e-2mask_rcnn_pvt_v2_b2_fpn_1x_coco.py mask_rcnn_pvt_v2_b2_fpn_3x_mstrain.pypaper not stated
Schedule 1x12 epochs; steps at 8 and 11; linear warmup over 500 iterations, starting at 0.001 times the rate§4.2 [code: detection/configs/base/schedules/schedule_1x.py#L7-L11]
Schedule 3x36 epochs; steps at 27 and 33§4.2 mask_rcnn_pvt_v2_b2_fpn_3x_mstrain.py
Train resizeshorter side 800, longer side at most 1333§4.2 [code: detection/configs/base/datasets/coco_detection.py#L9]1x
Train resize, 3xshorter side random in 640-800§4.2code uses 480-800 with AutoAugment, see Paper vs code
Test resizeshorter side 800§4.2 [code: detection/configs/base/datasets/coco_detection.py#L20]

Semantic segmentation on ADE20K §4.3:

NameValueWhereNotes
HeadSemantic FPN§4.3
OptimizerAdamW, initial learning rate 1e-4§4.3
Iterations, batch40k iterations, batch 16 on 4 GPUs§4.3
Schedulepolynomial, power 0.9§4.3 fpn_pvt_s_ade20k_40k.py
Train crop512 x 512, random resize and crop§4.3 [code: segmentation/configs/base/datasets/ade20k.py#L6-L11]code: resize to 2048 x 512 with ratio 0.5-2.0
Testshorter side 512§4.3

Results

All numbers are author-reported. The setup for each line is the task and split named in its row.

SettingMetricBaselineThis paperSource
ImageNet-1K, 224 px, largest modeltop-1 accuracySwin-B 83.3PVT v2-B5 83.8tab. 2
ImageNet-1K, about 4 GFLOPstop-1 accuracySwin-T 81.3 (4.5 GFLOPs)PVT v2-B2 82.0 (4.0 GFLOPs, 25.4M params)tab. 2
ImageNet-1K vs PVT v1top-1 accuracyPVT v1-Tiny 75.1PVT v2-B1 78.7tab. 2
COCO val2017, RetinaNet 1xAPPVT v1-Large 42.6PVT v2-B4 46.1tab. 3
COCO val2017, Mask R-CNN 1xbox APPVT v1-Large 42.9PVT v2-B4 47.5tab. 3
COCO val2017, ATSS (schedule not stated in table)box APSwin-T 47.2PVT v2-B2 49.9tab. 4
COCO val2017, GFL (schedule not stated in table)box APSwin-T 47.6PVT v2-B2 50.2tab. 4
ADE20K, Semantic FPNmIoUPVT v1-Large 42.1PVT v2-B4 47.9; B5 48.7tab. 5
Ablation, ImageNet and RetinaNettop-1; APPVT v1-Small 79.8; 40.4PVT v2-B2 82.0; 44.6tab. 6

Full tables

Classification on ImageNet-1K validation, input 224 x 224 tab. 2. GFLOPs at 224 x 224. "-Li" is PVT v2 with linear SRA.

Method#Param (M)GFLOPsTop-1 (%)
PVT v2-B0 (ours)3.40.670.5
ResNet1811.71.869.8
DeiT-Tiny/165.71.372.2
PVT v1-Tiny13.21.975.1
PVT v2-B1 (ours)13.12.178.7
ResNet5025.64.176.1
ResNeXt50-32x4d25.04.377.6
RegNetY-4G21.04.080.0
DeiT-Small/1622.14.679.9
T2T-ViT_t-1422.06.180.7
PVT v1-Small24.53.879.8
TNT-S23.85.281.3
Swin-T29.04.581.3
CvT-1320.04.581.6
CoaT-Lite Small20.04.081.9
Twins-SVT-S24.02.881.7
PVT v2-B2-Li (ours)22.63.982.1
PVT v2-B2 (ours)25.44.082.0
ResNet10144.77.977.4
ResNeXt101-32x4d44.28.078.8
RegNetY-8G39.08.081.7
T2T-ViT_t-1939.09.881.4
PVT v1-Medium44.26.781.2
CvT-2132.07.182.5
PVT v2-B3 (ours)45.26.983.2
ResNet15260.211.678.3
T2T-ViT_t-2464.015.082.2
PVT v1-Large61.49.881.7
TNT-B66.014.182.8
Swin-S50.08.783.0
Twins-SVT-B56.08.383.2
PVT v2-B4 (ours)62.610.183.6
ResNeXt101-64x4d83.515.679.6
RegNetY-16G84.016.082.9
ViT-Base/1686.617.681.8
DeiT-Base/1686.617.681.8
Swin-B88.015.483.3
Twins-SVT-L99.214.883.7
PVT v2-B5 (ours)82.011.883.8

COCO val2017, RetinaNet 1x and Mask R-CNN 1x tab. 3. "#P" is parameters in millions. "-Li" is PVT v2 with linear SRA.

BackboneRetinaNet #PAPAP50AP75APSAPMAPL
PVT v2-B0 (ours)13.037.257.239.523.140.449.7
ResNet1821.331.849.633.616.334.343.2
PVT v1-Tiny23.036.756.938.922.638.850.0
PVT v2-B1 (ours)23.841.261.943.925.444.554.3
ResNet5037.736.355.338.619.340.048.8
PVT v1-Small34.240.461.343.025.042.955.7
PVT v2-B2-Li (ours)32.343.664.746.828.347.657.4
PVT v2-B2 (ours)35.144.665.647.627.448.858.6
ResNet10156.738.557.841.221.442.651.1
ResNeXt101-32x4d56.439.959.642.722.344.252.5
PVT v1-Medium53.941.963.144.325.044.957.6
PVT v2-B3 (ours)55.045.966.849.328.649.861.4
PVT v1-Large71.142.663.745.425.846.058.4
PVT v2-B4 (ours)72.346.166.949.228.450.062.2
ResNeXt101-64x4d95.541.060.944.023.945.254.0
PVT v2-B5 (ours)91.746.267.149.528.550.062.5
BackboneMask R-CNN #PAP^bAP^b50AP^b75AP^mAP^m50AP^m75
PVT v2-B0 (ours)23.538.260.540.736.257.838.6
ResNet1831.234.054.036.731.251.032.7
PVT v1-Tiny32.936.759.239.335.156.737.3
PVT v2-B1 (ours)33.741.864.345.938.861.241.6
ResNet5044.238.058.641.434.455.136.7
PVT v1-Small44.140.462.943.837.860.140.3
PVT v2-B2-Li (ours)42.244.166.348.440.563.243.6
PVT v2-B2 (ours)45.045.367.149.641.264.244.4
ResNet10163.240.461.144.236.457.738.8
ResNeXt101-32x4d62.841.962.545.937.559.440.2
PVT v1-Medium63.942.064.445.639.061.642.1
PVT v2-B3 (ours)64.947.068.151.742.565.745.7
PVT v1-Large81.042.965.046.639.561.942.5
PVT v2-B4 (ours)82.247.568.752.042.766.146.1
ResNeXt101-64x4d101.942.863.847.338.460.641.3
PVT v2-B5 (ours)101.647.468.651.942.565.746.0

COCO val2017 box AP with four detectors, compared with Swin-T and ResNet-50 tab. 4. "#P" is parameters in millions; GFLOPs at 1280 x 800. The table does not state the schedule.

BackboneDetectorAP^bAP^b50AP^b75#PGFLOPs
ResNet50Cascade Mask R-CNN46.364.350.582739
Swin-TCascade Mask R-CNN50.569.354.986745
PVT v2-B2-Li (ours)Cascade Mask R-CNN50.969.555.280725
PVT v2-B2 (ours)Cascade Mask R-CNN51.169.855.383788
ResNet50ATSS43.561.947.032205
Swin-TATSS47.266.551.336215
PVT v2-B2-Li (ours)ATSS48.968.153.430194
PVT v2-B2 (ours)ATSS49.969.154.133258
ResNet50GFL44.563.048.332208
Swin-TGFL47.666.851.736215
PVT v2-B2-Li (ours)GFL49.268.253.730197
PVT v2-B2 (ours)GFL50.269.454.733261
ResNet50Sparse R-CNN44.563.448.2106166
Swin-TSparse R-CNN47.967.352.3110172
PVT v2-B2-Li (ours)Sparse R-CNN48.968.353.4104151
PVT v2-B2 (ours)Sparse R-CNN50.169.554.9107215

ADE20K validation, Semantic FPN, input 512 x 512 for GFLOPs tab. 5:

Backbone#Param (M)GFLOPsmIoU (%)
PVT v2-B0 (ours)7.625.037.2
ResNet1815.532.232.9
PVT v1-Tiny17.033.235.7
PVT v2-B1 (ours)17.834.242.5
ResNet5028.545.636.7
PVT v1-Small28.244.539.8
PVT v2-B2-Li (ours)26.341.045.1
PVT v2-B2 (ours)29.145.845.2
ResNet10147.565.138.8
ResNeXt101-32x4d47.164.739.7
PVT v1-Medium48.061.041.6
PVT v2-B3 (ours)49.062.447.3
PVT v1-Large65.179.642.1
PVT v2-B4 (ours)66.381.347.9
ResNeXt101-64x4d86.4103.940.2
PVT v2-B5 (ours)85.791.148.7

Ablation on ImageNet top-1 and COCO RetinaNet 1x AP tab. 6. The GFLOPs column is RetinaNet 1x.

#SettingTop-1 (%)#P (M)GFLOPsAP
1PVT v1-Small79.834.2285.840.4
2+ overlapping patch embedding81.134.9288.642.2
3++ convolutional FFN (PVT v2-B2)82.035.1290.744.6
4+++ linear SRA (PVT v2-B2-Li)82.132.3227.443.6

Figures: fig. 1 compares SRA with linear SRA. fig. 2 shows the two convolution-based changes. fig. 3 shows qualitative detection, instance and segmentation outputs. fig. 4 plots GFLOPs against input size. Per the authors, the compute of PVT v2-B2-Li climbs far less steeply as the input grows than PVT v1-Small's, and follows a curve similar to ResNet-50's §4.4.2. No figure is reproduced on this page.

Paper vs code

Checked against the repository linked from the abstract, at the commit above (Apache-2.0; the README calls it the official implementation). The classification, detection and segmentation folders were all read.

  • Linear SRA has extra layers in code. The text describes only average pooling to P x P §3.2. The code also applies a 1x1 convolution, LayerNorm and GELU to the pooled grid before the key and value projections pvt_v2.py pvt_v2.py. The released checkpoints are loaded into this code, so an implementation that matches them needs these layers.
  • Linear variants add a ReLU in the feed-forward block. The text does not mention it. The code applies ReLU after the first linear layer when the variant is linear pvt_v2.py pvt_v2.py.
  • Stage 2 depth differs for B2, B2-Li and B3. Table 1 gives L = 3 in stage 2 for these variants tab. 1. The code uses depths [3, 4, 6, 3] for B2 and B2-Li and [3, 4, 18, 3] for B3 pvt_v2.py pvt_v2.py pvt_v2.py. The README's B2 count (25.4M) matches Table 2, but I did not count parameters from the code, so I cannot tell from the sources which depth is right.
  • Classification learning rate. The text gives 1e-3 for batch 128 §4.1. The code's default is 5e-4 and it scales the rate linearly by batch x world size / 512 main.py main.py. That gives 1e-3 only when 128 is the batch per GPU on 8 GPUs (a global batch of 1024). The text does not say which.
  • Classification augmentation. The text lists crop, flip, label smoothing, mixup and random erasing §4.1. The code also uses RandAugment, colour jitter, CutMix and a repeated-augmentation sampler main.py main.py.
  • Evaluation resize. The text states only a 224 centre crop §4.1. The code resizes the shorter side to 256 first datasets.py.
  • Detection learning rate for Mask R-CNN 1x. The text gives 1e-4 §4.2. The 1x Mask R-CNN config sets 2e-4 mask_rcnn_pvt_v2_b2_fpn_1x_coco.py. The Sparse R-CNN 3x config sets about 1.8e-5 sparse_rcnn_pvt_v2_b2_fpn_300_proposals_crop_mstrain_480-800_3x_coco.py.
  • Detection multi-scale range for 3x. The text gives a shorter side in 640-800 §4.2. The 3x configs use 480-800 in their multi-scale policy, with an AutoAugment-style crop branch mask_rcnn_pvt_v2_b2_fpn_3x_mstrain.py mask_rcnn_pvt_v2_b2_fpn_3x_mstrain.py.
  • Stochastic depth and gradient clipping are set in code only: 0.1 for B0, B1, B2 and B2-Li, and 0.3 for B3, B4 and B5; clipping at 1.0 for B3 to B5 pvt_v2_b3.py pvt_v2_b5.py.
  • Segmentation code. The repository's segmentation configs cover PVT v1 only fpn_pvt_s_ade20k_40k.py. Their learning rate is 1e-4 doubled for 8 GPUs, with 40k iterations and 4 images per GPU fpn_pvt_s_ade20k_40k.py [code: segmentation/configs/base/datasets/ade20k.py#L35]. This is consistent with the text's 1e-4 at batch 16 on 4 GPUs under linear scaling, but no PVT v2 segmentation config is released.
  • Model sizes in the README differ from Table 2. The README lists 3.7M for B0 (table: 3.4M), 14.0M for B1 (table: 13.1M), and 83.1% top-1 for B3 (table: 83.2%) README.md.
  • Classification head. The code averages the tokens after the final norm and applies one linear layer pvt_v2.py. The paper does not describe the head.

Pitfalls

  • Text and table disagree on several numbers. The introduction says B5 "yields 83.8% top-1 error"; the table reports accuracy §1 tab. 2. The text says B5 is 0.5% above Swin and Twins §4.1; Twins-SVT-L is 83.7%, which is 0.1% lower than B5, while Swin-B is 83.3%.
  • Segmentation sentence names the wrong model. The text compares "PVT-Large" with ResNeXt101-64x4d and reports 48.7 mIoU §4.3. The 48.7 figure is for PVT v2-B5; PVT v1-Large is 42.1 tab. 5. The 12% GFLOPs saving quoted there matches B5 (91.1 against 103.9) tab. 5.
  • Overlap patch embedding output size. The text says the output is h/S x w/S §3.3. With kernel 2S-1 and padding S-1, the output is ceil(H/S) for any H. This matters for detection and segmentation, where inputs are not multiples of the stride. The padding is set by the code's patch_size // 2 pvt_v2.py.
  • Only keys and values shrink. Queries still come from all N tokens, and keys and values number 49 per head. The cost is therefore linear in N, but the query and output projections still scale with N §3.2 eq. 2.
  • The linear variant trades accuracy for compute. Against the convolutional SRA model, linear SRA cuts RetinaNet 1x GFLOPs from 290.7 to 227.4 and costs 1.0 AP (44.6 to 43.6) tab. 6. On ImageNet it gains 0.1 (82.0 to 82.1) tab. 6.
  • The convolutional FFN and overlap embedding add cost. Going from row 2 to row 3 of Table 6 adds about 0.2M parameters and about 2 GFLOPs at RetinaNet input size tab. 6.
  • No position embedding. Positional information comes from zero padding in the overlap embedding and the depthwise conv. The claim that the model handles variable resolution rests on the ablation rows and on the authors' statement §3.4 §4.4.1; no separate experiment varies the input size.
  • Schedules are missing from some comparisons. Section 4.2 says "1x or 3x" and that all settings match the Swin comparison §4.2, but Table 4 does not state which schedule was used tab. 4.
  • Numerical details the paper omits. Stochastic depth, warmup, minimum learning rate, LayerNorm epsilon, and the classification head are not stated in the paper. The values above come from the code main.py pvt_v2.py.
  • Mixed precision is used in several 3x detection configs (ATSS, GFL, Cascade Mask R-CNN, Mask R-CNN-Li) atss_pvt_v2_b2_fpn_3x_mstrain_fp16.py. The paper does not mention it.

Lineage

  • Builds on: PVT v1 (arXiv:2102.12122), whose four-stage pyramid and spatial reduction attention this paper keeps §1 §3.1. The README gives the PVT v1 id README.md.
  • Compared against: Swin Transformer, which has its own card [/papers/2103.14030]; ViT and DeiT for classification tab. 2; CNNs such as ResNet, ResNeXt and RegNet; and T2T-ViT, TNT, CvT, CoaT and Twins tab. 2.
  • Superseded by: not known from content in this wiki.

Source and license

Adapted from “PVT v2: Improved Baselines with Pyramid Vision Transformer” by Wenhai Wang, Enze Xie, Xiang Li, Deng-Ping Fan, Kaitao Song, Ding Liang, Tong Lu, Ping Luo, Ling Shao (arXiv:2106.13797), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/whai362/PVT at commit 57e2dfaa5a46 (Apache-2.0). Any quoted code is shown under that license.