This is an official implementation for "AS-MLP: An Axial Shifted MLP Architecture for Vision".

Related tags

Deep Learning AS-MLP
Overview

AS-MLP architecture for Image Classification

Model Zoo

Image Classification on ImageNet-1K

Network Resolution Top-1 (%) Params FLOPs Throughput (image/s) model
AS-MLP-T 224x224 81.3 28M 4.4G 1047 onedrive
AS-MLP-S 224x224 83.1 50M 8.5G 619 onedrive
AS-MLP-B 224x224 83.3 88M 15.2G 455 onedrive

Usage

Install

  • Clone this repo:
git clone https://github.com/svip-lab/AS-MLP
cd AS-MLP
  • Create a conda virtual environment and activate it:
conda create -n asmlp python=3.7 -y
conda activate asmlp
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=10.1 -c pytorch
  • Install timm==0.3.2:
pip install timm==0.3.2
  • Install cupy-cuda101:
pip install cupy-cuda101
  • Install Apex:
git clone https://github.com/NVIDIA/apex
cd apex
pip install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
  • Install other requirements:
pip install opencv-python==4.4.0.46 termcolor==1.1.0 yacs==0.1.8

Evaluation

To evaluate a pre-trained AS-MLP on ImageNet val, run:

bash train_scripts/test.sh

Training from scratch

To train a AS-MLP on ImageNet from scratch, run:

bash train_scripts/train.sh

You can easily reproduce our results. Enjoy!

Throughput

To measure the throughput, run:

bash train_scripts/get_throughput.sh

Citation

If this project is helpful for you, you can cite our paper:

@article{Lian_2021_ASMLP,
  author = {Lian, Dongze and Yu, Zehao and Sun, Xing and Gao, Shenghua},
  title = {AS-MLP: An Axial Shifted MLP Architecture for Vision},
  journal={arXiv preprint arXiv:2107.08391},
  year = {2021}
}

Acknowledgement

The code is built upon Swin-Transformer

