CvT
12 memberslucid.models.vision.cvtCvT family — backbone + image classification (Wu et al., 2021).
Wu, Haiping, et al. "CvT: Introducing Convolutions to Vision Transformers." Proceedings of the IEEE/CVF International Conference on Computer Vision, 2021, pp. 22-31.
The Convolutional vision Transformer (CvT) reinjects the locality inductive bias of CNNs into ViT through two changes: (i) replacing the non-overlapping patch embedding by overlapping convolutional token embedding, and (ii) replacing the linear projections inside self-attention with depthwise-separable convolutional projections. CvT also drops positional embeddings entirely — locality is supplied implicitly by the convolutional projections.
Convolutional token embedding is performed at the start of each of the three stages: a strided convolution produces a new token grid of reduced spatial resolution and increased channel width, yielding a Swin-like hierarchical pyramid. Inside every block the queries / keys / values are computed with depthwise convolutions rather than linear maps:
where is the spatially reshaped token map. When the key/value DWConv uses stride 2 the attention becomes strided, reducing by 4 inside attention without losing the full-resolution output for the next block. Variants CvT-13 / 21 / 24 scale depth and width along this three-stage convolutional transformer skeleton.
Classes
Functions
cvt_13→ CvTCvT-13 backbone (Wu et al., 2021).
cvt_13_cls→ CvTForImageClassificationCvT-13 image classifier (Wu et al., 2021).
cvt_21→ CvTCvT-21 backbone (Wu et al., 2021).
cvt_21_cls→ CvTForImageClassificationCvT-21 image classifier (Wu et al., 2021).
cvt_w24→ CvTCvT-W24 wide backbone (Wu et al., 2021).
cvt_w24_cls→ CvTForImageClassificationCvT-W24 wide image classifier (Wu et al., 2021).