tensorflow模型量化
来源:互联网 发布:mac上好用的office软件 编辑:程序博客网 时间:2024/06/05 14:55
关于量化的具体原理可以参考:http://fjdu.github.io/machine/learning/2016/07/07/quantize-neural-networks-with-tensorflow.html,对量化的原理有详细说明,这里不再赘述.
由于按照http://fjdu.github.io/machine/learning/2016/07/07/quantize-neural-networks-with-tensorflow.html的教程出现问题,通过查找才量化成功,因此在此记录一下使用tensorflow模型量化流程.
1.源码编译安装tensorflow
量化公具的使用,需要源码编译安装tensorflow,如果之前有通过pip直接安装tensorflow,则需要将tensorflow先卸载,然后下载源码编译安装tensorflow,具体过程可以参考:http://blog.csdn.net/u011961856/article/details/76725411
2.编译量化工具:
sudo bazel build tensorflow/contrib/quantization/tools:quantize_graph
运行后报错:
ERROR: no such package 'tensorflow/contrib/quantization/tools': BUILD file not found on package path.
修改命令为:
sudo bazel build tensorflow/tools/quantization:quantize_graph
3.模型量化:
以GoogLeNet 为例,下载模型:
curl http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz -o /tmp/inceptionv3.tgz
解压:
tar xzf /tmp/inceptionv3.tgz
解压后文件为,模型文件classify_image_graph_def.pb ,测试图片cropped_panda.jpg,以及标签文件imagenet_synset_to_human_label_map.txt,这些在后面测试的时候要用到.
模型量化:
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
量化后的模型为quantized_graph.pb,进入模型保存目录,运行ls -lh查看模型大小,发现量化后模型由92M减小为24M.
测试效果:
重新回到tensorflow目录下:
cd
cd tensorflow
编译label _image代码:
sudo bazel build tensorflow/examples/label_image:label_image
测试量化模型:
注意由于tensorflow版本不同,输入参数名有所改变:
按照提示参数输入即可.
测试量化前的模型结果:
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"
测试量化后的模型结果:
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"
- tensorflow模型量化
- tensorflow Quantize(量化)
- 风险量化模型
- 量化模型的分类
- 游戏战斗力量化模型探讨
- 量化投资_佛莱斯选股模型
- 量化投资-基本面模型-沪铜多因素模型
- 量化投资-基本面模型-沪铝多因素模型
- 量化投资-基本面模型-沪锌多因素模型
- 量化投资-基本面模型-沪铅多因素模型
- 量化投资-基本面模型-热卷多因素模型
- 量化进阶——为什么量化投资一定要多模型
- Tensorflow:模型保存/模型恢复?
- 量化投资-棕榈日线-基本面模型
- Tensorflow cifar模型源码
- tensorflow模型相关
- Tensorflow cifar模型源码
- tensorflow模型优化技巧
- VMware虚拟机搭MAC系统
- Beanutils基本用法
- Agti—Net
- 读书笔记(一)——《Java核心技术卷一》第三章Java的基本程序设计结构
- java 类初始化顺序
- tensorflow模型量化
- 文章标题
- 小写数字金额转大写
- leetcode 545. Boundary of Binary Tree
- sleep() 和 wait() 有什么区别?
- 安卓动画学习笔记
- CI中的默认访问的控制器
- javascript学习笔记之DOM
- 结构体和联合体 的区别