CNN模型 int8量化实现方式(二)

python 版本切换
sudo update-alternatives --list python

sudo update-alternatives --config python

卸载TensorFlow

先介绍卸载, 如果你的tensorflow是用pip安装的,那下面简单的命令就可以完成卸载了

sudo pip uninstall tensorflow_gpu  
sudo pip3 uninstall tensorflow_gpu

这里介绍一个完全基于 Tensorflow 的模型量化方法,以 yolo v3 为例

1)利用现有yolo v3 模型 生成 Tensorflow pb 模型
基于 https://github.com/mystic123/tensorflow-yolo-v3
Run python ./convert_weights.py and python ./convert_weights_pb.py

2)完全基于 Tensorflow 的量化
https://blog.csdn.net/u011961856/article/details/76736103

1.源码编译安装tensorflow
可参考 https://blog.csdn.net/u011961856/article/details/76725411

2 编译量化工具

sudo bazel build tensorflow/tools/quantization:quantize_graph

3.模型量化:

sudo bazel-bin/tensorflow/tools/quantization/quantize_graph --input=/tmp/classify_image_graph_def.pb --output_node_names="softmax" --output=/tmp/quantized_graph.pb --mode=eightbit

/tmp/ 这个路径我的修改为自己的绝对路径

sudo bazel-bin/tensorflow/tools/quantization/quantize_graph --input=/home/zhangjun/tensorflow/tmp/classify_image_graph_def.pb --output_node_names="softmax" --output=/home/zhangjun/tensorflow/tmp/quantized_graph.pb --mode=eightbit

4.测试量化模型:
测试量化前的模型结果:

sudo bazel-bin/tensorflow/examples/label_image/label_image --graph=/tmp/classify_image_graph_def.pb --input_width=299 --input_height=299 --input_mean=128 --input_std=128 --input_layer="Mul:0" --output_layer="softmax:0" --labels="/tmp/imagenet_synset_to_human_label_map.txt" --image="/tmp/cropped_panda.jpg"

/tmp/ 这个路径我的修改为自己的绝对路径

sudo bazel-bin/tensorflow/examples/label_image/label_image --graph=/home/zhangjun/tensorflow/tmp/classify_image_graph_def.pb --input_width=299 --input_height=299 --input_mean=128 --input_std=128 --input_layer="Mul:0" --output_layer="softmax:0" --labels="/home/zhangjun/tensorflow/tmp/imagenet_synset_to_human_label_map.txt" --image="/home/zhangjun/tensorflow/tmp/cropped_panda.jpg"

测试量化后的模型结果:

   sudo bazel-bin/tensorflow/examples/label_image/label_image --graph=/tmp/quantized_graph.pb --input_width=299 --input_height=299 --input_mean=128 --input_std=128 --input_layer="Mul:0" --output_layer="softmax:0" --labels="/tmp/imagenet_synset_to_human_label_map.txt" --image="/tmp/cropped_panda.jpg"

/tmp/ 这个路径我的修改为自己的绝对路径

bazel-bin/tensorflow/examples/label_image/label_image --graph=/home/zhangjun/tensorflow/tmp/quantized_graph.pb --input_width=299 --input_height=299 --input_mean=128 --input_std=128 --input_layer="Mul:0" --output_layer="softmax:0" --labels="/home/zhangjun/tensorflow/tmp/imagenet_synset_to_human_label_map.txt" --image="/home/zhangjun/tensorflow/tmp/cropped_panda.jpg"

tensorflow 对于 模型的量化目前来说并不成熟,处于开发阶段,tensorflow lite 是应该已经支持 量化模型的运行, 而 tensorflow 本身的支持很有限,貌似正在集成

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值