我需要将预训练的NN模型转换为Tensorflow Lite。该代码已使用Tensorflow进行了培训,并简单地另存为pb文件。我认为这是使用freeze_graph完成的。我的问题是,要进行转换,我需要模型的输入和输出参数,否则转换器将尝试在.pb文件中定位它们,而在其图元中不包含'serve'标签。
import os
import tensorflow as tf
facenet_model_checkpoint = "location/of/inception_v2"
model_exp = os.path.expanduser(facenet_model_checkpoint)
# Extracts the meta and ckpt file
meta_file, ckpt_file = facenet.get_model_filenames(model_exp)
with tf.Session(graph=tf.Graph()) as sess:
saver = tf.train.import_meta_graph(os.path.join(model_exp, meta_file), input_map=None)
saver.restore(tf.get_default_session(), os.path.join(model_exp, ckpt_file))
converter = tf.lite.TFLiteConverter.from_saved_model(facenet_model_checkpoint)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)