当找不到MetaGraphDef集('serve')并且我不知道输入和输出时,如何使用Tensorflow Lite转换器?

2024-04-27 04:23:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要把预先训练好的神经网络模型转换成张量流模型。代码已经使用Tensorflow进行了训练,并简单地保存为pb文件。我想这是用冰冻图做的。我的问题是,为了能够转换,我需要模型的输入和输出参数,或者转换器试图在.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)

Tags: 文件path模型importmodelostfas