Swin Transformer
15 memberslucid.models.vision.swinSwin Transformer family — Liu et al., 2021.
Liu, Ze, et al. "Swin Transformer: Hierarchical Vision Transformer using Shifted Windows." Proceedings of the IEEE/CVF International Conference on Computer Vision, 2021, pp. 10012-10022.
The Swin Transformer reintroduces the hierarchical feature pyramid of classical CNNs into a pure-transformer backbone, making it a general-purpose vision model that scales linearly with image resolution rather than quadratically (as plain ViT does). The image is first split into non-overlapping patches and projected to channels. Four stages then follow, each halving the spatial resolution via a patch merging layer that concatenates neighbours and projects , doubling the channel width — giving the canonical pyramid.
Within each stage the tokens flow through pairs of Swin blocks. The first block computes self-attention inside non-overlapping windows of size (default ), and the second performs shifted-window (SW-MSA) attention where the grid is cyclically shifted by . Because each window is processed independently, the attention cost per image is instead of , but the shift introduces cross-window connections so the receptive field still grows with depth. A learnable relative position bias is added inside softmax:
The four canonical variants (Tiny / Small / Base / Large) scale and per-stage block counts from Table 7 of the paper, trading parameters for accuracy while reusing the same shifted-window mechanism end to end.
Classes
Functions
swin_tiny→ SwinTransformerSwin-Tiny backbone (Liu et al., 2021).
swin_tiny_cls→ SwinTransformerForImageClassificationSwin-Tiny image classifier (Liu et al., 2021).
swin_small→ SwinTransformerSwin-Small backbone (Liu et al., 2021).
swin_small_cls→ SwinTransformerForImageClassificationSwin-Small image classifier (Liu et al., 2021).
swin_base→ SwinTransformerSwin-Base backbone (Liu et al., 2021).
swin_base_cls→ SwinTransformerForImageClassificationSwin-Base image classifier (Liu et al., 2021).
swin_large→ SwinTransformerSwin-Large backbone (Liu et al., 2021).
swin_large_cls→ SwinTransformerForImageClassificationSwin-Large image classifier (Liu et al., 2021).
Weights
SwinBaseWeightsPretrained weight tags for lucid.models.swin_base_cls.
SwinLargeWeightsPretrained weight tags for lucid.models.swin_large_cls.
SwinSmallWeightsPretrained weight tags for lucid.models.swin_small_cls.
SwinTinyWeightsPretrained weight tags for lucid.models.swin_tiny_cls.