This repository contains PyTorch code of our paper: Dynamic Slimmable Network (CVPR 2021 Oral).
Architecture of DS-Net. The width of each supernet stage is adjusted adaptively by the slimming ratio ρ predicted by the gate.
Accuracy vs. complexity on ImageNet.
-
Install PyTorch 1.2.0+, for example:
conda install -c pytorch pytorch torchvision
-
Install pytorch-image-models 0.3.2, for example:
pip install timm==0.3.2
-
Download ImageNet from http://image-net.org/. Move validation images to labeled subfolders using following script: https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.shvalprep.sh
For example, train dynamic slimmable MobileNet supernet with 8 GPUs (takes about 2 days):
python -m torch.distributed.launch --nproc_per_node=8 train.py /PATH/TO/ImageNet -c ./configs/mobilenetv1_bn_uniform.yml
-
Modify
resume:
to your supernet checkpoint. Recalibrate BN before gate trainingpython -m torch.distributed.launch --nproc_per_node=8 train.py /PATH/TO/ImageNet -c ./configs/mobilenetv1_bn_uniform_reset_bn.yml
-
Modify
resume:
to your supernet checkpoint after BN recalibration. Start gate trainingpython -m torch.distributed.launch --nproc_per_node=8 train.py /PATH/TO/ImageNet -c ./configs/mobilenetv1_bn_uniform_gate.yml
If you use our code for your paper, please cite:
@inproceedings{li2021dynamic,
author = {Changlin Li and
Guangrun Wang and
Bing Wang and
Xiaodan Liang and
Zhihui Li and
Xiaojun Chang},
title = {Dynamic Slimmable Network},
booktitle = {CVPR},
year = {2021}
}