What Makes for Hierarchical Vision Transformer?

Yuxin Fang\(^{1}\)1,   Xinggang Wang\(^{1}\)2,   Rui Wu\(^{2}\),   Wenyu Liu\(^{1}\)
\(^1\)School of EIC, Huazhong University of Science & Technology    \(^2\) Horizon Robotics
{yxf, xgwang}@hust.edu.cn


Abstract

Recent studies indicate that hierarchical Vision Transformer with a macro architecture of interleaved non-overlapped window-based self-attention & shifted-window operation is able to achieve state-of-the-art performance in various visual recognition tasks, and challenges the ubiquitous convolutional neural networks (CNNs) using densely slid kernels. Most follow-up works attempt to replace the shifted-window operation with other kinds of cross-window communication paradigms, while treating self-attention as the de-facto standard for window-based information aggregation. In this manuscript, we question whether self-attention is the only choice for hierarchical Vision Transformer to attain strong performance, and the effects of different kinds of cross-window communication. To this end, we replace self-attention layers with embarrassingly simple linear mapping layers, and the resulting proof-of-concept architecture termed as can achieve very strong performance in ImageNet-\(1k\) image recognition. Moreover, we find that is able to better leverage the pre-trained representations from image recognition and demonstrates excellent transfer learning properties on downstream dense prediction tasks such as object detection and instance segmentation. We also experiment with other alternatives to self-attention for content aggregation inside each non-overlapped window under different cross-window communication approaches, which all give similar competitive results. Our study reveals that the macro architecture of Swin model families, other than specific aggregation layers or specific means of cross-window communication, may be more responsible for its strong performance and is the real challenger to the ubiquitous CNN’s dense sliding window paradigm. Code and models will be publicly available to facilitate future research.

1 Introduction↩︎

Recently, the impregnable position of convolutional neural networks (CNNs) in computer vision seems to be weakened by the emerging hierarchical Vision Transformer families [1][4]. As one representative, Swin Transformer [3] and its variants (e.g.[5], [6]) with an interleaved non-overlapped window-based self-attention & cross-window token mixing paradigm are able to achieve state-of-the-art performance in image recognition, and demonstrate excellent transferability on various downstream computer vision tasks such as object detection and scene parsing. Therefore it is meaningful to conduct an in-depth study on this new architecture family, and analyze what makes it so strong.

9.8 pt

Table 1: Study of three representative hierarchical Vision Transformer with different information aggregation layers on ImageNet-\(1k\) [7]. All models are trained with 200 epochs schedule using the optimization scheme from [3]. “Shift”, “Shuffle”, and “MSG” refer to the cross-window communication scheme in [3][5], and [6], respectively. Models using MHSA layers keep the same configurations as their original implantations. Other models are tuned and selected with their best performance consuming \(\sim 4.5\)G FLOPs budgets and parameters ranging from \(24\)M to \(29\)M with only model depth & model width adaptations. We remove all densely slid conv-layers in the network stem and each block of [5] for a clearer study of different aggregation layers in non-overlapped windows. Overall, these results motivate us to focus more on the macro architecture design than specific aggregation layers or specific means of cross-window communication.
MHSA Linear DW Linear MLP
Shift \(80.5\) \(79.7\) \(79.8\) \(79.9\)
Shuffle \(80.6\) \(79.6\) \(79.6\) \(79.8\)
MSG \(80.4\) \(79.5\) \(79.7\) \(79.7\)

Methodologically, Swin Transformer first partitions feature maps to a series of non-overlapped local windows, and uses multi-head self-attention (MHSA) layers to aggregate information in each window individually. Then, instead of using a dense sliding window paradigm for cross-window token mixing like CNNs [8][10], Swin Transformer proposes to shift windows between consecutive layers. By alternating these two operations, each token is able to interact with all other tokens, and the overall architecture can obtain very strong capacities.

Most successors of Swin Transformer mainly focus on replacing the shifted-window operation with other kinds of cross-window communication, such as the spatial token shuffle operation from [5], and the messenger tokens exchange proposed in [6]. While the use of window-based MHSA is usually taken for granted and treated as the de-facto standard for token fusion within each local window.

In this manuscript, we ponder the question: “What Makes for Hierarchical Vision Transformer?”. Specifically, we investigate whether MHSA is the only choice to aggregate information for the Swin model family, and the effects of different cross-window communication schemes such as spatial token shuffle and auxiliary messager tokens exchange. Previous practice from computer vision suggests that MHSA is good at capture dense and long-range contextual information [11], [12] in scene parsing tasks [13], [14]. Intuitively, it is somewhat too aggressive to use MHSA to model contextual relation inside a local window with only \(7 \times 7 = 49\) spatial tokens.

