jemartin commited on
Commit
8aa8da0
·
verified ·
1 Parent(s): 3b39d5b

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +152 -0
README.md ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ model_name: googlenet-12-int8.onnx
5
+ tags:
6
+ - validated
7
+ - vision
8
+ - classification
9
+ - inception_and_googlenet
10
+ - googlenet
11
+ ---
12
+ <!--- SPDX-License-Identifier: BSD-3-Clause -->
13
+
14
+ # GoogleNet
15
+
16
+ |Model |Download |Download (with sample test data)| ONNX version |Opset version|Top-1 accuracy (%)|Top-5 accuracy (%)|
17
+ | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |
18
+ |GoogleNet| [28 MB](model/googlenet-3.onnx) | [31 MB](model/googlenet-3.tar.gz) | 1.1 | 3| | |
19
+ |GoogleNet| [28 MB](model/googlenet-6.onnx) | [31 MB](model/googlenet-6.tar.gz) | 1.1.2 | 6| | |
20
+ |GoogleNet| [28 MB](model/googlenet-7.onnx) | [31 MB](model/googlenet-7.tar.gz) | 1.2 | 7| | |
21
+ |GoogleNet| [28 MB](model/googlenet-8.onnx) | [31 MB](model/googlenet-8.tar.gz) | 1.3 | 8| | |
22
+ |GoogleNet| [28 MB](model/googlenet-9.onnx) | [31 MB](model/googlenet-9.tar.gz) | 1.4 | 9| | |
23
+ |GoogleNet| [27 MB](model/googlenet-12.onnx) | [25 MB](model/googlenet-12.tar.gz) | 1.9 | 12|67.78|88.34|
24
+ |GoogleNet-int8| [7 MB](model/googlenet-12-int8.onnx) | [5 MB](model/googlenet-12-int8.tar.gz) | 1.9 | 12|67.73|88.32|
25
+ |GoogleNet-qdq | [7 MB](model/googlenet-12-qdq.onnx) | [5 MB](model/googlenet-12-qdq.tar.gz) | 1.12 | 12 | 67.73 | 88.31 |
26
+ > Compared with the fp32 GoogleNet, int8 GoogleNet's Top-1 accuracy drop ratio is 0.07%, Top-5 accuracy drop ratio is 0.02% and performance improvement is 1.27x.
27
+ >
28
+ > **Note**
29
+ >
30
+ > The performance depends on the test hardware. Performance data here is collected with Intel® Xeon® Platinum 8280 Processor, 1s 4c per instance, CentOS Linux 8.3, data batch size is 1.
31
+
32
+ ## Description
33
+ GoogLeNet is the name of a convolutional neural network for classification,
34
+ which competed in the ImageNet Large Scale Visual Recognition Challenge in 2014.
35
+
36
+ Differences:
37
+ - not training with the relighting data-augmentation;
38
+ - not training with the scale or aspect-ratio data-augmentation;
39
+ - uses "xavier" to initialize the weights instead of "gaussian";
40
+
41
+ ### Dataset
42
+ [ILSVRC2014](http://www.image-net.org/challenges/LSVRC/2014/)
43
+
44
+ ## Source
45
+ Caffe BVLC GoogLeNet ==> Caffe2 GoogLeNet ==> ONNX GoogLeNet
46
+
47
+ ## Model input and output
48
+ ### Input
49
+ ```
50
+ data_0: float[1, 3, 224, 224]
51
+ ```
52
+ ### Output
53
+ ```
54
+ prob_0: float[1, 1000]
55
+ ```
56
+ ### Pre-processing steps
57
+ #### Necessary Imports
58
+ ```python
59
+ import imageio
60
+ from PIL import Image
61
+ ```
62
+ #### Obtain and pre-process image
63
+
64
+ ```python
65
+ def get_image(path):
66
+ '''
67
+ Using path to image, return the RGB load image
68
+ '''
69
+ img = imageio.imread(path, pilmode='RGB')
70
+ return img
71
+
72
+ # Pre-processing function for ImageNet models using numpy
73
+ def preprocess(img):
74
+ '''
75
+ Preprocessing required on the images for inference with mxnet gluon
76
+ The function takes loaded image and returns processed tensor
77
+ '''
78
+ img = np.array(Image.fromarray(img).resize((224, 224))).astype(np.float32)
79
+ img[:, :, 0] -= 123.68
80
+ img[:, :, 1] -= 116.779
81
+ img[:, :, 2] -= 103.939
82
+ img[:,:,[0,1,2]] = img[:,:,[2,1,0]]
83
+ img = img.transpose((2, 0, 1))
84
+ img = np.expand_dims(img, axis=0)
85
+
86
+ return img
87
+ ```
88
+
89
+ ### Post-processing steps
90
+ ```python
91
+ def predict(path):
92
+ # based on : https://mxnet.apache.org/versions/1.0.0/tutorials/python/predict_image.html
93
+ img = get_image(path)
94
+ img = preprocess(img)
95
+ mod.forward(Batch([mx.nd.array(img)]))
96
+ # Take softmax to generate probabilities
97
+ prob = mod.get_outputs()[0].asnumpy()
98
+ prob = np.squeeze(prob)
99
+ a = np.argsort(prob)[::-1]
100
+ return a
101
+ ```
102
+ ### Sample test data
103
+ random generated sample test data:
104
+ - test_data_set_0
105
+ - test_data_set_1
106
+ - test_data_set_2
107
+ - test_data_set_3
108
+ - test_data_set_4
109
+ - test_data_set_5
110
+
111
+ ## Results/accuracy on test set
112
+ This bundled model obtains a top-1 accuracy 68.7% (31.3% error) and
113
+ a top-5 accuracy 88.9% (11.1% error) on the validation set, using
114
+ just the center crop. (Using the average of 10 crops,
115
+ (4 + 1 center) * 2 mirror, should obtain a bit higher accuracy.)
116
+
117
+ ## Quantization
118
+ GoogleNet-int8 and GoogleNet-qdq are obtained by quantizing fp32 GoogleNet 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/googlenet/quantization/ptq/README.md) to understand how to use Intel® Neural Compressor for quantization.
119
+
120
+ ### Environment
121
+ onnx: 1.9.0
122
+ onnxruntime: 1.8.0
123
+
124
+ ### Prepare model
125
+ ```shell
126
+ wget https://github.com/onnx/models/raw/main/vision/classification/inception_and_googlenet/googlenet/model/googlenet-12.onnx
127
+ ```
128
+
129
+ ### Model quantize
130
+ Make sure to specify the appropriate dataset path in the configuration file.
131
+ ```bash
132
+ bash run_tuning.sh --input_model=path/to/model \ # model path as *.onnx
133
+ --config=googlenet.yaml \
134
+ --data_path=/path/to/imagenet \
135
+ --label_path=/path/to/imagenet/label \
136
+ --output_model=path/to/save
137
+ ```
138
+
139
+ ## References
140
+ * [Going deeper with convolutions](https://arxiv.org/pdf/1409.4842.pdf)
141
+
142
+ * [Intel® Neural Compressor](https://github.com/intel/neural-compressor)
143
+
144
+ ## Contributors
145
+ * [mengniwang95](https://github.com/mengniwang95) (Intel)
146
+ * [airMeng](https://github.com/airMeng) (Intel)
147
+ * [ftian1](https://github.com/ftian1) (Intel)
148
+ * [hshen14](https://github.com/hshen14) (Intel)
149
+
150
+ ## License
151
+ [BSD-3](LICENSE)
152
+