CNN模型 INT8 量化实现方式(一)

当前CNN模型基本都是 float32,将其转换为 INT8 可以降低模型大小,提升速度,精度降低的也不太多。那么在实际中如何实现这个量化了?在网上找到了两种实践方法,这里先介绍其中的一种。

这里主要涉及两个问题:1)就是 int8量化;2)就是 int8 模型的使用

基于Caffe-Int8-Convert-Tools进行caffe模型转int8量化 在 NCNN 框架上运行
https://blog.csdn.net/u014644466/article/details/83278954

首先是基于 Caffe-Int8-Convert-Tools 这个工具进行 int8量化
https://github.com/BUG1989/caffe-int8-convert-tools

int8 模型的使用
How to use Int8 inference
https://github.com/Tencent/ncnn/pull/487
https://github.com/Tencent/ncnn/wiki/quantized-int8-inference#caffe-int8-convert-tools
In the default set, the inference using the Float32 mode,If you want switch the inference to Int8 mode,just need add 2 lines code,more details please see the examples/squeezenet-int8.cpp file.

......
ncnn::Net squeezenet;
squeezenet.set_conv_model(CONV_INT8);               //set the Int8 mode
squeezenet.load_param("squeezenet_v1.1.param");
squeezenet.load_scale("squeezenet_v1.1.table");     //parse the Int8 calibration table,also it's the quantize scale value
squeezenet.load_model("squeezenet_v1.1.bin");

NCNN 框架主要针对 android 优化的,

Q 支持哪些平台

A 跨平台,主要支持 android,次要支持 ios / linux / windows

Q 计算精度如何

A armv7 neon float 不遵照 ieee754 标准,有些采用快速实现(如exp sin等),速度快但确保精度足够高

Q pc 上的速度很慢

A pc都是x86架构的,基本没做什么优化,主要用来核对结果,毕竟up主精力是有限的(

猜你喜欢

转载自blog.csdn.net/zhangjunhit/article/details/84562334