[Summary] Swin Transformer: Hierarchical Vision Transformer using Shifted Windows Explained

Ze Liu, Yutong Lin, Yue Cao, Han Hu, Yixuan Wei, Zheng Zhang, Stephen Lin, B. Guo · 2021 · IEEE International Conference on Computer Vision · 24728 citations

Paper Summary and Key Insights

This summary breaks down the key contributions, methodology, results, and applications of this research paper. Use the sections below to understand the paper's context, main ideas, and significance.

Swin Transformer: Hierarchical Vision Transformer using Shifted Windows

Context

The landscape of deep learning has witnessed a remarkable divergence between computer vision and natural language processing. While Convolutional Neural Networks (CNNs) have long reigned supreme as the backbone for diverse vision tasks, the Transformer architecture has revolutionized natural language processing by effectively modeling long-range dependencies in sequential data. The challenge of adapting Transformers to computer vision, however, has been significant, primarily due to fundamental differences between the two domains. Visual entities exhibit vast variations in scale, from minute details to expansive objects, and images possess a far higher resolution than text sequences, leading to prohibitive computational costs if global self-attention is applied directly. Previous attempts, such as the Vision Transformer (ViT), often produced single-resolution feature maps and suffered from quadratic computational complexity with respect to image size, rendering them unsuitable for dense prediction tasks or high-resolution imagery. This paper addresses these critical limitations, aiming to establish a Transformer-based architecture that can serve as a versatile, general-purpose backbone for the entire spectrum of computer vision applications.

Key Contributions

  • The paper introduces the Swin Transformer, a novel vision Transformer that constructs hierarchical feature maps, enabling flexible modeling at various scales, akin to traditional CNNs.
  • It proposes a shifted windowing scheme for self-attention computation, which efficiently limits calculations to non-overlapping local windows while simultaneously facilitating cross-window connections in successive layers.
  • Researchers demonstrate that this hierarchical architecture achieves linear computational complexity with respect to image size, making it highly scalable for high-resolution images and dense prediction tasks.
  • The Swin Transformer achieves state-of-the-art performance across a broad range of vision benchmarks, including image classification, object detection, and semantic segmentation, significantly outperforming previous models.
  • The work establishes Transformer-based models as viable and powerful general-purpose backbones for computer vision, challenging the long-standing dominance of CNNs.
  • It incorporates a relative position bias within the self-attention mechanism, which is shown to be crucial for enhancing performance across various vision tasks.

Method (Simple Explanation)

The Swin Transformer's core innovation lies in its hierarchical architecture and the shifted window approach for self-attention. Initially, an input RGB image is divided into non-overlapping patches, each treated as a "token," similar to how words are processed in NLP Transformers. These raw pixel values are then projected into a higher-dimensional feature space via a linear embedding layer. To create a multi-scale representation, essential for vision tasks, the architecture employs "patch merging" layers that progressively reduce the number of tokens in deeper stages while increasing their feature dimensions, thereby building hierarchical feature maps analogous to those found in CNNs, as illustrated in Figure 1(a).

To circumvent the quadratic computational complexity of global self-attention, which would be intractable for high-resolution images, the Swin Transformer computes self-attention locally within non-overlapping windows. However, simply restricting attention to local windows would limit the model's ability to capture global context. To address this, the authors introduce a crucial "shifted window partitioning" scheme. As depicted in Figure 2, in one layer, windows are partitioned regularly; in the subsequent layer, the window partition is shifted. This alternating shift allows information to flow between windows that were previously separate, effectively creating cross-window connections without incurring the computational overhead of global attention.

Furthermore, the paper details an efficient batch computation approach for the shifted window configuration, using a cyclic-shifting mechanism (Figure 4) to maintain efficiency and prevent an increase in the number of windows. This ensures that the shifted window approach remains computationally lightweight. Finally, a relative position bias is incorporated into the self-attention calculation, providing the model with explicit spatial information about the patches within each window, which empirically proves beneficial for overall performance.

