美文网首页程序员
利用TFLite将MobilenetV2模型部署到移动端(pb-

利用TFLite将MobilenetV2模型部署到移动端(pb-

作者: 两层奶油 | 来源:发表于2019-03-29 15:52 被阅读0次

全部利用tf官方python代码(bazel我真滴是mac下编译环境问题搞不动)
有一个比较坑的地方是:
第1步和第2步在tf 1.4.0, numpy 1.15.4可以成功
第3步在tf 1.13.1, numpy 1.16.1可以成功

过程分为3步:
1、导出前向传播图(不包含权重)

python export_inference_graph.py 
--model_name=mobilenet_v2_035 
--output_file=0318_log_v2_035_mobilenet/0318_export_v2_035_mobilenet.pb 
--dataset_name=cards 
--dataset_dir=../datasets/cards_0317

2、将前向传播图(不包含权重)和训练得到的cpkt文件(包含权重)固化在一起

python freeze_graph.py 
--input_binary=true 
--input_graph=0318_log_v2_035_mobilenet/0318_export_v2_035_mobilenet.pb 
--input_checkpoint=0318_log_v2_035_mobilenet/model.ckpt-18000 
--output_graph=0318_log_v2_035_mobilenet/0318_frozen_v2_035_mobilenet.pb 
--output_node_names=MobilenetV2/Predictions/Reshape_1

3、利用TFLiteConverter将固化后的pb文件转成tflite格式文件

import tensorflow as tf
graph_def_file = "0318_log_v2_035_mobilenet/0318_frozen_v2_035_mobilenet.pb"
input_arrays = ["input"]
output_arrays = ["MobilenetV2/Predictions/Softmax"]
converter = tf.lite.TFLiteConverter.from_frozen_graph(
graph_def_file, input_arrays, output_arrays)
tflite_model = converter.convert()
open("0318_log_v2_035_mobilenet/0318_v2_035_float_mobilenet.tflite", "wb").write(tflite_model)

https://tensorflow.google.cn/lite/convert/python_api

相关文章

网友评论

    本文标题:利用TFLite将MobilenetV2模型部署到移动端(pb-

    本文链接:https://www.haomeiwen.com/subject/lyolbqtx.html