Comments
  • Error when using --cache-mode part

    Error when using --cache-mode part

    It seems that the code cannot generate "./train_pkl/samples_bytes_0.pkl" successfully.

    The first running, generate pkl, but return error:

    ./train_pkl/samples_bytes_0.pkl global_rank 0 cached 0/1281167 takes 0.00s per block global_rank 0 cached 128116/1281167 takes 21.24s per block global_rank 0 cached 256232/1281167 takes 19.01s per block global_rank 0 cached 384348/1281167 takes 18.36s per block global_rank 0 cached 512464/1281167 takes 29.66s per block global_rank 0 cached 640580/1281167 takes 35.94s per block global_rank 0 cached 768696/1281167 takes 36.32s per block global_rank 0 cached 896812/1281167 takes 35.54s per block global_rank 0 cached 1024928/1281167 takes 37.19s per block global_rank 0 cached 1153044/1281167 takes 46.55s per block global_rank 0 cached 1281160/1281167 takes 50.39s per block Traceback (most recent call last): File "/home/ma-user/anaconda3/envs/Pytorch-1.4.0/lib/python3.6/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/home/ma-user/anaconda3/envs/Pytorch-1.4.0/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/ma-user/anaconda3/envs/Pytorch-1.4.0/lib/python3.6/site-packages/torch/distributed/launch.py", line 260, in main() File "/home/ma-user/anaconda3/envs/Pytorch-1.4.0/lib/python3.6/site-packages/torch/distributed/launch.py", line 256, in main cmd=cmd) subprocess.CalledProcessError: Command '['/home/ma-user/anaconda3/envs/Pytorch-1.4.0/bin/python', '-u', 'main.py', '--local_rank=0', '--cfg', 'configs/as_base_patch4_shift5_224.yaml', '--data-path', '/cache/imagenet/imagenet/', '--eval', '--resume', '/cache/model/asmlp_base_patch4_shift5_224.pth', '--moxfile', '0']' died with <Signals.SIGKILL: 9>.

    The second running, pkl contain nothing, so the error occurs:

    ./train_pkl/samples_bytes_0.pkl Traceback (most recent call last): File "main.py", line 349, in main(config) File "main.py", line 78, in main dataset_train, dataset_val, data_loader_train, data_loader_val, mixup_fn = build_loader(config) File "/home/ma-user/work/AS-MLP-main/data/build.py", line 17, in build_loader dataset_train, config.MODEL.NUM_CLASSES = build_dataset(is_train=True, config=config) File "/home/ma-user/work/AS-MLP-main/data/build.py", line 80, in build_dataset cache_mode=config.DATA.CACHE_MODE if is_train else 'part') File "/home/ma-user/work/AS-MLP-main/data/cached_image_folder.py", line 250, in init cache_mode=cache_mode) File "/home/ma-user/work/AS-MLP-main/data/cached_image_folder.py", line 122, in init self.init_cache() File "/home/ma-user/work/AS-MLP-main/data/cached_image_folder.py", line 137, in init_cache self.samples = pickle.load(handle) EOFError: Ran out of input Traceback (most recent call last): File "/home/ma-user/anaconda3/envs/Pytorch-1.4.0/lib/python3.6/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/home/ma-user/anaconda3/envs/Pytorch-1.4.0/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/ma-user/anaconda3/envs/Pytorch-1.4.0/lib/python3.6/site-packages/torch/distributed/launch.py", line 260, in main() File "/home/ma-user/anaconda3/envs/Pytorch-1.4.0/lib/python3.6/site-packages/torch/distributed/launch.py", line 256, in main cmd=cmd) subprocess.CalledProcessError: Command '['/home/ma-user/anaconda3/envs/Pytorch-1.4.0/bin/python', '-u', 'main.py', '--local_rank=0', '--cfg', 'configs/as_base_patch4_shift5_224.yaml', '--data-path', '/cache/imagenet/imagenet/', '--eval', '--resume', '/cache/model/asmlp_base_patch4_shift5_224.pth', '--moxfile', '0']' returned non-zero exit status 1.

    opened by HantingChen 9
  • Can you provide .so compiling setting?

    Can you provide .so compiling setting?

    Like many projects, they would provide torch cuda extensions and a setup.py to compile and generate .so file so that they can be loaded and used. Could you provide such method to use as_shift op?

    opened by laisimiao 5
  • Reproduce the accuracy in paper

    Reproduce the accuracy in paper

    Hello, thanks for sharing your work. We have tride the code on AS-MLP-T, and only get 81.13/81.06 in two seperate experiments. Are there any settings needed to be modified?

    opened by Gaffey 4
  • Errror when using train_asmlp_b.sh

    Errror when using train_asmlp_b.sh

    When using train_asmlp_b.sh, the above error occurs:

    File "/home/ma-user/work/AS-MLP-main/models/as_mlp.py", line 165, in forward x = shortcut + self.drop_path(x) File "/home/ma-user/anaconda3/envs/Pytorch-1.4.0/lib/python3.6/site-packages/apex/amp/wrap.py", line 58, in wrapper return orig_fn(*new_args, **kwargs) RuntimeError: The size of tensor a (56) must match the size of tensor b (60) at non-singleton dimension 3

    opened by HantingChen 3
  • Question on the Shift CUDA implementation.

    Question on the Shift CUDA implementation.

    Thanks for sharing such a simple yet effective backbone work~

    When I run the code, I find no noticeable runtime difference between using the shift_cuda.py and using Algorithm 1 in the paper with Pytorch itself.

    Do I miss something to activate the CUDA acceleration?

    In fact, I copy part of the core codes in this repo and integrate the codes to the Swin Transformer, instead of running this repo directly.

    Could you please help me with this problem? Thanks~

    opened by XiaoqiangZhou 2
  • Training strategy on Imagenet

    Training strategy on Imagenet

    Hello! Thank you for your wonderful job! it is said that as-mlp uses the same training strategy in Swin Transformer, I want to know to what extend the work use the same strategy ? For example, does as-mlp use Mixup、Cutmix?
    I saw there exists codes for mixup in function build_loader which requires config.AUG.MIXUP, but I didn't find config.AUG in the config file for models. I want to know the detailed training setting for your models, may you do the favor for me?

    opened by Ga-Lee 2
  • Credit to involution

    Credit to involution

    The CUDA kernel of basic op seems to be borrowed from https://github.com/d-li14/involution, especially implied by https://github.com/svip-lab/AS-MLP/blob/main/models/shift_cuda.py#L169.

    Please consider properly giving credit to the involution repo and citing us. Thanks.

    opened by d-li14 2
  • Some questions about the code

    Some questions about the code

    image Hi, I have a few questions about the dimensions in yourt code.

    • Is your input dimension format like B C H W, eg, 1, 3, 224, 224?

    • If so, I suppose the dim in layernorm you initialized is C. when I run this, I got an error like Given normalized_shape=[2304], expected input with shape [*, 2304], but got input of size[8, 2304, 8, 8]

    • And also, how do you get the shape of nW*B, window_size*window_size, C after axis shift?

    Thank you

    opened by Shaw95 2
  • Opinion for Fast PatchMerging Layer

    Opinion for Fast PatchMerging Layer

    https://github.com/svip-lab/AS-MLP/blob/946848d957e5b1c33226ddacaa35f422a103ddfb/models/as_mlp.py#L187-L222

    Thanks for sharing your work!

    Why did you design PathMerging Layer normalizing features first?

    I think that if we normalize features after reduce layer, we can reduce the size of model and flops.

    Did you do ablation study for this layer?

    For example,

     class PatchMerging(nn.Module): 
         r""" Patch Merging Layer. 
      
         Args: 
             input_resolution (tuple[int]): Resolution of input feature. 
             dim (int): Number of input channels. 
             norm_layer (nn.Module, optional): Normalization layer.  Default: nn.LayerNorm 
         """ 
      
         def __init__(self, input_resolution, dim, norm_layer=nn.LayerNorm): 
             super().__init__() 
             self.input_resolution = input_resolution 
             self.dim = dim 
             self.reduction = nn.Conv2d(4 * dim, 2 * dim, 1, 1, bias=False) 
             self.norm = norm_layer(2 * dim) 
      
         def forward(self, x): 
             """ 
             x: B, H*W, C 
             """ 
             B, C, H, W = x.shape 
             #assert L == H * W, "input feature has wrong size" 
             assert H % 2 == 0 and W % 2 == 0, f"x size ({H}*{W}) are not even." 
      
             x = x.view(B, C, H, W) 
      
             x0 = x[:, :, 0::2, 0::2]  # B C H/2 W/2  
             x1 = x[:, :, 1::2, 0::2]  # B C H/2 W/2  
             x2 = x[:, :, 0::2, 1::2]  # B C H/2 W/2  
             x3 = x[:, :, 1::2, 1::2]  # B C H/2 W/2  
             x = torch.cat([x0, x1, x2, x3], 1)  # B 4*C H/2 W/2  
    
             x = self.reduction(x) 
             x = self.norm(x) 
             return x 
    
    opened by developer0hye 2
  • Semantic Segmentation?

    Semantic Segmentation?

    Thank you for your work! However, I did not find your code for semantic segmentation. I am currently working on pure-MLP segmentation and it would be a huge help if you could provide the ASMLP code for semantic segmentation.

    opened by Dootmaan 1
  • Please add paper link as well.

    Please add paper link as well.

    I arrived this repo via followings' likes. For those who like me, it would be good if paper link is included in README. Anyway, thanks for your great effort and reports.

    Sincerely, Sungguk Cha

    opened by sunggukcha 1
