转自 https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/512752/
正確的做法
首先產生eval.pbtxt才能保證後續的freeze_graph、toco的正確。如何產生eval.pbtxt詳見Tensorflow部署到移動端。
利用eval.pbtxt進行正確的freeze graph:
freeze_graph
bazel-bin/tensorflow/python/tools/freeze_graph \
--input_graph=/home/lg/Desktop/mobilenet_v1/mobilenet_v1_eval.pbtxt \
--input_checkpoint=/home/lg/Desktop/mobilenet_v1/checkpoint/model.ckpt-20000 \
--input_binary=false \
--output_graph=/home/lg/Desktop/mobilenet_v1/frozen_mobilenet_v1_224.pb \
--output_node_names=MobilenetV1/Predictions/Reshape_1 \
--checkpoint_version=2
toco
利用eval.pbtxt進行正確的freeze graph之後生成正確的.pb檔案,再對.pb檔案進行toco:
保持FLOAT型別的toco操作:
bazel-bin/tensorflow/contrib/lite/toco/toco \
--input_file=/home/lg/Desktop/mobilenet_v1/frozen_mobilenet_v1_224.pb \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--output_file=/home/lg/Desktop/mobilenet_v1/frozen_graph_mobilenet_v1-FLOAT.tflite \
--inference_type=FLOAT \
--input_type=FLOAT \
--input_arrays=Placeholder \
--output_arrays=MobilenetV1/Predictions/Reshape_1 \
--input_shapes=1,224,224,3
進行量化為QUANTIZED_UINT8的toco操作:
bazel-bin/tensorflow/contrib/lite/toco/toco \
--input_file=/home/lg/Desktop/mobilenet_v1/frozen_mobilenet_v1_224.pb \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--output_file=/home/lg/Desktop/mobilenet_v1/frozen_graph_mobilenet_v1-QUANTIZED_UINT8.tflite \
--inference_type=QUANTIZED_UINT8 \
--input_type=QUANTIZED_UINT8 \
--input_arrays=Placeholder \
--output_arrays=MobilenetV1/Predictions/Reshape_1 \
--input_shapes=1,224,224,3 \
--default_ranges_min=0.0 \
–default_ranges_max=255.0