jemartin commited on
Commit
8dc352f
·
verified ·
1 Parent(s): 20edb5d

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +97 -0
README.md ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ model_name: mnist-7.onnx
5
+ tags:
6
+ - validated
7
+ - vision
8
+ - classification
9
+ - mnist
10
+ ---
11
+ <!--- SPDX-License-Identifier: MIT -->
12
+
13
+ # MNIST - Handwritten Digit Recognition
14
+
15
+ ## Description
16
+ This model predicts handwritten digits using a convolutional neural network (CNN).
17
+
18
+ ## Model
19
+ |Model|Download|Download (with sample test data)| ONNX version |Opset version|TOP-1 ERROR|
20
+ |-----|:-------|:-------------------------------|:-------------|:------------|:------------|
21
+ |MNIST|[27 kB](model/mnist-1.onnx)|[26 kB](model/mnist-1.tar.gz) |1.0 |1 |1.1% |
22
+ |MNIST|[26 kB](model/mnist-7.onnx)|[26 kB](model/mnist-7.tar.gz) |1.2 |7 |1.1% |
23
+ |MNIST|[26 kB](model/mnist-8.onnx)|[26 kB](model/mnist-8.tar.gz) |1.3 |8 |1.1% |
24
+ |MNIST-12|[26 kB](model/mnist-12.onnx)|[26 kB](model/mnist-12.tar.gz) |1.9 |12 |1.1% |
25
+ |MNIST-12-int8|[11 kB](model/mnist-12-int8.onnx)|[10 kB](model/mnist-12-int8.tar.gz) |1.9 |12 |1.1% |
26
+
27
+ ### Dataset
28
+ The model has been trained on the popular [MNIST dataset](http://yann.lecun.com/exdb/mnist/).
29
+
30
+ ### Source
31
+ The model is trained in CNTK following the tutorial [CNTK 103D: Convolutional Neural Network with MNIST](https://github.com/Microsoft/CNTK/blob/master/Tutorials/CNTK_103D_MNIST_ConvolutionalNeuralNetwork.ipynb). Note that the specific architecture used is the model with alternating convolution and max pooling layers (found under the "Solution" section at the end of the tutorial).
32
+
33
+ ### Demo
34
+ [Run MNIST in browser](https://microsoft.github.io/onnxjs-demo/#/mnist) - implemented by ONNX.js with MNIST version 1.2
35
+
36
+ ## Inference
37
+ We used CNTK as the framework to perform inference. A brief description of the inference process is provided below:
38
+
39
+ ### Input
40
+ Input tensor has shape `(1x1x28x28)`, with type of float32.
41
+ One image at a time. This model doesn't support mini-batch.
42
+
43
+ ### Preprocessing
44
+ Images are resized into (28x28) in grayscale, with a black background and a white foreground (the number should be in white). Color value is scaled to [0.0, 1.0].
45
+
46
+ Example:
47
+ ```python
48
+ import numpy as np
49
+ import cv2
50
+
51
+ image = cv2.imread('input.png')
52
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
53
+ gray = cv2.resize(gray, (28,28)).astype(np.float32)/255
54
+ input = np.reshape(gray, (1,1,28,28)
55
+ ```
56
+
57
+ ### Output
58
+ The likelihood of each number before [softmax](https://en.wikipedia.org/wiki/Softmax_function), with shape of `(1x10)`.
59
+
60
+ ### Postprocessing
61
+ Route the model output through a softmax function to map the aggregated activations across the network to probabilities across the 10 classes.
62
+
63
+ ### Sample test data
64
+ Sets of sample input and output files are provided in
65
+ * serialized protobuf TensorProtos (`.pb`), which are stored in the folders `test_data_set_*/`.
66
+
67
+ ## Quantization
68
+ MNIST-12-int8 is obtained by quantizing MNIST-12 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/mnist/quantization/ptq/README.md) to understand how to use Intel® Neural Compressor for quantization.
69
+
70
+ ### Environment
71
+ onnx: 1.9.0
72
+ onnxruntime: 1.10.0
73
+
74
+ ### Prepare model
75
+ ```shell
76
+ wget https://github.com/onnx/models/raw/main/vision/classification/mnist/model/mnist-12.onnx
77
+ ```
78
+
79
+ ### Model quantize
80
+ ```bash
81
+ bash run_tuning.sh --input_model=path/to/model \ # model path as *.onnx
82
+ --config=mnist.yaml \
83
+ --output_model=path/to/save
84
+ ```
85
+
86
+ ## References
87
+ * [Intel® Neural Compressor](https://github.com/intel/neural-compressor)
88
+
89
+ ## Contributors
90
+ * [mengniwang95](https://github.com/mengniwang95) (Intel)
91
+ * [airMeng](https://github.com/airMeng) (Intel)
92
+ * [ftian1](https://github.com/ftian1) (Intel)
93
+ * [hshen14](https://github.com/hshen14) (Intel)
94
+
95
+ ## License
96
+ MIT
97
+