Owner
SVIP Lab
ShanghaiTech Vision and Intelligent Perception Lab
SVIP Lab
Official implementation of AAAI-21 paper "Label Confusion Learning to Enhance Text Classification Models"

Description: This is the official implementation of our AAAI-21 accepted paper Label Confusion Learning to Enhance Text Classification Models. The str

null 101 Nov 25, 2022
Official PyTorch implementation for paper Context Matters: Graph-based Self-supervised Representation Learning for Medical Images

Context Matters: Graph-based Self-supervised Representation Learning for Medical Images Official PyTorch implementation for paper Context Matters: Gra

null 49 Nov 23, 2022
The official implementation of NeMo: Neural Mesh Models of Contrastive Features for Robust 3D Pose Estimation [ICLR-2021]. https://arxiv.org/pdf/2101.12378.pdf

NeMo: Neural Mesh Models of Contrastive Features for Robust 3D Pose Estimation [ICLR-2021] Release Notes The offical PyTorch implementation of NeMo, p

Angtian Wang 76 Nov 23, 2022
StyleGAN2-ADA - Official PyTorch implementation

Abstract: Training generative adversarial networks (GAN) using too little data typically leads to discriminator overfitting, causing training to diverge. We propose an adaptive discriminator augmentation mechanism that significantly stabilizes training in limited data regimes.

