Skip to content

Commit f064171

Browse files
add int8 shufflenetv2 model (#476)
* add quantized shufflenetv2 Signed-off-by: mengniwa <[email protected]> * fix readme Signed-off-by: mengniwa <[email protected]> Co-authored-by: Wenbing Li <[email protected]>
1 parent 6bf4397 commit f064171

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

vision/classification/shufflenet/README.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ Computationally efficient CNN architecture designed specifically for mobile devi
99
ShuffleNet is a deep convolutional network for image classification. [ShuffleNetV2](https://pytorch.org/hub/pytorch_vision_shufflenet_v2/) is an improved architecture that is the state-of-the-art in terms of speed and accuracy tradeoff used for image classification.
1010

1111
Caffe2 ShuffleNet-v1 ==> ONNX ShuffleNet-v1
12+
1213
PyTorch ShuffleNet-v2 ==> ONNX ShuffleNet-v2
1314

15+
ONNX ShuffleNet-v2 ==> Quantized ONNX ShuffleNet-v2
16+
17+
ONNX ShuffleNet-v2 ==> Quantized ONNX ShuffleNet-v2
18+
1419
## Model
1520

1621
|Model |Download |Download (with sample test data)|ONNX version|Opset version|
@@ -24,6 +29,13 @@ PyTorch ShuffleNet-v2 ==> ONNX ShuffleNet-v2
2429
|Model |Download |Download (with sample test data)|ONNX version|Opset version|Top-1 error |Top-5 error |
2530
|-------------|:--------------|:--------------|:--------------|:--------------|:--------------|:--------------|
2631
|ShuffleNet-v2 |[9.2MB](model/shufflenet-v2-10.onnx) | [8.7MB](model/shufflenet-v2-10.tar.gz) | 1.6 | 10 | 30.64 | 11.68|
32+
|ShuffleNet-v2-fp32 |[8.79MB](model/shufflenet-v2-12.onnx) |[8.69MB](model/shufflenet-v2-12.tar.gz) |1.9 |12 |33.65 |13.43|
33+
|ShuffleNet-v2-int8 |[2.28MB](model/shufflenet-v2-12-int8.onnx) |[2.37MB](model/shufflenet-v2-10-int8.tar.gz) |1.9 |12 |33.85 |13.66 |
34+
> Compared with the fp32 ShuffleNet-v2, int8 ShuffleNet-v2's Top-1 error rising ratio is 0.59%, Top-5 error rising ratio is 1.71% and performance improvement is 1.62x.
35+
>
36+
> Note the performance depends on the test hardware.
37+
>
38+
> Performance data here is collected with Intel® Xeon® Platinum 8280 Processor, 1s 4c per instance, CentOS Linux 8.3, data batch size is 1.
2739
2840
## Inference
2941
[This script](ShufflenetV2-export.py) converts the ShuffleNetv2 model from PyTorch to ONNX and uses ONNX Runtime for inference.
@@ -66,14 +78,43 @@ For training we use train+valset in COCO except for 5000 images from minivalset,
6678
Details of performance on COCO object detection are provided in [this paper](https://arxiv.org/pdf/1807.11164v1.pdf)
6779
<hr>
6880

81+
## Quantization
82+
ShuffleNet-v2-int8 is obtained by quantizing ShuffleNet-v2-fp32 model. We use [Intel® Neural Compressor](https://github.com/intel/neural-compressor) with onnxruntime backend to perform quantization. View the [instructions](https://github.com/intel/neural-compressor/blob/master/examples/onnxrt/onnx_model_zoo/shufflenet/README.md) to understand how to use Intel® Neural Compressor for quantization.
83+
84+
### Environment
85+
onnx: 1.9.0
86+
onnxruntime: 1.8.0
87+
88+
### Prepare model
89+
```shell
90+
wget https://github.com/onnx/models/tree/master/vision/classification/shufflenet/model/shufflenet-v2-12.onnx
91+
```
92+
93+
### Model quantize
94+
Make sure to specify the appropriate dataset path in the configuration file.
95+
```bash
96+
bash run_tuning.sh --input_model=path/to/model \ # model path as *.onnx
97+
--config=shufflenetv2.yaml \
98+
--output_model=path/to/save
99+
```
100+
101+
### Model inference
102+
We use onnxruntime to perform ShuffleNetv2_fp32 and ShuffleNetv2_int8 inference. View the notebook [onnxrt_inference](../onnxrt_inference.ipynb) to understand how to use these 2 models for doing inference as well as which preprocess and postprocess we use.
103+
69104
## References
70-
Ningning Ma, Xiangyu Zhang, Hai-Tao Zheng, Jian Sun. ShuffleNet V2: Practical Guidelines for EfficientCNN Architecture Design. 2018.
105+
* Ningning Ma, Xiangyu Zhang, Hai-Tao Zheng, Jian Sun. ShuffleNet V2: Practical Guidelines for EfficientCNN Architecture Design. 2018.
106+
107+
* huffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices](https://arxiv.org/abs/1707.01083)
71108

72-
[ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices](https://arxiv.org/abs/1707.01083)
109+
* [Intel® Neural Compressor](https://github.com/intel/neural-compressor)
73110
<hr>
74111

75112
## Contributors
76-
Ksenija Stanojevic
113+
* Ksenija Stanojevic
114+
* [mengniwang95](https://github.com/mengniwang95) (Intel)
115+
* [airMeng](https://github.com/airMeng) (Intel)
116+
* [ftian1](https://github.com/ftian1) (Intel)
117+
* [hshen14](https://github.com/hshen14) (Intel)
77118
<hr>
78119

79120
## License
Binary file not shown.
Binary file not shown.
8.79 MB
Binary file not shown.
8.69 MB
Binary file not shown.

0 commit comments

Comments
 (0)