When Shift Operation Meets Vision Transformer: An Extremely Simple Alternative to Attention Mechanism

26 Jan 2022  ·  Guangting Wang, Yucheng Zhao, Chuanxin Tang, Chong Luo, Wenjun Zeng ·

Attention mechanism has been widely believed as the key to success of vision transformers (ViTs), since it provides a flexible and powerful way to model spatial relationships. However, is the attention mechanism truly an indispensable part of ViT? Can it be replaced by some other alternatives? To demystify the role of attention mechanism, we simplify it into an extremely simple case: ZERO FLOP and ZERO parameter. Concretely, we revisit the shift operation. It does not contain any parameter or arithmetic calculation. The only operation is to exchange a small portion of the channels between neighboring features. Based on this simple operation, we construct a new backbone network, namely ShiftViT, where the attention layers in ViT are substituted by shift operations. Surprisingly, ShiftViT works quite well in several mainstream tasks, e.g., classification, detection, and segmentation. The performance is on par with or even better than the strong baseline Swin Transformer. These results suggest that the attention mechanism might not be the vital factor that makes ViT successful. It can be even replaced by a zero-parameter operation. We should pay more attentions to the remaining parts of ViT in the future work. Code is available at github.com/microsoft/SPACH.

PDF Abstract

Results from the Paper


Task Dataset Model Metric Name Metric Value Global Rank Result Benchmark
Semantic Segmentation ADE20K Shift-T Validation mIoU 46.3 # 169
Semantic Segmentation ADE20K Shift-B (UperNet) Validation mIoU 49.2 # 128
Semantic Segmentation ADE20K Shift-B Validation mIoU 47.9 # 148
Semantic Segmentation ADE20K Shift-S Validation mIoU 47.8 # 149
Object Detection COCO minival Shift-T APM 42.3 # 67
Image Classification ImageNet Shift-T Top 1 Accuracy 81.7% # 563
Number of params 28M # 629
GFLOPs 4.4 # 208
Image Classification ImageNet Shift-S Top 1 Accuracy 82.8% # 453
Number of params 50M # 725
GFLOPs 8.5 # 278
Image Classification ImageNet Shift-B Top 1 Accuracy 83.3% # 403
Number of params 88M # 832
GFLOPs 15.2 # 339

Methods