PVTConfig
ModelConfigPVTConfig(num_classes: int = 1000, in_channels: int = 3, variant: str = 'pvt_tiny', embed_dims: tuple[int, ...] = (64, 128, 320, 512), depths: tuple[int, ...] = (2, 2, 2, 2), num_heads: tuple[int, ...] = (1, 2, 5, 8), sr_ratios: tuple[int, ...] = (8, 4, 2, 1), mlp_ratios: tuple[float, ...] = (8.0, 8.0, 4.0, 4.0))Configuration dataclass for every PVT (v2) variant.
PVTConfig is an immutable container that fully specifies the
architecture of a Pyramid Vision Transformer v2 (Wang et al., 2021
and 2022). The implementation in lucid.models.vision.pvt
builds PVT v2 by default: overlapping convolutional patch
embedding at each stage, a depthwise-conv-augmented MLP, and the
Spatial-Reduction Attention (SRA) from PVT v1.
Parameters
num_classesint= 10001000 (ImageNet-1k).in_channelsint= 33 (RGB).variantstr= 'pvt_tiny'"pvt_v2_b0" through "pvt_v2_b5"). Defaults to
"pvt_tiny".embed_dimstuple of int= (64, 128, 320, 512)(64, 128, 320, 512) — PVT v2-B1.depthstuple of int= (2, 2, 2, 2)(2, 2, 2, 2).num_headstuple of int= (1, 2, 5, 8)(1, 2, 5, 8).sr_ratiostuple of int= (8, 4, 2, 1)1 disables
SR for the deepest stage. Defaults to (8, 4, 2, 1).mlp_ratiostuple of float= (8.0, 8.0, 4.0, 4.0)(8.0, 8.0, 4.0, 4.0) — early stages widen more than late
stages, following PVT v2-B1.Attributes
model_typeClassVar[str]"pvt" used by the model registry.Notes
Spatial-Reduction Attention (SRA) reduces the per-stage attention cost from to by downsampling the K / V feature map by stride before computing attention.
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, arXiv:2106.13797.
Examples
Build a PVT v2-B1 configuration with a 100-class head:
>>> from lucid.models.vision.pvt import PVTConfig
>>> cfg = PVTConfig(num_classes=100)
>>> cfg.embed_dims, cfg.depths, cfg.sr_ratios, cfg.num_classes
((64, 128, 320, 512), (2, 2, 2, 2), (8, 4, 2, 1), 100)Used by 3
Constructors
1__init__
→None__init__(num_classes: int = 1000, in_channels: int = 3, variant: str = 'pvt_tiny', embed_dims: tuple[int, ...] = (64, 128, 320, 512), depths: tuple[int, ...] = (2, 2, 2, 2), num_heads: tuple[int, ...] = (1, 2, 5, 8), sr_ratios: tuple[int, ...] = (8, 4, 2, 1), mlp_ratios: tuple[float, ...] = (8.0, 8.0, 4.0, 4.0))