【问题标题】:Tensorflow: error trying to restore a model in a pb fileTensorflow:尝试在 pb 文件中恢复模型时出错
【发布时间】:2019-03-18 23:17:45
【问题描述】:

我正在尝试加载从 https://github.com/tensorflow/models/tree/master/official/resnet 获取的已训练模型,但是当我尝试加载 .pb 时,ParseFromString 方法出现错误:

import tensorflow as tf
from tensorflow.python.platform import gfile
GRAPH_PB_PATH = '../resnet_v2_fp32_savedmodel_NHWC/1538687283/saved_model.pb'
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="")
sess = tf.Session(graph=g_in)

DecodeError: Error parsing message

我做错了什么?

【问题讨论】:

    标签: tensorflow machine-learning resnet


    【解决方案1】:

    我遇到了类似的问题,我没有使用 gfile,而是使用了 tf.saved_model.loader.load 函数,就像在这篇文章 https://stackoverflow.com/a/46547595/4637693 中一样:

    sess = tf.Session(graph=tf.Graph())
    model = tf.saved_model.loader.load(sess, [tf.saved_model.tag_constants.SERVING], './model')
    graph_def = model.graph_def
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 2020-05-23
      • 2022-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-08
      相关资源
      最近更新 更多