GithubHelp home page GithubHelp logo

activemlp's Introduction

ActiveMLP

This repo is the official implementation of "ActiveMLP: An MLP-like Architecture with Active Token Mixer", by Guoqiang Wei*, Zhizheng Zhang*, Cuiling Lan, Yan Lu and Zhibo Chen.

ActiveMLP is a general MLP-like visual backbone, which is applicable to image classification, object detection and semantic segmentation tasks. The core operator, Active Token Mixer (ATM), actively incorporates contextual information from other tokens in the global scope. It adaptively predicts where to capture useful contexts and learns how to fuse the captured contexts with the origianl information at channel levels.

The ActiveMLP variants achieve 79.7% ~ 83.8% acc@top1 with the models scaled from 15M ~ 76M on ImageNet-1K. It also shows the superiority on downstream dense prediction tasks. ActiveMLP-Large achieves 51.1% mIoU with UperNet on ADE20K semantic segmentation dataset.

ActiveMLP

Model zoo

name acc@1 acc@5 #params FLOPs download
Active-xT 79.7 94.9 15M 2.2G model
Active-T 82.0 95.9 27M 4.0G model
Active-S 83.1 96.3 39M 6.9G
Active-B 83.5 96.6 52M 10.1G
Active-L 83.8 96.6 76M 12.4G model

Usage

The following guideline of ActiveMLP is for image classification, the guideline for semantic segmentation can be found here.

Install

  • Clone this repo:
git clone https://github.com/microsoft/ActiveMLP.git
cd ActiveMLP
  • Install pytorch following the official guideline, we use pytorch==1.7.1 with cuda==11.1 and cudnn8.
  • Install other packages with:
pip install -r requirements.txt

Data preparation

Download the standard ImageNet-1K dataset from http://image-net.org, and construct the data like:

ImageNet_Root
├── train
│   ├── n01440764
│   │   ├── n01440764_10026.JPEG
│   │   ├── n01440764_10027.JPEG
│   │   ├── ...
│   ├── ...
├── val
    ├── n02093754
    │   ├── ILSVRC2012_val_00000832.JPEG
    │   ├── ILSVRC2012_val_00003267.JPEG
    │   ├── ...
    ├── ...

Evaluation

To evaluate a pre-trained ActiveMLP on ImageNet val, run with:

python -m torch.distributed.launch --nproc_per_node <num-gpus> \
    --use_env main.py \
    --data-path <path-to-imagenet> \
    --model <activemlp-model> \
    --resume <checkpoint.pth> \
    --eval --dist-eval 

For example, to evaluate the ActiveMLP-Tiny with two GPUs distributedly:

python -m torch.distributed.launch --nproc_per_node 2 \
    --use_env main.py \
    --data-path <path-to-imagenet> \
    --model ActiveTiny \
    --resume activemlp_tiny.pth \
    --eval --dist-eval 

This should give:

[ema] accuracy on 50000 test images: 81.990% acc@1 | 95.930% acc@5

Training

To train an ActiveMLP on ImageNet from scratch, run with:

python -m torch.distributed.launch --nproc_per_node <num-gpus> \
    --use_env main.py \
    --batch-size <batch-szie> \
    --data-path <path-to-imagenet> \
    --model <activemlp-model> [other options]

For example, train the ActiveMLP-Tiny with 1024 batch size on 8 GPUs, run with:

python -m torch.distributed.launch --nproc_per_node 8 \ 
    --use_env main.py \
    --batch-size 128 \
    --data-path <path-to-imagenet> \
    --model ActivexTiny \
    --drop-path 0.1 \
    --output-dir active_xtiny_output

Throughput

To evaluate the throughput, run with:

python -m torch.distributed.launch --nproc_per_node 1 \
    --use_env main.py --batch-size 64 \
    --data-path <path-to-imagenet> \
    --model ActivexTiny \
    --throughput

Citing

@article{wei2022activemlp,
    title={ActiveMLP: An MLP-like Architecture with Active Token Mixer},
    author={Wei, Guoqiang and Zhang, Zhizheng and Lan, Cuiling and Lu, Yan and Chen, Zhibo},
    journal={arXiv preprint arXiv:2203.06108},
    year={2022}
}

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.