PVT v2 backbone (Wang et al., 2022).
The Pyramid Vision Transformer v2 is a pure-transformer backbone that produces a hierarchical feature pyramid — making it a drop-in replacement for ResNet-style backbones in dense prediction tasks (detection, segmentation). The trunk has four stages, each beginning with an overlapping convolutional patch embedding ( stride 4 for stage 0; stride 2 for subsequent stages). Inside each stage every transformer block applies Spatial-Reduction Attention (SRA):
where decreases with depth (e.g. ). This cuts the per-stage attention cost from to . PVT v2 additionally inserts a depthwise convolution between the two MLP linears, providing spatial mixing inside the feed-forward sublayer and removing the need for explicit positional embeddings.
forward_features returns the mean-pooled final-stage
feature .
Parameters
configPVTConfigembed_dims, depths,
num_heads, sr_ratios, mlp_ratios, in_channels,
and num_classes. See PVTConfig.Attributes
patch_embed_OverlapPatchEmbedstagesnn.ModuleList_PVTStage modules; stages 1-3 each contain their
own stride-2 patch-embedding downsampler.feature_infolist[FeatureInfo]Notes
Reference (v1): Wenhai Wang et al., "Pyramid Vision Transformer: A Versatile Backbone for Dense Prediction without Convolutions", ICCV 2021, arXiv:2102.12122. Reference (v2): Wenhai Wang et al., "PVT v2: Improved Baselines with Pyramid Vision Transformer", CVMJ 2022.
Examples
Build a PVT v2-B1 backbone and run a forward pass:
>>> import lucid
>>> from lucid.models.vision.pvt import PVT, PVTConfig
>>> model = PVT(PVTConfig())
>>> x = lucid.randn(1, 3, 224, 224)
>>> feat = model.forward_features(x)
>>> feat.shape # (B, embed_dims[-1])
(1, 512)