Skip to content

Latest commit

 

History

History
89 lines (58 loc) · 6.32 KB

architecture.md

File metadata and controls

89 lines (58 loc) · 6.32 KB

Swin Transformer Architecture

Overview

Swin Transformer, introduced by researchers at Microsoft Research Asia, is a hierarchical vision transformer specifically designed to efficiently handle high-resolution visual data. Its innovative architecture allows it to outperform traditional vision transformers, such as Vision Transformer (ViT), especially on tasks requiring multi-scale and dense predictions, like object detection and semantic segmentation.

The primary components of the Swin Transformer architecture include local windowed self-attention, shifted windows, and hierarchical feature extraction. Together, these innovations help the Swin Transformer to achieve linear computational complexity relative to image size, making it scalable to high-resolution inputs.


Key Components of the Swin Transformer Architecture

1. Local Windowed Self-Attention

Unlike traditional transformers like ViT, which calculate global self-attention across the entire image, Swin Transformer calculates self-attention within small, fixed-size windows. By limiting the scope of self-attention to local windows, Swin Transformer reduces the computational complexity to O(n), where n is the number of tokens in each window. This local windowed self-attention significantly improves efficiency and allows the model to process high-resolution images more effectively.

Local Windowed Self-Attention

Figure 1. Local Windowed Self-Attention in Swin Transformer compared to Global Attention in ViT.

2. Shifted Window Mechanism

To enable interactions between neighboring windows, Swin Transformer uses a shifted window mechanism. In this mechanism, the partitioned windows are shifted by half the window size at alternating layers. This allows tokens in one window to interact with tokens in adjacent windows at the next layer, facilitating feature sharing across windows without significantly increasing computational costs.

Shifted Window Mechanism

Figure 2. Shifted Window Mechanism enabling cross-window connections in Swin Transformer.

3. Hierarchical Feature Extraction

Swin Transformer introduces a hierarchical architecture, which is similar to the multi-scale feature extraction found in convolutional neural networks (CNNs). The model constructs feature maps with progressively increasing resolution, enabling it to capture both fine-grained and high-level information. This hierarchical feature extraction makes Swin Transformer particularly well-suited for tasks like object detection and segmentation, where multi-scale information is essential.

Hierarchical Feature Extraction

Figure 3. Hierarchical Feature Extraction in Swin Transformer, allowing multi-scale feature representation.


Comparison with Other Vision Architectures

Swin Transformer’s architecture is unique compared to other prominent vision transformers, such as Vision Transformer (ViT) and Data-efficient Image Transformer (DeiT), in the following ways:

Feature Swin Transformer Vision Transformer (ViT) Data-efficient Image Transformer (DeiT)
Attention Scope Local windows Global Global
Window Shifting Shifted windows None None
Hierarchical Structure Yes No No
Computational Complexity Linear Quadratic Quadratic
Suitable for High Res. Yes Limited Limited

Comparison Summary

  1. Vision Transformer (ViT): Computes global self-attention across the entire image, leading to quadratic complexity with respect to the image size. ViT lacks a hierarchical structure, which limits its ability to handle multi-scale features efficiently.

  2. Data-efficient Image Transformer (DeiT): Although DeiT introduces some optimizations for training efficiency, it still uses global attention and lacks Swin Transformer’s hierarchical and shifted window mechanisms, making it less scalable for high-resolution images.

  3. Swin Transformer: By combining local attention within windows, a shifted window approach for cross-patch connections, and a hierarchical structure, Swin Transformer maintains the flexibility of transformers while achieving computational efficiency comparable to that of CNNs.

Comparison of Swin Transformer with ViT and DeiT

Figure 4. Comparison of Swin Transformer with Vision Transformer (ViT) and Data-efficient Image Transformer (DeiT).


Applications

Due to its efficient and scalable architecture, Swin Transformer has achieved state-of-the-art results on a wide range of computer vision tasks, including:

  • Image Classification: Achieves competitive accuracy on large-scale datasets.
  • Object Detection: The hierarchical structure supports multi-scale detection, achieving high accuracy across different object scales.
  • Semantic Segmentation: Swin Transformer’s multi-scale feature extraction enables it to produce accurate segmentation maps with fine-grained details.

References

For more details on the Swin Transformer architecture, please refer to the original paper:

@article{liu2021swin,
  title={Swin Transformer: Hierarchical Vision Transformer using Shifted Windows},
  author={Liu, Ze and Lin, Yutong and Cao, Yue and Hu, Han and Wei, Yixuan and Zhang, Zheng and Lin, Stephen and Guo, Baining},
  journal={arXiv preprint arXiv:2103.14030},
  year={2021}
}