This motivates us to replace MHSA layers with linear mapping, one of the most common & simplest components in neural architecture design, in three representative hierarchical Vision Transformer instantiations, i.e., Swin Transformer [3], Shuffle Transformer [5], and MSG Transformer [6]. The resulting proof-of-concept model is termed as . We find that with embarrassingly simple linear mapping layers is sufficient for local content aggregation, and is able to achieve very competitive performance in ImageNet-\(1k\) image recognition benchmark [7]. Moreover, can better leverage the pre-trained representations from image recognition and demonstrate excellent transferability in downstream dense prediction tasks such as object detection & instance segmentation.

Furthermore, we experiment with other variants for information aggregation inside each local window, e.g., depth-wise linear mapping with separable weights (denoted as “DW Linear” in Tab. 1), and multi-layer perceptrons with intermediate activation functions (denoted as “MLP” in Tab. 1). We also conduct a study on different cross-window communication approaches such as spatial token shuffle (denoted as “Shuffle” in Tab. 1) and auxiliary messager tokens exchange (denoted as “MSG” in Tab. 1). As shown in Tab. 1, we find different content aggregation layers all give similar competitive results under the same cross-window communication approaches, and vice versa: different cross-window communication methods also achieve similar strong performance under the same content aggregation layer.

Based on the available evidence, we hypothesize that the macro architecture of Swin model families, i.e., interleaved non-overlapped window-based token mixing & cross-window communications, other than specific aggregation layers such as MHSA or specific means of cross-window communication such as shifted-window or spatial shuffle, may be more responsible for their strong performance, and is the real challenger to the ubiquitous CNN’s dense sliding window paradigm.

Please note that this manuscript is not an attempt to show that simple linear or MLP layers are superior to MHSA. On the contrary, we find MHSA is better than linear mapping & MLP in terms of accuracy with even fewer budgets (see Tab. 7). Our goal is to abstract away from specific aggregation layers as well as cross-window communication approaches, and highlight the importance and contribution of the macro architecture of the Swin Transformer family. We hope our work can encourage the community to rethink the role of attention in neural architecture design, and shed a little light on future studies of general visual representation learning.

2 Background and Related Work↩︎

Highly mature and robust training recipes [15] enable standard Transformer architecture [16], [17] directly inherited from natural language processing to attain excellent performance in the image recognition task even with limited data & model sizes [18], [19]. Standard Transformer models sequence-to-sequence relationship in a pair-wise manner with minimal prior via global scaled dot-product multi-head self-attention (MHSA), which scales quadratically with the sequence length. Therefore standard Transformer suffers from the scaling problem in spatial dimensions and fails to process high-resolution inputs with varying sizes in computer vision downstream tasks.

To more efficiently apply Vision Transformers to other downstream tasks in computer vision such as object detection, instance segmentation, and scene parsing, three key issues need to be solved: (1) involving hierarchical architectures to establish multi-scale feature representations for better handling of large variations in scales. (2) reducing memory & computation costs from global MHSA to efficiently process high-resolution inputs with varying token lengths, and (3) introducing appropriate inductive biases & prior knowledge of the target task for better performance.

To mitigate the aforementioned issues,  [2], [4], [20] process features with multi-resolution stages using spatial pooling operations instead of in a columnar manner.  [1], [3] further propose to compute MHSA in weakly-overlapped or non-overlapped local windows. After that, many follow-up hierarchical local window-based Vision Transformers emerge and challenge the hegemonic position of CNN in computer vision [5], [6], [21].

To demystify the relation between CNN and hierarchical Vision Transformer, [22] study the inhomogeneous depth-wise convolution under modern training & optimization recipe from [3], and demonstrates that CNN can achieve similar competitive performance compared with the Swin Transformer family in various vision tasks. Furthermore,  [23] and  [24] study the convolution-attention hybrid architecture. Combining the strengths from both camps, convolution-attention hybrid architecture can achieve state-of-the-art performance under different resource constraints across various datasets.

Previous studies show that simple multi-layer perceptrons (MLPs) architectures are competitive with CNNs in digit recognition [25], [26], keyword spotting [27] and handwritting recognition [28]. Recently, a series of works [29][31] revisit the architecture based exclusively on columnar structured MLPs in image recognition tasks under modern training and transfer learning recipes.

As cursorily summarized in Tab. 2, there are still two “missing pieces” remain, i.e., the CNN with columnar architectures, and the MLP with hierarchical architectures.  [22] touches the former topic with the columnar architecture proposed in [32]. This manuscript conducts a primitive study to the latter one: a straightforward, simple, yet must-know model in computer vision. We argue it is inevitable to investigate the potential of hierarchical linear mapping & MLP structures now, and we hope the proposed proof-of-concept model can encourage the community to rethink the role between macro model design methodologies and specific network building blocks.

4.2 pt

Table 2: A cursory summary of macro architectures (Column) and specific aggregation layers (Row). “✔” means the architecture configuration has been comprehensively studied, while there are still two “missing pieces” remain. This manuscript gives a primitively study to hierarchical architecture with simple linear or MLP layers.
Conv MHSA Linear & MLP
Columnar “Missing Piece”
Hierarchical “Missing Piece”

3 What Makes for Hierarchical Vision Transformer?↩︎

