Shuffle Transformer

Very recently, window-based Transformers, which computed self-attention within non-overlapping local windows, demonstrated promising results on image classification, semantic segmentation, and object detection. However, less study has been devoted to the cross-window connection which is the key element to improve the representation ability. Shuffle Transformer revisit the spatial shuffle as an efficient way to build connections among windows, which is highly efficient and easy to implement by modifying two lines of code. Furthermore, the depth-wise convolution is introduced to complement the spatial shuffle for enhancing neighbor-window connections. The proposed architectures achieve excellent performance on a wide range of visual tasks including image-level classification, object detection, and semantic segmentation.


  • PyTorch==1.7.1
  • torchvision==0.8.2
  • timm==0.3.2

The Apex is optional for faster training speed.

git clone
cd apex
pip install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./

Other Requirements

pip install opencv-python== termcolor==1.1.0 yacs==0.1.8
pip install einops

Main Results

Results on ImageNet-1K
name [email protected] #params FLOPs Throughputs(Images/s) Weights
Shuffle-T 82.4 28M 4.6G 791 google drive
Shuffle-S 83.6 50M 8.9G 450 google drive
Shuffle-B 84.0 88M 15.6 279 google drive


For classification on ImageNet-1K, to train from scratch, run:

python -m torch.distributed.launch --nproc_per_node <num-of-gpus-to-use> \ 
--cfg <config-file> --data-path <imagenet-path> [--batch-size <batch-size-per-gpu> --output <output-directory>]

To evaluate, run:

python -m torch.distributed.launch --nproc_per_node <num-of-gpus-to-use> --eval \
--cfg <config-file> --resume <checkpoint> --data-path <imagenet-path> 

In progress

  • Semantic Segmentation
  • Instance Segmentation

Citing Shuffle Transformer

 title={Shuffle Transformer: Rethinking Spatial Shuffle for Vision Transformer},
 author={Huang, Zilong and Ben, Youcheng and Luo, Guozhong and Cheng, Pei and Yu, Gang and Fu, Bin},
 journal={arXiv preprint arXiv:2106.03650},


Thanks to open-source implementation of Swin-Transformer.