将Mobilenet细分模型转换为tflite

时间:2019-07-02 17:24:34

标签: tensorflow tensorflow-lite

我在Tensorflow中的初学者非常乐意原谅我这个简单的问题,但我无法在任何地方找到该答案。我正在将在Pascal数据集上训练的mobilenet细分模型(http://download.tensorflow.org/models/deeplabv3_mnv2_pascal_trainval_2018_01_29.tar.gz)转换为Tensorflow-lite进行移动推理超过一个星期,但没有成功。我无法正确定义转换器的输入和输出格式。

import tensorflow as tf
import numpy as np
img = tf.placeholder(name="Image", dtype=tf.float32, shape=(512,512,  3))
out = tf.placeholder(name="Output", dtype=tf.float32, shape=(512,512, 1))
localpb = 'frozen_inference_graph.pb'
tflite_file = 'retrained_graph_eyes1za.lite'
print("{} -> {}".format(localpb, tflite_file))
converter = tf.lite.TFLiteConverter.from_frozen_graph(
localpb, img, out
)
tflite_model = converter.convert()


open(tflite_file,'wb').write(tflite_model)

但是,它会引发很多错误,例如急切的执行。请告诉我如何编写将以上Mobilenet模型转换为tflite的代码。

1 个答案:

答案 0 :(得分:1)

在命令提示符或bash shell中尝试此操作 您可以使用以下两种方式之一

用于从软件包管理器安装的tensorflow

'pk'

从源构建

python -m tensorflow.python.tools.optimize_for_inference \
--input=/path/to/frozen_inference_graph.pb \
--output=/path/to/frozen_inference_graph_stripped.pb \
--frozen_graph=True \
--input_names="sub_7" \
--output_names="ResizeBilinear_3"

希望它能起作用!