We first briefly review the Swin Transformer family in Sec. 3.1, and then introduce the proposed in Sec. 3.2.

3.1 The Swin Architecture Family↩︎

Methodologically, Swin Transformer [3] processes high-resolution input hierarchically using multi-head self-attention (MHSA) within non-overlapped local windows. Specifically, MHSA is used as the aggregation layer to fuse content information of spatial tokens inside each window. Since the non-overlapped partition scheme lacks connection across windows, Swin Transformer proposes to use shifted-window operations between every two successive window-based MHSA layers to encourage cross-window communications. Hierarchical architecture design is also adopted to produce multi-resolution representations for better handling of large scale & size variations in visual entities.

Most successors of Swin Transformer mainly focus on replacing shifted-window operations with other kinds of cross-window communications such as spatial token shuffle [5] or information exchange based on auxiliary messager tokens [6], while keeping other components unchanged.

Overall, Swin Transformer and its variants all adopt the MHSA as the aggregation layer for spatial token fusion, and use non-overlapped window-based token mixing & cross-window communications in an alternating fashion with hierarchical representations as the macro architecture. We refer readers to  [3], [5], [6] for more details of the Swin Transformer family architectures investigated in this manuscript.

Figure 1: Pseudocode.

3.2 A Proof-of-concept Model:↩︎

Despite being greatly successful in various tasks, we question whether MHSA is the only choice to aggregate information for the Swin Transformer family. To this end, we attempt to use linear mapping, one of the simplest components in neural architecture design, as a touchstone & probe to reveal that the macro architecture (interleaved non-overlapped window-based token mixing & cross-window communications) seems to be more responsible for Swin model families’ strong performance other than specific aggregation layers such as MHSA.

7.575 pt

Table 3: Results of different -Tiny variants on ImageNet-\(1k\) image recognition benchmark.
Method Model Width Model Depth #Params. (M) FLOPs (G) Throughput (Img/s) Top-\(1\) Acc.
Swin -Tiny \(64\) \(\{2, 4, 22, 4\}\) \(24.6\) \(4.0\) \(320\) \(80.5\)
Shuffle -Tiny \(64\) \(\{2, 4, 22, 4\}\) \(24.6\) \(4.0\) \(328\) \(80.6\)
MSG -Tiny \(64\) \(\{2, 4, 22, 4\}\) \(30.6\) \(4.5\) \(380\) \(80.4\)

7.8pt

Table 4: Scaling the tiny-sized model. We use the shifted-window operation [3] as the default cross-window communication scheme.
Method Model Width Model Depth #Params. (M) FLOPs (G) Throughput (Img/s) Top-\(1\) Acc.
Swin -Tiny \(64\) \(\{2, 4, 22, 4\}\) \(24.6\) \(4.0\) \(320\) \(80.5\)
Swin -Small \(96\) \(\{2, 4, 22, 4\}\) \(54.9\) \(8.9\) \(201\) \(82.0\)
Swin -Base \(128\) \(\{2, 4, 22, 4\}\) \(97.3\) \(15.9\) \(143\) \(82.5\)

We choose three representative and publicly available instantiations from the Swin model family, i.e., Swin Transformer [3], Shuffle Transformer [5], and MSG Transformer [6]. We directly replace their window-based MHSA layers with layers described in Algorithm 1, and align other components and configurations with Swin Transformer [3].

Specifically, layer takes partitioned image features with shape (\(\mathtt{B, C, ws^2}\)) as inputs, where \(\mathtt{B}\) is the total number of partitioned windows, \(\mathtt{C}\) is the number of channels and \(\mathtt{ws}\) is the window size. Since directly performing dense linear mapping from flattened inputs with shape (\(\mathtt{B, C \times ws^2}\)) to outputs with the same shape (\(\mathtt{B, C \times ws^2}\)) is computationally infeasible, we divide the input tensor to several groups where each group has \(\mathtt{ws^2}\) tokens with \(\mathtt{gs}\) channels (i.e., the group size is \(\mathtt{gs}\)). To further reduce FLOPs and parameters budgets, linear mappings are performed along tokens’ height and width dimensions separately, which is similar to the merit of [12] and [33]. Therefore, the number of inputs for linear mapping is only \(\mathtt{gs \times ws}\). Finally, the transformed representations along two axes are fused via element-wise addition followed by a point-wise linear projection layer.

In our default instantiation, the weights and biases of \(\mathtt{lin\_map\_h}\)() and \(\mathtt{lin\_map\_w}\)() in Alg. 1 are shared across different groups. Linear mappings with separate parameters for different groups are denoted as depth-wise linear mapping (“DW Linear” in Tab. 1 and Tab. 8) in this manuscript. Our controlled experiments demonstrate that using separate weight cannot bring further improvements in linear mapping given similar model sizes, which echos the observation in previous multi-head v.s. single-head self-attention studies [34], [35].

