1. 程式人生 > >pb編譯生成tflite檔案

pb編譯生成tflite檔案

通過凍圖生成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:

命令中有空格