Tensorflow 模型转换 .pb convert to .lite实例
作者:cefengxu 时间:2023-08-13 05:19:04
2017年底,Tensorflow 推出Lite版本,可实现移动端的快速运行,其中,一个很关键的问题,如何把现有分类模型(.pb) 转换为(.lite)模型呢?
其实,步骤如下
1- 进入 Tensorflow 源码文件夹(以便bazel可以无需配置找打相应路径)
2- 转换可执行文件
bazel run --config=opt \
//tensorflow/contrib/lite/toco:toco -- \
--input_file=/tmp/mobilenet_v1_1.0_224_frozen.pb \ # 待转换模型路径
--output_file=/tmp/tflite_model2.tflite \ # 目标模型路径
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--input_shape=1,224,224,3 \ # 输入图像宽高
--input_array=input \ # 输入节点名称<参考1>
--output_array=MobilenetV1/Predictions/Reshape_1 \ # 输出节点名称<参考1>
--inference_type=FLOAT \ # 图像数据类型
--input_data_type=FLOAT
参考1: 如果输入输出节点不知道:进入python,import tf ,并通过如下命令( tf.GraphDef() )查找:
>>> import tensorflow as tf
>>> gf = tf.GraphDef()
>>> gf.ParseFromString(open('/your/path/to/graphname.pb','rb').read())
>>> for n in gf.node:
>>> print ( n.name +' ===> '+n.op )
参转换后,在android手机上运行,在不考虑精度的前提下,不同实现方式得到的结果如下:
模型 | type | model size | speed |
---|---|---|---|
mobilenet-v1-224 | .pb | 17 mb | 106 ms |
mobilenet-v1-224 | .lite | 16.4 mb | 72 ms |
来源:https://blog.csdn.net/u011292539/article/details/80484444
标签:Tensorflow,pb,lite
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现连接FTP并下载文件夹
2021-02-28 01:56:26
![](https://img.aspxhome.com/file/2023/1/120551_0s.png)
python 实现检验33品种数据是否是正态分布
2022-09-25 19:57:55
pytorch中Schedule与warmup_steps的用法说明
2023-07-07 00:18:14
用js限制网页只在微信浏览器中打开(或者只能手机端访问)
2023-09-24 00:11:25
django与小程序实现登录验证功能的示例代码
2023-08-04 01:06:58
python 包之 Pillow 图像处理教程分享
2022-02-22 01:22:48
Python正则表达式和元字符详解
2021-02-26 02:54:19
利用Python实现sqlite3增删改查的封装
2021-06-19 14:57:05
mysql数据库索引损坏及修复经验分享
2024-01-16 11:22:43
Python命名空间与作用域深入全面详解
2022-03-07 08:36:10
![](https://img.aspxhome.com/file/2023/1/115491_0s.jpg)
MySQL学习之分组查询的用法详解
2024-01-26 02:27:37
![](https://img.aspxhome.com/file/2023/7/78097_0s.png)
vue实现父子组件之间的通信以及兄弟组件的通信功能示例
2024-05-21 10:15:43
![](https://img.aspxhome.com/file/2023/4/125294_0s.gif)
Python开发之身份证验证库id_validator验证身份证号合法性及根据身份证号返回住址年龄等信息
2022-08-08 04:10:31
![](https://img.aspxhome.com/file/2023/2/70252_0s.png)
分析Python编程时利用wxPython来支持多线程的方法
2021-03-09 12:02:57
Vue中如何优雅的捕获 Promise 异常详解
2023-07-02 16:56:14
numpy 声明空数组详解
2022-09-20 15:29:44
mysql5存储过程编写实践
2008-12-24 16:32:00
一个简单的像素画小工具
2010-01-01 15:33:00
Git常用命令介绍
2022-08-14 03:42:46
python函数不定长参数使用方法解析
2022-07-05 23:47:20