This repository contains an op-for-op PyTorch reimplementation of ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices .
Contains MNIST, CIFAR10&CIFAR100, TinyImageNet_200, MiniImageNet_1K, ImageNet_1K, Caltech101&Caltech256 and more etc.
Please refer to README.md
in the data
directory for the method of making a dataset.
Both training and testing only need to modify the config.py
file.
- line 29:
model_arch_name
change toshufflenet_v1_x1_0
. - line 31:
model_mean_parameters
change to[0.485, 0.456, 0.406]
. - line 32:
model_std_parameters
change to[0.229, 0.224, 0.225]
. - line 34:
model_num_classes
change to1000
. - line 36:
mode
change totest
. - line 89:
model_weights_path
change to./results/pretrained_models/ShuffleNetV1_x1_0-ImageNet_1K-7a092cde.pth.tar
.
python3 test.py
- line 29:
model_arch_name
change toshufflenet_v1_x1_0
. - line 31:
model_mean_parameters
change to[0.485, 0.456, 0.406]
. - line 32:
model_std_parameters
change to[0.229, 0.224, 0.225]
. - line 34:
model_num_classes
change to1000
. - line 36:
mode
change totrain
. - line 50:
pretrained_model_weights_path
change to./results/pretrained_models/ShuffleNetV1_x1_0-ImageNet_1K-7a092cde.pth.tar
.
python3 train.py
- line 29:
model_arch_name
change toshufflenet_v1_x1_0
. - line 31:
model_mean_parameters
change to[0.485, 0.456, 0.406]
. - line 32:
model_std_parameters
change to[0.229, 0.224, 0.225]
. - line 34:
model_num_classes
change to1000
. - line 36:
mode
change totrain
. - line 53:
resume
change to./samples/shufflenet_v1_x1_0-ImageNet_1K/epoch_xxx.pth.tar
.
python3 train.py
Source of original paper results: https://arxiv.org/pdf/1707.01083.pdf)
In the following table, the top-x error value in ()
indicates the result of the project, and -
indicates no test.
Model | Dataset | Top-1 error (val) | Top-5 error (val) |
---|---|---|---|
shufflenet_v1_x0_5 | ImageNet_1K | 41.2%(41.1%) | 19.0%(19.0%) |
shufflenet_v1_x1_0 | ImageNet_1K | 32.0%(31.9%) | 13.6%(13.6%) |
shufflenet_v1_x1_5 | ImageNet_1K | 29.0%(29.9%) | 10.4%(10.4%) |
shufflenet_v1_x2_0 | ImageNet_1K | 27.1%(27.0%) | 9.2%(9.2%) |
# Download `ShuffleNetV1_x1_0-ImageNet_1K-7a092cde.pth.tar` weights to `./results/pretrained_models`
# More detail see `README.md<Download weights>`
python3 ./inference.py
Input:
Output:
Build `shufflenet_v1_x1_0` model successfully.
Load `shufflenet_v1_x1_0` model weights `/ShuffleNetV1-PyTorch/results/pretrained_models/ShuffleNetV1_x1_0-ImageNet_1K-7a092cde.pth.tar` successfully.
tench, Tinca tinca (54.11%)
platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus (4.75%)
triceratops (2.94%)
armadillo (2.64%)
barracouta, snoek (2.63%)
If you find a bug, create a GitHub issue, or even better, submit a pull request. Similarly, if you have questions, simply post them as GitHub issues.
I look forward to seeing what the community does with these models!
Zhang, Xiangyu and Zhou, Xinyu and Lin, Mengxiao and Sun, Jian
We introduce an extremely computation-efficient CNN architecture named ShuffleNet, which is designed specially for mobile devices with very limited computing power (e.g., 10-150 MFLOPs). The new architecture utilizes two new operations, pointwise group convolution and channel shuffle, to greatly reduce computation cost while maintaining accuracy. Experiments on ImageNet classification and MS COCO object detection demonstrate the superior performance of ShuffleNet over other structures, e.g. lower top-1 error (absolute 7.8%) than recent MobileNet on ImageNet classification task, under the computation budget of 40 MFLOPs. On an ARM-based mobile device, ShuffleNet achieves โผ13ร actual speedup over AlexNet while maintaining comparable accuracy.
@inproceedings{zhang2018shufflenet,
title={Shufflenet: An extremely efficient convolutional neural network for mobile devices},
author={Zhang, Xiangyu and Zhou, Xinyu and Lin, Mengxiao and Sun, Jian},
booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
pages={6848--6856},
year={2018}
}