赞
踩
bazel build tensorflow/python/tools:freeze_graph && \
bazel-bin/tensorflow/python/tools/freeze_graph \
--input_graph=eval_graph_def.pb \
--input_checkpoint=checkpoint \
--output_graph=frozen_eval_graph.pb \
--output_node_names=outputs
For example:
bazel-bin/tensorflow/python/tools/freeze_graph \
--input_graph=./mobilenet_v1_1.0_224/mobilenet_v1_1.0_224_eval.pbtxt \
--input_checkpoint=./mobilenet_v1_1.0_224/mobilenet_v1_1.0_224.ckpt \
--output_graph=./mobilenet_v1_1.0_224/frozen_eval_graph_test.pb \
--output_node_names=MobilenetV1/Predictions/Reshape_1
转换前需要先编译转换工具
bazel build tensorflow/contrib/lite/toco:toco
转换分两种,一种的转换为float的tf lite,另一种可以转换为对模型进行unit8的量化版本的模型。两种方式如下:
非量化的转换:
./bazel-bin/third_party/tensorflow/contrib/lite/toco/toco \ 官网给的这个路径不对
./bazel-bin/tensorflow/contrib/lite/toco/toco \
—input_file=./mobilenet_v1_1.0_224/frozen_eval_graph_test.pb \
—output_file=./mobilenet_v1_1.0_224/tflite_model_test.tflite \
--input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE \
--inference_type=FLOAT \
--input_shape="1,224, 224,3" \
--input_array=input \
--output_array=MobilenetV1/Predictions/Reshape_1
量化方式的转换(注意,只有量化训练的模型才能进行量化的tf_lite转换):
./bazel-bin/third_party/tensorflow/contrib/lite/toco/toco \
./bazel-bin/tensorflow/contrib/lite/toco/toco \
--input_file=frozen_eval_graph.pb \
--output_file=tflite_model.tflite \
--input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE \
--inference_type=QUANTIZED_UINT8 \
--input_shape="1,224, 224,3" \
--input_array=input \
--output_array=outputs \
--std_value=127.5 --mean_value=127.5
Reference:
https://tensorflow.google.cn/performance/quantization
https://www.tensorflow.org/mobile/tflite/devguide
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。