Results

  • The Swin Transformer achieved a top-1 accuracy of 87.3% on ImageNet-1K image classification, demonstrating superior performance compared to previous Transformer-based and ConvNet-based models, as detailed in Table 1(b).
  • For object detection on the COCO test-dev set, the model attained 58.7 box AP and 51.1 mask AP, significantly surpassing the previous state-of-the-art results by +2.7 box AP and +2.6 mask AP, as presented in Table 2(c).
  • In semantic segmentation on ADE20K val, the Swin Transformer achieved 53.5 mIoU, marking an improvement of +3.2 mIoU over the previous state-of-the-art (SETR), as shown in Table 3.
  • The ablation study in Table 4 clearly demonstrates that the shifted window partitioning approach significantly improves accuracy across all three tasks (ImageNet-1K, COCO, ADE20K) compared to a non-shifted window approach.
  • As indicated in Table 4, the inclusion of relative position bias provides substantial accuracy gains across image classification, object detection, and semantic segmentation compared to models without position encoding or with absolute position embedding.
  • The shifted window approach also proves to be highly efficient, exhibiting much lower latency compared to sliding window methods and even slightly faster performance than Performer, as detailed in Table 5.

Applications

  • General-purpose computer vision backbone: The Swin Transformer can serve as a foundational architecture for a wide array of vision tasks, offering a powerful alternative to traditional CNNs for various applications.
  • High-resolution image analysis: Its linear computational complexity makes it particularly well-suited for processing high-resolution images, which is crucial for fields like medical imaging, remote sensing, and industrial inspection.
  • Dense prediction tasks: The hierarchical feature maps and efficient self-attention enable superior performance in tasks requiring pixel-level understanding, such as object detection and semantic segmentation for autonomous driving, robotics, and video surveillance.
  • Unified vision-language modeling: By demonstrating the potential of Transformers in vision, this work paves the way for more integrated models that can process both visual and textual data, fostering advancements in multimodal artificial intelligence.

Why it Matters

The Swin Transformer marks a pivotal moment in the evolution of deep learning for computer vision, signaling a potential paradigm shift from CNN-centric architectures to Transformer-based models. By effectively addressing the inherent challenges of scale variation and high computational cost in visual data, this paper successfully bridges the gap between the successes of Transformers in natural language processing and their applicability to the visual domain. This breakthrough not only provides a powerful, general-purpose backbone for a vast array of vision tasks but also fosters the vision of a unified architecture capable of processing both visual and textual signals, potentially unlocking new frontiers in multimodal AI research. The demonstrated efficiency and state-of-the-art performance across diverse benchmarks underscore the Swin Transformer's profound impact, encouraging further innovation in scalable and versatile Transformer designs for future intelligent systems.

Using SpatialRead to Understand This Paper

  • The intricate details of the Swin Transformer's hierarchical architecture, particularly how patch merging layers create multi-scale representations, become clearer when SpatialRead allows for focused AI conversations on specific paragraphs.
  • Understanding Figure 2, which illustrates the crucial shifted window approach, is greatly enhanced as SpatialRead's screenshot feature enables direct AI queries about the visual elements and their functional implications.
  • The complex equations for computational complexity, such as Equation (1) and (2), can be easily captured and explained by SpatialRead's AI models, providing intuitive breakdowns of their significance.
  • SpatialRead's ability to highlight and query dense sections, like the "Efficient batch computation for shifted configuration" on page 5, allows researchers to quickly grasp the nuances of the proposed optimization techniques.
  • Comparing the extensive results presented in tables, such as Table 1 (ImageNet-1K classification) and Table 2 (COCO object detection), is made more efficient by using SpatialRead to extract and summarize key performance metrics.
  • The tool provides access to multiple AI models, offering diverse perspectives and nuanced explanations for technical terms like "relative position bias" or "self-attention computation," catering to different learning preferences.

Download SpatialRead →

Open access PDF →