From f79fa87dca5523699ae43b474ab42fdebebc2d31 Mon Sep 17 00:00:00 2001 From: BUG1989 <248857878@qq.com> Date: Tue, 20 Aug 2019 07:46:04 -0500 Subject: [PATCH] Add the readme file of quantization tools (#1198) --- tools/quantize/README.md | 30 ++++++++++++++++++++++++++++++ tools/quantize/ncnn2int8.cpp | 6 +++--- tools/quantize/ncnn2table.cpp | 1 + 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 tools/quantize/README.md diff --git a/tools/quantize/README.md b/tools/quantize/README.md new file mode 100644 index 000000000..12a54143d --- /dev/null +++ b/tools/quantize/README.md @@ -0,0 +1,30 @@ +# Post Training Quantization Tools + +To support int8 model deployment on mobile devices,we provide the universal post training quantization tools which can convert the float32 model to int8 model. + +The old convert tool and technical detail is in [Caffe-Int8-Convert-Tools](https://github.com/BUG1989/caffe-int8-convert-tools) + +## User Guide + +Example with mobilenet,just need three steps. + +### 1. Optimization graphic + +``` +./ncnnoptimize mobilenet-fp32.param mobilenet-fp32.bin mobilenet-nobn-fp32.param mobilenet-nobn-fp32.bin +``` + +### 2. Create the calibration table file + +We suggest that using the verification dataset for calibration, which is more than 5000 images. + +``` +./ncnn2table --param mobilenet-nobn-fp32.param --bin mobilenet-nobn-fp32.bin --images images/ --output mobilenet-nobn.table --mean 104,117,123 --norm 0.017,0.017,0.017 --size 224,224 --thread 2 +``` + +### 3. Quantization + +``` +./ncnn2int8 mobilenet-nobn-fp32.param mobilenet-nobn-fp32.bin mobilenet-int8.param mobilenet-int8.bin +``` + diff --git a/tools/quantize/ncnn2int8.cpp b/tools/quantize/ncnn2int8.cpp index a691ae42f..ff1846d84 100755 --- a/tools/quantize/ncnn2int8.cpp +++ b/tools/quantize/ncnn2int8.cpp @@ -195,7 +195,7 @@ int NetQuantize::quantize_convolution() // find convolution layer std::map >::iterator iter_data = blob_int8scale_table.find(layers[i]->name); - if (iter_data == weight_int8scale_table.end()) + if (iter_data == blob_int8scale_table.end()) continue; char key[256]; @@ -261,7 +261,7 @@ int NetQuantize::quantize_convolutiondepthwise() // find convolutiondepthwise layer std::map >::iterator iter_data = blob_int8scale_table.find(layers[i]->name); - if (iter_data == weight_int8scale_table.end()) + if (iter_data == blob_int8scale_table.end()) continue; char key[256]; @@ -327,7 +327,7 @@ int NetQuantize::quantize_innerproduct() // find InnerProduct layer std::map >::iterator iter_data = blob_int8scale_table.find(layers[i]->name); - if (iter_data == weight_int8scale_table.end()) + if (iter_data == blob_int8scale_table.end()) continue; char key[256]; diff --git a/tools/quantize/ncnn2table.cpp b/tools/quantize/ncnn2table.cpp index 9a9297a86..b19d4f104 100755 --- a/tools/quantize/ncnn2table.cpp +++ b/tools/quantize/ncnn2table.cpp @@ -685,6 +685,7 @@ void showUsage() std::cout << " -h, --help show this help message and exit" << std::endl; std::cout << " -p, --param path to ncnn.param file" << std::endl; std::cout << " -b, --bin path to ncnn.bin file" << std::endl; + std::cout << " -i, --images path to calibration images" << std::endl; std::cout << " -o, --output path to output calibration tbale file" << std::endl; std::cout << " -m, --mean value of mean" << std::endl; std::cout << " -n, --norm value of normalize(scale value,defualt is 1)" << std::endl;