To some extent, is one of the simplest possible instantiations of architectures with interleaved non-overlapped window-based token mixing & cross-window communications scheme. Despite being simple, the layer is more lightweight than the MHSA layer. Therefore the lack in capacity compared with MHSA can be compensated by deeper or wider architecture design given similar FLOPs & parameters budgets, and the resulting architecture is still able to achieve competitive performance (Sec. 4.2).

It is noteworthy that the proposed layer enables a fully linear mapping & MLP architecture to directly process high-resolution input images with arbitrary shapes. This property allows MLP-like architectures to be easily transferred to different computer vision downstream tasks, which is lack in previous studies [29], [30], [36]. In Tab. 6 we demonstrate that the transfer learning performance of is on a par with Swin Transformer in object detection and instance segmentation even with relatively worse supervised pre-trained representations on ImageNet-\(1k\) [7].

Overall, the merit of is to abstract away from specific aggregation layers as well as cross-window communication schemes, and highlights the importance of the macro architecture, which seems overlooked in previous research on hierarchical Vision Transformer.

4 Experiments↩︎

We first give the general experimental setup in Sec. 4.1, and then report the pre-training, scaling, and transfer learning performance of in Sec. 4.2. The model analysis and ablation study are finally conducted in Sec. 4.3.

4.1 Setup↩︎

4.1.0.1 Pre-train Settings.

The experiments are conducted on the public available codebase of [3], [5], [6] and the \(\mathtt{timm}\) library [37].

During pre-training, all models are trained and evaluated on ImageNet-\(1k\) [7] benchmark following the setup in [3], [15]. We train models with \(300\) epochs on ImageNet-\(1k\) for main results. For model analysis and ablation study, we study different content aggregation layers with model width and model depth3 same as Swin Transformer-Tiny (i.e., model width \(= 96\), model depth \(= \{2, 2, 6, 2\}\)) using \(200\) epochs training schedule on ImageNet-\(1k\) unless specified.

The input resolution is \(224 \times 224\) and the window size is \(7 \times 7\) for all models in all experiments. For a clearer study of different aggregation layers in non-overlapped windows, we remove all densely slid conv-layers in the network stem and each block of [5] in this manuscript.

Model throughput data during inference are measured using a single Titan Xp GPU with batch size \(= 64\) with input resolution \(= 224 \times 224\). Model FLOPs during inference are measured with batch size \(= 1\) with input resolution \(= 224 \times 224\).

16.0 pt

Table 5: Comparisons with other MLP-like architectures on ImageNet-\(1k\) image recognition benchmark.
Method Input Resolution #Params. (M) FLOPs (G) Top-\(1\) Acc.
MLP-Mixer-B/16 [29] \(224\) \(59\) \(12.7\) \(77.3\)
ResMLP-24 [30] \(224\) \(30\) \(6.0\) \(79.4\)
ResMLP-36 [30] \(224\) \(45\) \(8.9\) \(79.7\)
gMLP-S [36] \(224\) \(20\) \(4.5\) \(79.6\)
GFNet-S [38] \(224\) \(25\) \(4.5\) \(80.0\)
S\(^2\)-MLP-wide [39] \(224\) \(71\) \(14.0\) \(80.0\)
Swin-Mixer-T/D6 [3] \(256\) \(23\) \(4.0\) \(79.7\)
Swin -Tiny (Ours) \(224\) \(25\) \(4.0\) \(\mathbf{80.5}\)
GFNet-B [38] \(224\) \(43\) \(7.9\) \(80.7\)
S\(^2\)-MLP-deep [39] \(224\) \(51\) \(10.5\) \(80.7\)
Swin-Mixer-B/D24 [3] \(256\) \(61\) \(10.4\) \(81.3\)
gMLP-B [36] \(224\) \(73\) \(15.8\) \(81.6\)
Swin -Small (Ours) \(224\) \(55\) \(8.9\) \(\mathbf{82.0}\)

4.2pt

Table 6: Transfer learning performance of -Tiny on MS-COCO object detection and instance segmentation benchmarks using the Mask R-CNN framework [40] with training & testing configurations from [3].
Method #Params. (M) FLOPs (G) Pre-train Top-\(1\) AP\(^{bb}\) AP\(^{bb}_{50}\) AP\(^{bb}_{75}\) AP\(^{m}\) AP\(^{m}_{50}\) AP\(^{m}_{75}\)
Swin Transformer-Tiny [3] \(48\) \(267\) \(81.3\) \(43.7\) \(66.6\) \(47.7\) \(39.8\) \(63.3\) \(42.7\)
Swin -Tiny (Ours) \(44\) \(253\) \(80.5\) \(43.8\) \(66.2\) \(47.8\) \(39.6\) \(62.9\) \(42.4\)

4.1.0.2 Transfer Learning Settings.

The experiments are conducted on the public available codebase of [3] and the \(\mathtt{mmdetection}\) library [41].

We study the transfer learning performance of ImageNet-\(1k\) \(300\)-epoch supervised pre-trained models in the challenging MS-COCO [42] object detection and instance segmentation benchmarks using the Mask R-CNN [40] framework. We fine-tune the pre-trained with standard \(1 \times\) schedule [40] on MS-COCO \(\mathtt{train}\) split and report the transfer learning results on MS-COCO \(\mathtt{val}\) split following the training and testing configurations from [3].