NVIDIA Research Projects 3.2k Dec 30, 2022
Official implementation of the ICLR 2021 paper

You Only Need Adversarial Supervision for Semantic Image Synthesis Official PyTorch implementation of the ICLR 2021 paper "You Only Need Adversarial S

Bosch Research 272 Dec 28, 2022
Official PyTorch implementation of Joint Object Detection and Multi-Object Tracking with Graph Neural Networks

This is the official PyTorch implementation of our paper: "Joint Object Detection and Multi-Object Tracking with Graph Neural Networks". Our project website and video demos are here.

Richard Wang 443 Dec 6, 2022
Official implementation of the paper Image Generators with Conditionally-Independent Pixel Synthesis https://arxiv.org/abs/2011.13775

CIPS -- Official Pytorch Implementation of the paper Image Generators with Conditionally-Independent Pixel Synthesis Requirements pip install -r requi

Multimodal Lab @ Samsung AI Center Moscow 201 Dec 21, 2022
Official pytorch implementation of paper "Image-to-image Translation via Hierarchical Style Disentanglement".

HiSD: Image-to-image Translation via Hierarchical Style Disentanglement Official pytorch implementation of paper "Image-to-image Translation

null 364 Dec 14, 2022
Official pytorch implementation of paper "Inception Convolution with Efficient Dilation Search" (CVPR 2021 Oral).

IC-Conv This repository is an official implementation of the paper Inception Convolution with Efficient Dilation Search. Getting Started Download Imag

Jie Liu 111 Dec 31, 2022
Official PyTorch Implementation of Unsupervised Learning of Scene Flow Estimation Fusing with Local Rigidity

UnRigidFlow This is the official PyTorch implementation of UnRigidFlow (IJCAI2019). Here are two sample results (~10MB gif for each) of our unsupervis

Liang Liu 28 Nov 16, 2022
Official implementation of our paper "LLA: Loss-aware Label Assignment for Dense Pedestrian Detection" in Pytorch.

LLA: Loss-aware Label Assignment for Dense Pedestrian Detection This project provides an implementation for "LLA: Loss-aware Label Assignment for Dens

null 35 Dec 6, 2022
Official implementation of Self-supervised Graph Attention Networks (SuperGAT), ICLR 2021.

SuperGAT Official implementation of Self-supervised Graph Attention Networks (SuperGAT). This model is presented at How to Find Your Friendly Neighbor

Dongkwan Kim 127 Dec 28, 2022
An official implementation of "SFNet: Learning Object-aware Semantic Correspondence" (CVPR 2019, TPAMI 2020) in PyTorch.

PyTorch implementation of SFNet This is the implementation of the paper "SFNet: Learning Object-aware Semantic Correspondence". For more information,

CV Lab @ Yonsei University 87 Dec 30, 2022
This project is the official implementation of our accepted ICLR 2021 paper BiPointNet: Binary Neural Network for Point Clouds.

BiPointNet: Binary Neural Network for Point Clouds Created by Haotong Qin, Zhongang Cai, Mingyuan Zhang, Yifu Ding, Haiyu Zhao, Shuai Yi, Xianglong Li

Haotong Qin 59 Dec 17, 2022
Official code implementation for "Personalized Federated Learning using Hypernetworks"

Personalized Federated Learning using Hypernetworks This is an official implementation of Personalized Federated Learning using Hypernetworks paper. [

Aviv Shamsian 121 Dec 25, 2022
StyleGAN2 - Official TensorFlow Implementation

StyleGAN2 - Official TensorFlow Implementation

NVIDIA Research Projects 10.1k Dec 28, 2022
Old Photo Restoration (Official PyTorch Implementation)

Bringing Old Photo Back to Life (CVPR 2020 oral)

Microsoft 11.3k Dec 30, 2022
Official implementation of "GS-WGAN: A Gradient-Sanitized Approach for Learning Differentially Private Generators" (NeurIPS 2020)

GS-WGAN This repository contains the implementation for GS-WGAN: A Gradient-Sanitized Approach for Learning Differentially Private Generators (NeurIPS

null 46 Nov 9, 2022
Official PyTorch implementation of Spatial Dependency Networks.

Spatial Dependency Networks: Neural Layers for Improved Generative Image Modeling Đorđe Miladinović   Aleksandar Stanić   Stefan Bauer   Jürgen Schmid

Djordje Miladinovic 34 Jan 19, 2022