MaxViT backbone (Tu et al., 2022).
MaxViT combines a convolutional MBConv stage with two complementary sparse self-attention mechanisms — block attention and grid attention — to obtain dense local plus dense global receptive fields at linear complexity in the number of tokens. The backbone is a four-stage pyramid preceded by a two-conv stem, and every MaxViT block applies (i) MobileNetV3-style MBConv, (ii) block attention, and (iii) grid attention in sequence.
Given a feature map of shape , block attention partitions it into non-overlapping windows (default ) and runs full self-attention inside each window — identical to Swin's W-MSA. Grid attention takes the same feature map and gathers tokens that share the same intra-window position across all windows. Formally, with , :
forward_features returns the global-average-pooled
feature.
Parameters
configMaxViTConfigdepths, dims,
window_size, num_heads, mlp_ratio, in_channels,
and num_classes. See MaxViTConfig.Attributes
stemnn.Modulestagesnn.ModuleListhead_HeadNormLinear + Tanh → final
Linear (also present on the backbone for parameter sharing).feature_infolist[FeatureInfo]Notes
Reference: Zhengzhong Tu et al., "MaxViT: Multi-Axis Vision Transformer", ECCV 2022, arXiv:2204.01697.
Examples
Build a MaxViT-Tiny backbone and run a forward pass:
>>> import lucid
>>> from lucid.models.vision.maxvit import MaxViT, MaxViTConfig
>>> model = MaxViT(MaxViTConfig())
>>> x = lucid.randn(1, 3, 224, 224)
>>> feat = model.forward_features(x)
>>> feat.shape # (B, dims[-1])
(1, 512)Used by 2
Constructors
1Properties
1feature_info: list[FeatureInfo]