Model FLOPs during inference are measured with batch size \(= 1\) and input resolution \(= 1280 \times 800\).

4.2 Main Results↩︎

4.2.0.1 Results of on ImageNet-1k.

As shown in Tab. 3, given limited FLOPs and parameters budgets, tiny-sized models are able to achieve competitive performance on ImageNet-\(1k\) [7] image recognition benchmark with three different cross-window communication paradigm, i.e., shifted-window [3], spatial token shuffle [5], and auxiliary messager tokens exchange [6].

Along with the results in Tab. 1, it is noteworthy that (1) shifted-window, spatial token shuffle, and auxiliary messager tokens exchange all give similar strong results under the same aggregation layer, and moreover, (2) different aggregation layers are all quite competitive under the same cross-window token mixing approach.

All these results support our proposal: the macro architecture of the Swin model family, other than specific aggregation layers or specific means of cross-window communication, may be more responsible for its strong performance.

4.8pt

Table 7: Wider v.s. deeper macro structure for .
Method Model Width Model Depth #Params. (M) FLOPs (G) Throughput (Img/s) Top-\(1\)
Swin Transformer-Tiny [3] \(96\) \(\{2, 2, 6, 2\}\) \(28.3\) \(4.5\) \(378\) \(80.5\)
Swin -Tiny (Baseline) \(96\) \(\{2, 2, 6, 2\}\) \(22.6\) \(3.4\) \(410\) \(78.8\)
Swin -Tiny (Wide) \(112\) \(\{2, 2, 6, 2\}\) \(30.6\) \(4.6\) \(343\) \(79.8\)
Swin -Tiny (Deep) \(64\) \(\{2, 4, 22, 4\}\) \(24.6\) \(4.0\) \(320\) \(79.7\)

3.pt

Table 8: Linear v.s. depth-wise linear in .
#Group Agg. Layer #Params. FLOPs Throughput Top-\(1\)
Linear \(22.0\) \(78.8\)
DW Linear \(28.4\) \(78.9\)
Linear \(21.8\) \(78.7\)
DW Linear \(26.2\) \(78.9\)

4.8pt

Table 9: Linear mapping v.s. MLP in .
Agg. Layer #Params. FLOPs Throughput Top-\(1\)
MLP \(22.8\) \(3.4\) \(357\) \(79.0\)
Linear Mapping \(22.0\) \(3.3\) \(413\) \(78.8\)

4.2.0.2 Scaling -Tiny.

There is little literature available on the scaling properties of hierarchical MLP-like models. Here we demonstrate that the tiny-sized model is scalable.

We choose Swin -Tiny as the model scaling start point. Width scaling [43], [44] is adopted while the model depth and input resolution are kept unchanged. The training and testing configurations are aligned with [3]. Results in Tab. 4 show that both -Small & -Base can be successfully optimized, converged, and consistently benefit from more computations and larger model size.

Finding appropriate model scaling laws tailored for as well as other MLP variants is non-trivial, since the model complexity of MLP-like architectures is a linear combination of two different parts: (1) the content aggregation layer part for depth-wise or group-wise spatial token mixing only, and (2) the feed-forward network part for point-wise or token-wise feature transformation only, which is different from the complexity of CNNs. Consequently, previous successful practice in CNNs scaling cannot apply to in a principled way and can be only verified one-by-one experimentally. We leave the study of sophisticated model scaling laws on for future work.

4.2.0.3 Comparisons with Other MLP Variants.

We summarize some recently proposed MLP-like architectures in Tab. 5. The proposed demonstrates superior performance with fewer FLOPs and parameters. The window partitioning operation and hierarchical representations introduce \(2\mathrm{D}\) locality bias and invariance to . Therefore it is not a surprise that is more efficient and competitive than global & columnar MLP architectures such as MLP-Mixer and ResMLP by leveraging these design priors.

Swin-Mixer is a recently proposed MLP-like architecture with hierarchical representations based on the Swin Transformer family. We demonstrate that both the tiny-sized and small-sized can outperform the corresponding Swin-Mixer counterparts even with fewer computation budgets.

4.2.0.4 Transfer Learning Performance of .

There is little literature available on the transferability of MLP-like architecture to downstream dense prediction tasks such as object detection and instance segmentation. Most available MLP variants using global kernels for spatial token mixing, therefore their spatial kernel sizes are fixed and highly correlated to the input resolution during pre-training, which largely limits the applications on high-resolution inputs with varying shapes and sizes during transfer learning.

The proposed can naturally overcome this issue via window-based spatial token mixing inherited from the Swin model family. is able to directly process arbitrary resolutions zero-padded to be divisible by the window size.

Results in Tab. 6 demonstrate that the transfer learning performance of is on a par with Swin Transformer in MS-COCO object detection and instance segmentation benchmarks even using relatively worse supervised pre-trained representations on ImageNet-\(1k\). These promising results indicate that could be able to better leverage the pre-trained representations for transfer learning.

