Welcome to follow my public account [Jizhi Vision], reply 001 to get Google programming specification

O_o >_< O_o O_o ~_~ O_o

This article introduces the Tengine model transformation and quantification process.

Tengine, like NCNN, is also an excellent end-to-end reasoning framework. I wrote an article titled “NCNN Model Transformation and Quantitative Process” in the previous article, for those who are interested, please refer to it.

So let’s start.

Build Tengine Tools

CONVERT_TOOL and QUANT_TOOL are enabled in cmakelist. TXT:

Start compiling:

cd <Tengine-path>
mkdir build

cd build

#Begin to compile
camke ..
make -j32
make install
Copy the code

Convert_tool and quant_tool will be generated in the./build/install/bin/ directory as follows:

     

2. Tengine model transformation

See what kind of arguments convert_tool requires with the following command:

cd ./build/install/bin

./convert_tool -h
Copy the code

As above, the front is the input and the back is the output.

Tengine provides rich front-end support for model transformation tools, which basically absorbs the mainstream deep learning frameworks both at home and abroad.

The front end is Caffe:

./convert_tool -f caffe -p ./mobilenet.prototxt -m ./mobilenet.caffemodel -o ./mobilenet.tmfile
Copy the code

Front-end Onnx:

./convert_tool -f onnx -m ./mobilenet.onnx -o ./mobilenet.tmfile
Copy the code

The front-end is Mxnet:

./convert_tool -f mxnet -p ./mobilenet.params -m ./mobilenet.json -o ./mobilenet.tmfile
Copy the code

The front end is Darknet:

./convert_tool -f darknet -p ./yolov3.weights -m ./yolov3.cfg -o yolov3.tmfile
Copy the code

The front-end is TensorFlow:

/convert_tool -f tensorflow -m mobielenet_v1_1.0_224_frozen. Pb -o mobilenet.tmfileCopy the code

Front end for TFLite:

./convert_tool -f tflite -m mobielenet.tflite -o mobilenet.tmfile
Copy the code

The front-end is MegEngine:

./convert_tool -f megengine -m mobilenet.pkl -o mobilenet.tmfile
Copy the code

Front-end OneFlow:

./convert_tool -f oneflow -p mobilenet.prototxt -m mobilenet/ -o mobilenet.tmfile
Copy the code

The front end is NCNN:

./convert_tool -f ncnn -p mobilenet.param -m mobilenet.bin -o mobilenet.tmfile
Copy the code

3. Tengine quantitative reasoning

As you can see, Tengine provides three quantification tools: Quant_tool_int8, quant_tool_uint8 and quant_tool_uint8_perchannel are respectively symmetric quantization, asymmetric quantization and asymmetric uint8_perchannel. The quantization strategies in them are similar, so here we pick quant_tool_int8 and say something about it.

Install the dependency libraries first:

apt update
apt install libopencv-dev
Copy the code

Use the following command to view the quantization tool parameter:

./quant_tool_int8 -h
Copy the code

As you can see, the input is quite abundant.

The front-end input is FP32 TMfile. Example of quantization:

/ quant_tool_int8-m./mobilenet_fp32.tmfile -i./dataset -o./mobilenet_int8.tmfile -g 3,224,224 -w 104.007, 116.669, 122.679 s 0.017, 0.017, 0.017Copy the code

The following logs are generated when the command is successfully executed:

And generate the following INT8 model file:

     

Then it can be used for reasoning.

I have shared the Tengine model transformation and quantification method above. I hope my sharing can be of some help to your study.


[Model Reasoning] Tengine Model Transformation and Quantification