Tensorflow 使用 python 将 pb 文件转换为 TFLITE [英] Tensorflow Convert pb file to TFLITE using python

查看:65
本文介绍了Tensorflow 使用 python 将 pb 文件转换为 TFLITE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个训练后保存为 pb 文件的模型,我想使用 tensorflow mobile,使用 TFLITE 文件很重要.问题是我在谷歌搜索转换器后发现的大多数示例都是终端或 cmd 上的命令.你能和我分享一个使用python代码转换为tflite文件的例子吗?

解决方案

遵循这个

但是最简单的方法是使用变量导出saved_model.pb,以防您想避免使用像Bazel这样的构建工具.

I have a model saved after training as pb file, I want to use tensorflow mobile and it's important to work with TFLITE file. The problem is most of the examples I found after googling for converters are command on terminal or cmd. Can you please share with me an example of converting to tflite files using python code?

解决方案

Following this TF example you can pass "--Saved_model_dir" parameter to export the saved_model.pb and variables folder to some directory (none existing dir) before running retrain.py script:

python retrain.py ...... --saved_model_dir /home/..../export

In order to convert your model to tflite you need to use below line:

convert_saved_model.convert(saved_model_dir='/home/.../export',output_arrays="final_result",output_tflite='/home/.../export/graph.tflite')

Note: you need to import convert_saved_model:

from tensorflow.contrib.lite.python import convert_saved_model

Remember you can convert to tflite in 2 ways:

But the easiest way is to export saved_model.pb with variables in case you want to avoid using builds tools like Bazel.

这篇关于Tensorflow 使用 python 将 pb 文件转换为 TFLITE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