4.3 Analysis and Ablation Study↩︎

In this section, we study the impact of model width & model depth configurations, weight sharing properties of linear mapping layers, as well as the number of groups. Overall, we conclude that is quite robust to different model choices and configurations thanks to the strong macro architecture.

4.3.0.1 Going Wider or Deeper?

We study the model width and model depth configurations for the tiny-sized model. A high-performance tiny-sized model can also be served as a promising start point for model scaling.

Since a single layer is much lighter than a single window-based MHSA layer from [3] in terms of both parameters and computations, we need to adjust the model width and depth of to align with the budgets for Swin Transformer-Tiny. The resulting models are termed as Swin -Tiny (Wide) and Swin -Tiny (Deep).

As shown in Tab. 7, the wider model seems to be more speed friendly while the deeper model is a lot more parameters & FLOPs efficient. We choose Swin -Tiny (Deep) as our default tiny-sized model instantiation.

4.3.0.2 Linear or Depth-wise Linear?

In this manuscript, depth-wise linear (DW Linear) layers refer to linear mapping with separate or non-shared weights & biases for each group. Therefore the model parameters increase while the theoretical FLOPs are kept unchanged when using DW linear layers instead of shared linear layers. As shown in Tab. 8, DW linear layers bring no significant improvement, which echos the observation in previous multi-head v.s. single-head self-attention studies [34], [35] to some extent. Therefore we choose to share linear weights & biases across different groups as our default instantiation for better parameters efficiency.

4.3.0.3 Linear Mapping or MLP?

In Tab. 9, we investigate the impact of using simple linear mapping layers and more sophisticated MLP layers for content aggravation inside each non-overlapped window. The results suggest that using MLPs with intermediate \(\mathtt{GELU}\)() activation functions [45] cannot bring further improvements.

This observation in our hierarchical is somewhat in line with the findings from the columnar counterpart [30], where ResMLP models also adopt simple patch-to-patch (or token-to-token) linear transformations instead of MLP layers in MLP-Mixer [29] for cross-patch communications.

