aaronmarkham commented on a change in pull request #12808: MKL-DNN Quantization 
Examples and README
URL: https://github.com/apache/incubator-mxnet/pull/12808#discussion_r225536883
 
 

 ##########
 File path: example/quantization/README.md
 ##########
 @@ -1,4 +1,248 @@
 # Model Quantization with Calibration Examples
+
+This folder contains examples of quantizing a FP32 model with Intel® MKL-DNN 
or CUDNN.
+
+<h2 id="0">Contents</h2>
+
+* [1. Model Quantization with Intel® MKL-DNN](#1)
+* [2. Model Quantization with CUDNN](#2)
+
+<h2 id="1">Model Quantization with Intel® MKL-DNN</h2>
+
+Intel® MKL-DNN supports quantization well with subgraph feature on Intel® CPU 
Platform and can bring huge performance improvement on Intel® Xeon® Scalable 
Platform. A new quantization script `imagenet_gen_qsym_mkldnn.py` has been 
designed to launch quantization for image-classification models with Intel® 
MKL-DNN. This script intergrates with [Gluon-CV 
modelzoo](https://gluon-cv.mxnet.io/model_zoo/classification.html) so that more 
pre-trained models can be downloaded from Gluon-CV and can be converted for 
quantization. This script also supports custom models.
+
+Use below command to install Gluon-CV:
+
+```
+pip install gluoncv
+```
+
+The following models have been tested on Linux systems.
+
+| Model | Source | Dataset | FP32 Accuracy | INT8 Accuracy |
+|:---|:---|---|:---:|:---:|
+| [ResNet50-V1](#3)  | 
[Gluon-CV](https://gluon-cv.mxnet.io/model_zoo/classification.html)  | 
[Validation Dataset](http://data.mxnet.io/data/val_256_q90.rec)  | 
75.87%/92.72%  |  75.71%/92.65% |
+|[Squeezenet 
1.0](#4)|[Gluon-CV](https://gluon-cv.mxnet.io/model_zoo/classification.html)|[Validation
 
Dataset](http://data.mxnet.io/data/val_256_q90.rec)|57.01%/79.71%|56.62%/79.55%|
+|[MobileNet 
1.0](#5)|[Gluon-CV](https://gluon-cv.mxnet.io/model_zoo/classification.html)|[Validation
 
Dataset](http://data.mxnet.io/data/val_256_q90.rec)|69.76%/89.32%|69.61%/89.09%|
+|[ResNet152-V2](#6)|[MXNet 
ModelZoo](http://data.mxnet.io/models/imagenet/resnet/152-layers/)|[Validation 
Dataset](http://data.mxnet.io/data/val_256_q90.rec)|76.76%/93.03%|76.48%/92.96%|
+|[Inception-BN](#7)|[MXNet 
ModelZoo](http://data.mxnet.io/models/imagenet/inception-bn/)|[Validation 
Dataset](http://data.mxnet.io/data/val_256_q90.rec)|72.09%/90.60%|72.00%/90.53%|
+| [SSD-VGG](#8) | 
[example/ssd](https://github.com/apache/incubator-mxnet/tree/master/example/ssd)
  | VOC2007/2012  | 0.83 mAP  | 0.82 mAP  |
+
+<h3 id='3'>ResNet50-V1</h3>
+
+The following command is to download the pre-trained model from Gluon-CV and 
transfer it into the symbolic model which would be finally quantized. The 
validation dataset is available 
[here](http://data.mxnet.io/data/val_256_q90.rec) for testing the pre-trained 
models:
+
+```
+python imagenet_gen_qsym_mkldnn.py --model=resnet50_v1 --num-calib-batches=5 
--calib-mode=naive
+```
+
+The model would be automatically replaced in fusion and quantization format 
and saved as the quantized symbol and parameter fils in `./model` dictionary. 
The following command is to launch inference.
+
+```
+# USE MKLDNN AS SUBGRAPH BACKEND
+export MXNET_SUBGRAPH_BACKEND=MKLDNN
+
+# Launch FP32 Inference 
+python imagenet_inference.py --symbol-file=./model/resnet50_v1-symbol.json 
--param-file=./model/resnet50_v1-0000.params --rgb-mean=123.68,116.779,103.939 
--rgb-std=58.393,57.12,57.375 --num-skipped-batches=50 --batch-size=64 
--num-inference-batches=500 --dataset=./data/val_256_q90.rec --ctx=cpu 
--data-nthreads=1
+
+# Launch INT8 Inference
+python imagenet_inference.py 
--symbol-file=./model/resnet50_v1-quantized-5batches-naive-symbol.json 
--param-file=./model/resnet50_v1-quantized-0000.params 
--rgb-mean=123.68,116.779,103.939 --rgb-std=58.393,57.12,57.375 
--num-skipped-batches=50 --batch-size=64 --num-inference-batches=500 
--dataset=./data/val_256_q90.rec --ctx=cpu  --data-nthreads=1
+
+# Launch dummy data Inference
+python imagenet_inference.py --symbol-file=./model/resnet50_v1-symbol.json 
--batch-size=64 --num-inference-batches=500 --ctx=cpu --benchmark=True
+python imagenet_inference.py 
--symbol-file=./model/resnet50_v1-quantized-5batches-naive-symbol.json 
--batch-size=64 --num-inference-batches=500 --ctx=cpu --benchmark=True
+```
+
+<h3 id='4'>SqueezeNet1.0</h3>
+
+The following command is to download the pre-trained model from Gluon-CV and 
transfer it into the symbolic model which would be finally quantized. The 
validation dataset is available 
[here](http://data.mxnet.io/data/val_256_q90.rec) for testing the pre-trained 
models:
+
+```
+python imagenet_gen_qsym_mkldnn.py --model=squeezenet1.0 --num-calib-batches=5 
--calib-mode=naive
+```
+The model would be automatically replaced in fusion and quantization format 
and saved as the quantized symbol and parameter fils in `./model` dictionary. 
The following command is to launch inference.
+
+```
+# USE MKLDNN AS SUBGRAPH BACKEND
+export MXNET_SUBGRAPH_BACKEND=MKLDNN
+
+# Launch FP32 Inference
+python imagenet_inference.py --symbol-file=./model/squeezenet1.0-symbol.json 
--param-file=./model/squeezenet1.0-0000.params 
--rgb-mean=123.68,116.779,103.939 --rgb-std=58.393,57.12,57.375 
--num-skipped-batches=50 --batch-size=64 --num-inference-batches=500 
--dataset=./data/val_256_q90.rec --ctx=cpu --data-nthreads=1
+
+# Launch INT8 Inference
+python imagenet_inference.py 
--symbol-file=./model/squeezenet1.0-quantized-5batches-naive-symbol.json 
--param-file=./model/squeezenet1.0-quantized-0000.params 
--rgb-mean=123.68,116.779,103.939 --rgb-std=58.393,57.12,57.375 
--num-skipped-batches=50 --batch-size=64 --num-inference-batches=500 
--dataset=./data/val_256_q90.rec --ctx=cpu  --data-nthreads=1
+
+# Launch dummy data Inference
+python imagenet_inference.py --symbol-file=./model/squeezenet1.0-symbol.json 
--batch-size=64 --num-inference-batches=500 --ctx=cpu  --benchmark=True
+python imagenet_inference.py 
--symbol-file=./model/squeezenet1.0-quantized-5batches-naive-symbol.json 
--batch-size=64 --num-inference-batches=500 --ctx=cpu --benchmark=True
+```
+
+<h3 id='5'>MobileNet1.0</h3>
+
+The following command is to download the pre-trained model from Gluon-CV and 
transfer it into the symbolic model which would be finally quantized. The 
validation dataset is available 
[here](http://data.mxnet.io/data/val_256_q90.rec) for testing the pre-trained 
models:
+
+```
+python imagenet_gen_qsym_mkldnn.py --model=mobilenet1.0 --num-calib-batches=5 
--calib-mode=naive
+```
+The model would be automatically replaced in fusion and quantization format 
and saved as the quantized symbol and parameter fils in `./model` dictionary. 
The following command is to launch inference.
+
+```
+# USE MKLDNN AS SUBGRAPH BACKEND
+export MXNET_SUBGRAPH_BACKEND=MKLDNN
+
+# Launch FP32 Inference
+python imagenet_inference.py --symbol-file=./model/mobilenet1.0-symbol.json 
--param-file=./model/mobilenet1.0-0000.params --rgb-mean=123.68,116.779,103.939 
--rgb-std=58.393,57.12,57.375 --num-skipped-batches=50 --batch-size=64 
--num-inference-batches=500 --dataset=./data/val_256_q90.rec --ctx=cpu 
--data-nthreads=1
+
+# Launch INT8 Inference
+python imagenet_inference.py 
--symbol-file=./model/mobilenet1.0-quantized-5batches-naive-symbol.json 
--param-file=./model/mobilenet1.0-quantized-0000.params 
--rgb-mean=123.68,116.779,103.939 --rgb-std=58.393,57.12,57.375 
--num-skipped-batches=50 --batch-size=64 --num-inference-batches=500 
--dataset=./data/val_256_q90.rec --ctx=cpu  --data-nthreads=1
+
+# Launch dummy data Inference
+python imagenet_inference.py --symbol-file=./model/mobilenet1.0-symbol.json 
--batch-size=64 --num-inference-batches=500 --ctx=cpu  --benchmark=True
+python imagenet_inference.py 
--symbol-file=./model/mobilenet1.0-quantized-5batches-naive-symbol.json 
--batch-size=64 --num-inference-batches=500 --ctx=cpu --benchmark=True
+```
+
+<h3 id='6'>ResNet152-V2</h3>
+
+The following command is to download the pre-trained model from [MXNet 
ModelZoo](http://data.mxnet.io/models/imagenet/resnet/152-layers/) which would 
be finally quantized. The validation dataset is available 
[here](http://data.mxnet.io/data/val_256_q90.rec) for testing the pre-trained 
models:
+
+```
+python imagenet_gen_qsym_mkldnn.py --model=imagenet1k-resnet-152 
--num-calib-batches=5 --calib-mode=naive
+```
+
+The model would be automatically replaced in fusion and quantization format 
and saved as the quantized symbol and parameter fils in `./model` dictionary. 
The following command is to launch inference.
+
+```
+# USE MKLDNN AS SUBGRAPH BACKEND
+export MXNET_SUBGRAPH_BACKEND=MKLDNN
+
+# Launch FP32 Inference 
+python imagenet_inference.py 
--symbol-file=./model/imagenet1k-resnet-152-symbol.json 
--param-file=./model/imagenet1k-resnet-152-0000.params --num-skipped-batches=50 
--batch-size=64 --num-inference-batches=500 --dataset=./data/val_256_q90.rec 
--ctx=cpu --data-nthreads=1
+
+# Launch INT8 Inference
+python imagenet_inference.py 
--symbol-file=./model/imagenet1k-resnet-152-quantized-5batches-naive-symbol.json
 --param-file=./model/imagenet1k-resnet-152-quantized-0000.params 
--num-skipped-batches=50 --batch-size=64 --num-inference-batches=500 
--dataset=./data/val_256_q90.rec --ctx=cpu  --data-nthreads=1
+
+# Launch dummy data Inference
+python imagenet_inference.py 
--symbol-file=./model/imagenet1k-resnet-152-symbol.json --batch-size=64 
--num-inference-batches=500 --ctx=cpu --benchmark=True
+python imagenet_inference.py 
--symbol-file=./model/imagenet1k-resnet-152-quantized-5batches-naive-symbol.json
 --batch-size=64 --num-inference-batches=500 --ctx=cpu --benchmark=True
+```
+
+<h3 id='7'>Inception-BN</h3>
+
+The following command is to download the pre-trained model from [MXNet 
ModelZoo](http://data.mxnet.io/models/imagenet/inception-bn/) which would be 
finally quantized. The validation dataset is available 
[here](http://data.mxnet.io/data/val_256_q90.rec) for testing the pre-trained 
models:
 
 Review comment:
   from the...
   update the here link

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to