Tensorflow 寻找protobuf模型的输入张量
问题是:我试图从一个冻结到.pb(ProtoBuf)文件的模型中进行推理 我已经正确地冻结了模型,选择了我感兴趣的用于推断的节点(仅输出)。我也可以选择输出张量,但当我输入张量时,会产生类似的错误:Tensorflow 寻找protobuf模型的输入张量,tensorflow,Tensorflow,问题是:我试图从一个冻结到.pb(ProtoBuf)文件的模型中进行推理 我已经正确地冻结了模型,选择了我感兴趣的用于推断的节点(仅输出)。我也可以选择输出张量,但当我输入张量时,会产生类似的错误: InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'w2' with dtype float [[Node: w2 = Placeholder[dtype=DT_
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'w2' with dtype float
[[Node: w2 = Placeholder[dtype=DT_FLOAT, shape=<unknown>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
下面是我用来进行推断的代码(来自.pb文件):
任何帮助都是非常有价值的,谢谢 为了明确回答这个问题:
如果有人有这个问题。。对我有效的修复方法是更改行:
feed_-dict={w1:4,w2:8}
与feed_-dict={'w1:0':4,'w2:0':8}
,因为这个节点已经创建。如果要打印图形的节点,则获取它们的线为:
[n.name for n in tf.get_default_graph().as_graph_def().node]
如果有人有这个问题。。对我有效的修复方法是将行feed_dict={w1:4,w2:8}更改为feed_dict={'w1:0':4,'w2:0':8},因为已经创建了这个节点。如果要打印图形的节点,则获取它们的行是:[n.name for n in tf.get_default_graph().as_graph_def().node]
w1 = tf.placeholder("float")
w2 = tf.placeholder("float")
with tf.Session() as sess:
init = tf.global_variables_initializer()
with tf.gfile.FastGFile("my_test_model/frozen_model.pb", 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')
tensor = sess.graph.get_tensor_by_name('op_to_restore:0')
# sess.run(init)
print(tensor)
predictions = sess.run(tensor, feed_dict={w1: 4, w2: 8})
print(predictions)
[n.name for n in tf.get_default_graph().as_graph_def().node]