4.3.0.4 Number of Groups (#Group) for Linear Layers.

In Tab. 10, we study the impact of different numbers of groups (#Groups) in linear layers. The weights & biases of linear layers are shared across groups. We find setting #Groups too large or too small is harmful to performance, while other choices yield similar results. In this manuscript, #Groups \(=32\) (i.e., \(\mathtt{gs} = 3 \times 2^{({\#}\mathtt{stage} - 1)}\) in Alg. 1) is chosen as the default configuration for all-sized models.

1.8pt

Table 10: Number of groups in .
#Group \(\mathtt{gs}\) in Alg. 1 #Params. FLOPs Throughput Top-\(1\)
\(96\) \(1*2^{({\#}\mathtt{stage}-1)}\) \(21.8\) \(3.3\) \(413\) \(78.4\)
\(48\) \(2*2^{({\#}\mathtt{stage}-1)}\) \(21.8\) \(3.3\) \(416\) \(78.7\)
\(32\) \(3*2^{({\#}\mathtt{stage}-1)}\) \(22.0\) \(3.3\) \(413\) \(78.8\)
\(16\) \(6*2^{({\#}\mathtt{stage}-1)}\) \(22.6\) \(3.4\) \(410\) \(78.8\)
\(8\) \(12*2^{({\#}\mathtt{stage}-1)}\) \(25.0\) \(3.4\) \(420\) \(78.6\)

5 Conclusion↩︎

In this manuscript, we raise a crucial question that seems overlooked in previous research: “What Makes for Hierarchical Vision Transformer?”, and attempt to give an answer: the macro architecture design methodology may be more important than specific network layers and components. To this end, a proof-of-concept model named with embarrassingly lightweight & simple content aggregation layers is proposed as a touchstone or probe to support and validate our proposal. As a hierarchical MLP-like architecture, along with its variants also enables a fully linear mapping & MLP architecture to directly process high-resolution input images with arbitrary shapes, which makes it possible for investigating the transferability of linear mapping & MLP architectures on various computer vision downstream tasks other than image recognition such as object detection and scene parsing. We hope this manuscript can encourage the community to rethink the design of Vision Transformer, and shed a little light on future studies of general visual representation learning.

References↩︎

[1]
Vaswani, A.; Ramachandran, P.; Srinivas, A.; Parmar, N.; Hechtman, B.; and Shlens, J. 2021. Scaling local self-attention for parameter efficient visual backbones. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 12894–12904.
[2]
Wang, W.; Xie, E.; Li, X.; Fan, D.-P.; Song, K.; Liang, D.; Lu, T.; Luo, P.; and Shao, L. 2021. Pyramid vision transformer: A versatile backbone for dense prediction without convolutions. arXiv preprint arXiv:2102.12122.
[3]
Liu, Z.; Lin, Y.; Cao, Y.; Hu, H.; Wei, Y.; Zhang, Z.; Lin, S.; and Guo, B. 2021. Swin transformer: Hierarchical vision transformer using shifted windows. arXiv preprint arXiv:2103.14030.
[4]
Fan, H.; Xiong, B.; Mangalam, K.; Li, Y.; Yan, Z.; Malik, J.; and Feichtenhofer, C. 2021. Multiscale vision transformers. arXiv preprint arXiv:2104.11227.
[5]
Huang, Z.; Ben, Y.; Luo, G.; Cheng, P.; Yu, G.; and Fu, B. 2021. Shuffle Transformer: Rethinking Spatial Shuffle for Vision Transformer. arXiv preprint arXiv:2106.03650.
[6]
Fang, J.; Xie, L.; Wang, X.; Zhang, X.; Liu, W.; and Tian, Q. 2021. MSG-Transformer: Exchanging Local Spatial Information by Manipulating Messenger Tokens. arXiv preprint arXiv:2105.15168.
[7]
Russakovsky, O.; Deng, J.; Su, H.; Krause, J.; Satheesh, S.; Ma, S.; Huang, Z.; Karpathy, A.; Khosla, A.; Bernstein, M.; et al. 2015. Imagenet large scale visual recognition challenge. IJCV.
[8]
Krizhevsky, A.; Sutskever, I.; and Hinton, G. E. 2012. Imagenet classification with deep convolutional neural networks. NeurIPS.
[9]
Simonyan, K.; and Zisserman, A. 2014. Very deep convolutional networks for large-scale image recognition. arXiv preprint arXiv:1409.1556.
[10]
He, K.; Zhang, X.; Ren, S.; and Sun, J. 2016. Deep Residual Learning for Image Recognition. In CVPR.
[11]
Wang, X.; Girshick, R.; Gupta, A.; and He, K. 2018. Non-local neural networks. In Proceedings of the IEEE conference on computer vision and pattern recognition, 7794–7803.
[12]
Huang, Z.; Wang, X.; Huang, L.; Huang, C.; Wei, Y.; and Liu, W. 2019. Ccnet: Criss-cross attention for semantic segmentation. In ICCV.
[13]
Tu, Z.; Chen, X.; Yuille, A. L.; and Zhu, S.-C. 2005. Image parsing: Unifying segmentation, detection, and recognition. IJCV.
[14]
Tighe, J.; Niethammer, M.; and Lazebnik, S. 2014. Scene parsing with object instances and occlusion ordering. In CVPR.
[15]
Touvron, H.; Cord, M.; Douze, M.; Massa, F.; Sablayrolles, A.; and Jégou, H. 2020. Training data-efficient image transformers & distillation through attention. arXiv preprint arXiv:2012.12877.
[16]
Vaswani, A.; Shazeer, N.; Parmar, N.; Uszkoreit, J.; Jones, L.; Gomez, A. N.; Kaiser, L.; and Polosukhin, I. 2017. Attention is all you need. arXiv preprint arXiv:1706.03762.
[17]
Dosovitskiy, A.; Beyer, L.; Kolesnikov, A.; Weissenborn, D.; Zhai, X.; Unterthiner, T.; Dehghani, M.; Minderer, M.; Heigold, G.; Gelly, S.; et al. 2020. An image is worth 16x16 words: Transformers for image recognition at scale. arXiv preprint arXiv:2010.11929.
[18]
Yuan, L.; Chen, Y.; Wang, T.; Yu, W.; Shi, Y.; Jiang, Z.; Tay, F. E.; Feng, J.; and Yan, S. 2021. Tokens-to-token vit: Training vision transformers from scratch on imagenet. arXiv preprint arXiv:2101.11986.
[19]
Han, K.; Xiao, A.; Wu, E.; Guo, J.; Xu, C.; and Wang, Y. 2021. Transformer in transformer. arXiv preprint arXiv:2103.00112.
[20]
Heo, B.; Yun, S.; Han, D.; Chun, S.; Choe, J.; and Oh, S. J. 2021. Rethinking spatial dimensions of vision transformers. arXiv preprint arXiv:2103.16302.
[21]
Zhang, Z.; Zhang, H.; Zhao, L.; Chen, T.; and Pfister, T. 2021. Aggregating nested transformers. arXiv preprint arXiv:2105.12723.
[22]
Han, Q.; Fan, Z.; Dai, Q.; Sun, L.; Cheng, M.-M.; Liu, J.; and Wang, J. 2021. Demystifying Local Vision Transformer: Sparse Connectivity, Weight Sharing, and Dynamic Weight. arXiv preprint arXiv:2106.04263.
[23]
Xu, W.; Xu, Y.; Chang, T.; and Tu, Z. 2021. Co-scale conv-attentional image transformers. arXiv preprint arXiv:2104.06399.
[24]
Dai, Z.; Liu, H.; Le, Q. V.; and Tan, M. 2021. CoAtNet: Marrying Convolution and Attention for All Data Sizes. arXiv preprint arXiv:2106.04803.
[25]
Cireşan, D. C.; Meier, U.; Gambardella, L. M.; and Schmidhuber, J. 2012. Deep big multilayer perceptrons for digit recognition. In Neural networks: tricks of the trade, 581–598. Springer.
[26]
Simard, P. Y.; Steinkraus, D.; Platt, J. C.; et al. 2003. Best practices for convolutional neural networks applied to visual document analysis. In Icdar.
[27]
Chatelain, C. 2006. Extraction de séquences numériques dans des documents manuscrits quelconques. Ph.D. thesis, Université de Rouen.
[28]
Bluche, T. 2015. Deep neural networks for large vocabulary handwritten text recognition. Ph.D. thesis, Paris 11.
[29]
Tolstikhin, I.; Houlsby, N.; Kolesnikov, A.; Beyer, L.; Zhai, X.; Unterthiner, T.; Yung, J.; Keysers, D.; Uszkoreit, J.; Lucic, M.; et al. 2021. Mlp-mixer: An all-mlp architecture for vision. arXiv preprint arXiv:2105.01601.
[30]
Touvron, H.; Bojanowski, P.; Caron, M.; Cord, M.; El-Nouby, A.; Grave, E.; Joulin, A.; Synnaeve, G.; Verbeek, J.; and Jégou, H. 2021. Resmlp: Feedforward networks for image classification with data-efficient training. arXiv preprint arXiv:2105.03404.
[31]
Guo, M.-H.; Liu, Z.-N.; Mu, T.-J.; and Hu, S.-M. 2021. Beyond self-attention: External attention using two linear layers for visual tasks. arXiv preprint arXiv:2105.02358.
[32]
Yuan, L.; Hou, Q.; Jiang, Z.; Feng, J.; and Yan, S. 2021. Volo: Vision outlooker for visual recognition. arXiv preprint arXiv:2106.13112.
[33]
Wang, H.; Zhu, Y.; Green, B.; Adam, H.; Yuille, A.; and Chen, L.-C. 2020. Axial-deeplab: Stand-alone axial-attention for panoptic segmentation. In European Conference on Computer Vision.
[34]
Liu, L.; Liu, J.; and Han, J. 2021. Multi-head or Single-head? An Empirical Comparison for Transformer Training. arXiv preprint arXiv:2106.09650.
[35]
Michel, P.; Levy, O.; and Neubig, G. 2019. Are sixteen heads really better than one? arXiv preprint arXiv:1905.10650.
[36]
Liu, H.; Dai, Z.; So, D. R.; and Le, Q. V. 2021. Pay Attention to MLPs. arXiv preprint arXiv:2105.08050.
[37]
Wightman, R. 2019. PyTorch Image Models. https://git.io/fjVdB.
[38]
Rao, Y.; Zhao, W.; Zhu, Z.; Lu, J.; and Zhou, J. 2021. Global filter networks for image classification. arXiv preprint arXiv:2107.00645.
[39]
Yu, T.; Li, X.; Cai, Y.; Sun, M.; and Li, P. 2021. S \(^2\)-MLP: Spatial-Shift MLP Architecture for Vision. arXiv preprint arXiv:2106.07477.
[40]
He, K.; Gkioxari, G.; Dollár, P.; and Girshick, R. B. 2017. Mask R-CNN. In ICCV.
[41]
Chen, K.; Wang, J.; Pang, J.; Cao, Y.; Xiong, Y.; Li, X.; Sun, S.; Feng, W.; Liu, Z.; Xu, J.; Zhang, Z.; Cheng, D.; Zhu, C.; Cheng, T.; Zhao, Q.; Li, B.; Lu, X.; Zhu, R.; Wu, Y.; Dai, J.; Wang, J.; Shi, J.; Ouyang, W.; Loy, C. C.; and Lin, D. 2019. : Open MMLab Detection Toolbox and Benchmark. arXiv preprint arXiv:1906.07155.
[42]
Lin, T.; Maire, M.; Belongie, S. J.; Hays, J.; Perona, P.; Ramanan, D.; Dollár, P.; and Zitnick, C. L. 2014. Microsoft COCO: Common Objects in Context. In ECCV.
[43]
Zagoruyko, S.; and Komodakis, N. 2016. Wide residual networks. arXiv preprint arXiv:1605.07146.
[44]
Howard, A. G.; Zhu, M.; Chen, B.; Kalenichenko, D.; Wang, W.; Weyand, T.; Andreetto, M.; and Adam, H. 2017. Mobilenets: Efficient convolutional neural networks for mobile vision applications. arXiv preprint arXiv:1704.04861.
[45]
Hendrycks, D.; and Gimpel, K. 2016. Gaussian error linear units (gelus). arXiv preprint arXiv:1606.08415.

  1. Preprint. A part of this work was done when Yuxin Fang was interning at Horizon Robotics mentored by Rui Wu.↩︎

  2. Xinggang Wang is the corresponding author.↩︎

  3. In this manuscript, we define model width is the number of channels in the first stage of the network, and model depth is the number of content aggregation layers in each stage of the network.↩︎