pb编译生成tflite文件

这篇博客介绍了如何使用TensorFlow将.pb模型文件转换为tflite格式,包括通过冻图生成tflite文件的步骤和通过.ckpt与结构.pb文件的转换方法。同时,博主分享了adb调试过程以及遇到的Bug1及其解决策略,提供了参考资料链接。

通过冻图生成tflite文件:

tensorflow-master$> bazel build tensorflow/contrib/lite/toco:toco

tensorflow-master$> bazel-bin/tensorflow/contrib/lite/toco/toco \
	--input_file=/home/tclxa/TCL/tmp/frozen_model.pb  \
	--input_format=TENSORFLOW_GRAPHDEF \
	--output_format=TFLITE \
	--output_file=/home/tclxa/TCL/tmp/mobilenet_quant_v1_224.tflite \
	--inference_type=FLOAT \
	--input_type=FLOAT \
	--input_arrays=input \
	--output_arrays=MobilenetV1/Predictions/Reshape_1 \
	--input_shapes=1,224,224,3

–output_file、–inference_type、–input_type、–input_arrays、–output_arrays、–input_shapes需要根据自己模型说明作相应的修改

通过ckpt和结构pb生成冻图:.ckpt和结构.pb文件

tensorflow-master$> bazel build tensorflow/python/tools:freeze_graph

tensorflow-master$> bazel-bin/tensorflow/python/tools/freeze_graph \
	--input_graph=/home/tclxa/TCL/tmp/mobilenet_v1_224.pb \
	--input_checkpoint=/home/tclxa/TCL/tmp/mobilenet-10202.ckpt \
	--input_binary=true \
	--output_graph=/home/tclxa/TCL/tmp/frozen_model.pb \
	--output_node_names=MobileNet/Predictions/Reshape_1

–input_graph、–input_checkpoint、–output_graph、–output_node_names需要根据自己模型说明作相应的修改

adb调试:

将手机文件拷贝到电脑上:adb pull /mnt/sdcard/DCIM/Imgtest/test-dep.jpg /home/tclxa/TCL/tmp
进入手机命令:adb shell

错误:

Bug1:
 2018-08-17 13:14:04.041593: F tensorflow/contrib/lite/toco/model_cmdline_flags.cc:331] Check failed: 
absl::SimpleAtoi(dim_str, &size) Failed to parse input_shape: 1,
Solve:
命令中有空格

参考博文
tensorflow官方教程

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值