我是靠谱客的博主 俊秀茉莉,这篇文章主要介绍Tensorflow 1.14 训练模型 .pb 文件转换成 Tensorflowlite的 .tflite 文件Tensorflow 1.14 训练模型 .pb 文件转换成 Tensorflowlite的 .tflite 文件,现在分享给大家,希望可以做个参考。
Tensorflow 1.14 训练模型 .pb 文件转换成 Tensorflowlite的 .tflite 文件
1 tensorflow ssd_mobilenet 模型训练
tensorflow ssd_mobilenet 模型训练参考:https://blog.csdn.net/bibo1984/article/details/107397009
2 生成 .pb 文件
python3 /home/pi/xxxxxx/models/research/object_detection/export_tflite_ssd_graph.py --input_type image_tensor --pipeline_co
nfig_path /home/pi/xxxxxx/maidong/ssd_mobilenet_v2_coco_maidong.config --trained_checkpoint_prefix /home/pi/xxxxxx/maidong/train_logs/model.ckpt-XXXX --output_directory /home/pi/xxxxxx/maidong/outputmodels
3 配置 bazel
# 下载 bazel 安装脚本
wget -c https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel-3.1.0-installer-linux-x86_64.sh
# 添加脚本执行权限
chmod a+x bazel-3.1.0-installer-linux-x86_64.sh
# 安装
./bazel-3.1.0-installer-linux-x86_64.sh
# 下载 tensorflow
git clone https://github.com/tensorflow/tensorflow.git
# 配置 bazel
cd tensorflow
bazel build tensorflow/tools/graph_transforms:summarize_graph
生成 .tflite 文件
配置 pb_to_tflite.py 脚本,如下
import tensorflow as tf
# 需要配置
in_path = "/home/pi/xxxxxx/maidong/outputmodels/tflite_graph.pb"
# 模型输入节点
input_tensor_name = ["normalized_input_image_tensor"]
input_tensor_shape = {"normalized_input_image_tensor":[1,300,300,3]}
# 模型输出节点
classes_tensor_name = ['TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3']
converter = tf.lite.TFLiteConverter.from_frozen_graph(in_path,
input_tensor_name, classes_tensor_name,
input_tensor_shape)
converter.allow_custom_ops=True
converter.post_training_quantize = True
tflite_model = converter.convert()
open("output_detect.tflite", "wb").write(tflite_model)
print("done")
参考:
https://blog.csdn.net/SpiritYzw/article/details/105629397
最后
以上就是俊秀茉莉最近收集整理的关于Tensorflow 1.14 训练模型 .pb 文件转换成 Tensorflowlite的 .tflite 文件Tensorflow 1.14 训练模型 .pb 文件转换成 Tensorflowlite的 .tflite 文件的全部内容,更多相关Tensorflow内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复