将PB文件转换为SavedModel格式

时间:2019-05-17 09:14:08

标签: tensorflow

我下载了预训练的模型,该模型保存在包含所有变量的.pb文件中。 我想将其更改为SavedModel格式,但不知道如何。

我尝试打印出模型中各层的名称,然后简单地保存它。但是有一些需要创建的占位符,我没有。

with tf.gfile.FastGFile(GRAPH_PB_PATH, "rb") as f:
   graph_def = tf.GraphDef()
   graph_def.ParseFromString(f.read())
   g_in = tf.import_graph_def(graph_def, name="")


print([tensor.name for tensor in tf.get_default_graph().as_graph_def().node])
with tf.Graph().as_default():
    with tf.Session as sess:
        ...

        # Saving
        inputs = {
            "input_images": input_placeholder
        }
        outputs = {"feature_fusion/concat_3": model_output}
        tf.saved_model.simple_save(
            sess, 'path/to/your/location/', inputs, outputs
        )

预期的文件结构:

variables/
    variables.data-*****-of-*****
    variables.index
saved_model.pb

0 个答案:

没有答案
相关问题