Browse Source

Add the readme file of quantization tools (#1198)

tags/20190908
BUG1989 nihui 6 years ago
parent
commit
f79fa87dca
3 changed files with 34 additions and 3 deletions
  1. +30
    -0
      tools/quantize/README.md
  2. +3
    -3
      tools/quantize/ncnn2int8.cpp
  3. +1
    -0
      tools/quantize/ncnn2table.cpp

+ 30
- 0
tools/quantize/README.md View File

@@ -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
```


+ 3
- 3
tools/quantize/ncnn2int8.cpp View File

@@ -195,7 +195,7 @@ int NetQuantize::quantize_convolution()
// find convolution layer
std::map<std::string, std::vector<float> >::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<std::string, std::vector<float> >::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<std::string, std::vector<float> >::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];


+ 1
- 0
tools/quantize/ncnn2table.cpp View File

@@ -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;


Loading…
Cancel
Save