Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
model_name: shufflenet-8.onnx
|
| 5 |
+
tags:
|
| 6 |
+
- validated
|
| 7 |
+
- vision
|
| 8 |
+
- classification
|
| 9 |
+
- shufflenet
|
| 10 |
+
---
|
| 11 |
+
<!--- SPDX-License-Identifier: BSD-3-Clause -->
|
| 12 |
+
|
| 13 |
+
# ShuffleNet
|
| 14 |
+
|
| 15 |
+
## Use cases
|
| 16 |
+
Computationally efficient CNN architecture designed specifically for mobile devices with very limited computing power.
|
| 17 |
+
|
| 18 |
+
## Description
|
| 19 |
+
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.
|
| 20 |
+
|
| 21 |
+
Caffe2 ShuffleNet-v1 ==> ONNX ShuffleNet-v1
|
| 22 |
+
|
| 23 |
+
PyTorch ShuffleNet-v2 ==> ONNX ShuffleNet-v2
|
| 24 |
+
|
| 25 |
+
ONNX ShuffleNet-v2 ==> Quantized ONNX ShuffleNet-v2
|
| 26 |
+
|
| 27 |
+
ONNX ShuffleNet-v2 ==> Quantized ONNX ShuffleNet-v2
|
| 28 |
+
|
| 29 |
+
## Model
|
| 30 |
+
|
| 31 |
+
|Model |Download |Download (with sample test data)|ONNX version|Opset version|
|
| 32 |
+
|-------------|:--------------|:--------------|:--------------|:--------------|
|
| 33 |
+
|ShuffleNet-v1| [5.3 MB](model/shufflenet-3.onnx) | [7 MB](model/shufflenet-3.tar.gz) | 1.1 | 3|
|
| 34 |
+
|ShuffleNet-v1| [5.3 MB](model/shufflenet-6.onnx) | [9 MB](model/shufflenet-6.tar.gz) | 1.1.2 | 6|
|
| 35 |
+
|ShuffleNet-v1| [5.3 MB](model/shufflenet-7.onnx) | [9 MB](model/shufflenet-7.tar.gz) | 1.2 | 7|
|
| 36 |
+
|ShuffleNet-v1| [5.3 MB](model/shufflenet-8.onnx) | [9 MB](model/shufflenet-8.tar.gz) | 1.3 | 8|
|
| 37 |
+
|ShuffleNet-v1| [5.3 MB](model/shufflenet-9.onnx) | [9 MB](model/shufflenet-9.tar.gz) | 1.4 | 9|
|
| 38 |
+
|
| 39 |
+
|Model |Download |Download (with sample test data)|ONNX version|Opset version|Top-1 error |Top-5 error |
|
| 40 |
+
|-------------|:--------------|:--------------|:--------------|:--------------|:--------------|:--------------|
|
| 41 |
+
|ShuffleNet-v2 |[9.2MB](model/shufflenet-v2-10.onnx) | [8.7MB](model/shufflenet-v2-10.tar.gz) | 1.6 | 10 | 30.64 | 11.68|
|
| 42 |
+
|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|
|
| 43 |
+
|ShuffleNet-v2-int8 |[2.28MB](model/shufflenet-v2-12-int8.onnx) |[2.37MB](model/shufflenet-v2-12-int8.tar.gz) |1.9 |12 |33.85 |13.66 |
|
| 44 |
+
|ShuffleNet-v2-qdq |[2.30MB](model/shufflenet-v2-12-qdq.onnx) |[2.68MB](model/shufflenet-v2-12-qdq.tar.gz) |1.12 |12 |33.88 | 19.94 |
|
| 45 |
+
> 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.
|
| 46 |
+
>
|
| 47 |
+
> Note the performance depends on the test hardware.
|
| 48 |
+
>
|
| 49 |
+
> Performance data here is collected with Intel® Xeon® Platinum 8280 Processor, 1s 4c per instance, CentOS Linux 8.3, data batch size is 1.
|
| 50 |
+
|
| 51 |
+
## Inference
|
| 52 |
+
[This script](ShufflenetV2-export.py) converts the ShuffleNetv2 model from PyTorch to ONNX and uses ONNX Runtime for inference.
|
| 53 |
+
|
| 54 |
+
### Input to model
|
| 55 |
+
Input to the model are 3-channel RGB images of shape (3 x H x W), where H and W are expected to be at least 224.
|
| 56 |
+
```
|
| 57 |
+
data_0: float[1, 3, 224, 224]
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
### Preprocessing steps
|
| 61 |
+
All pre-trained models expect input images normalized in the same way. The images have to be loaded in to a range of [0, 1] and then normalized using mean = [0.485, 0.456, 0.406] and std = [0.229, 0.224, 0.225].
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
input_image = Image.open(filename)
|
| 65 |
+
preprocess = transforms.Compose([
|
| 66 |
+
transforms.Resize(256),
|
| 67 |
+
transforms.CenterCrop(224),
|
| 68 |
+
transforms.ToTensor(),
|
| 69 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
| 70 |
+
])
|
| 71 |
+
input_tensor = preprocess(input_image)
|
| 72 |
+
```
|
| 73 |
+
Create a mini-batch as expected by the model.
|
| 74 |
+
```python
|
| 75 |
+
input_batch = input_tensor.unsqueeze(0)
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
### Output of model
|
| 79 |
+
|
| 80 |
+
Output of this model is tensor of shape 1000, with confidence scores over ImageNet's 1000 classes.
|
| 81 |
+
```
|
| 82 |
+
softmax_1: float[1, 1000]
|
| 83 |
+
```
|
| 84 |
+
<hr>
|
| 85 |
+
|
| 86 |
+
## Dataset (Train and Validation)
|
| 87 |
+
Models are pretrained on ImageNet.
|
| 88 |
+
For training we use train+valset in COCO except for 5000 images from minivalset, and use the minivalset to test.
|
| 89 |
+
Details of performance on COCO object detection are provided in [this paper](https://arxiv.org/pdf/1807.11164v1.pdf)
|
| 90 |
+
<hr>
|
| 91 |
+
|
| 92 |
+
## Quantization
|
| 93 |
+
ShuffleNet-v2-int8 and ShuffleNet-v2-int8 are 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/image_recognition/onnx_model_zoo/shufflenet/quantization/ptq/README.md) to understand how to use Intel® Neural Compressor for quantization.
|
| 94 |
+
|
| 95 |
+
### Environment
|
| 96 |
+
onnx: 1.9.0
|
| 97 |
+
onnxruntime: 1.8.0
|
| 98 |
+
|
| 99 |
+
### Prepare model
|
| 100 |
+
```shell
|
| 101 |
+
wget https://github.com/onnx/models/raw/main/vision/classification/shufflenet/model/shufflenet-v2-12.onnx
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
### Model quantize
|
| 105 |
+
Make sure to specify the appropriate dataset path in the configuration file.
|
| 106 |
+
```bash
|
| 107 |
+
bash run_tuning.sh --input_model=path/to/model \ # model path as *.onnx
|
| 108 |
+
--config=shufflenetv2.yaml \
|
| 109 |
+
--output_model=path/to/save
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
### Model inference
|
| 113 |
+
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.
|
| 114 |
+
|
| 115 |
+
## References
|
| 116 |
+
* Ningning Ma, Xiangyu Zhang, Hai-Tao Zheng, Jian Sun. ShuffleNet V2: Practical Guidelines for EfficientCNN Architecture Design. 2018.
|
| 117 |
+
|
| 118 |
+
* huffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices](https://arxiv.org/abs/1707.01083)
|
| 119 |
+
|
| 120 |
+
* [Intel® Neural Compressor](https://github.com/intel/neural-compressor)
|
| 121 |
+
<hr>
|
| 122 |
+
|
| 123 |
+
## Contributors
|
| 124 |
+
* Ksenija Stanojevic
|
| 125 |
+
* [mengniwang95](https://github.com/mengniwang95) (Intel)
|
| 126 |
+
* [airMeng](https://github.com/airMeng) (Intel)
|
| 127 |
+
* [ftian1](https://github.com/ftian1) (Intel)
|
| 128 |
+
* [hshen14](https://github.com/hshen14) (Intel)
|
| 129 |
+
<hr>
|
| 130 |
+
|
| 131 |
+
## License
|
| 132 |
+
BSD 3-Clause License
|
| 133 |
+
<hr>
|
| 134 |
+
|