[BUG InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor]
在调用pb模型时,出现了这个bug,发现跟placeholder 有关,
所以我就把所有的placeholder 都起一个名字,然后在次调用
发现是这个keep_prob的问题。
最开始错误:
InvalidArgumentError: You must feed a value for placeholder tensor ‘Placeholder_1’ with dtype float
起名字:
keep_prob = tf.placeholder("float",name='keep')
重新调用后报的错:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'keep' with dtype float
[[Node: keep = Placeholder[dtype=DT_FLOAT, shape=<unknown>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
解决方法:
with tf.Session(graph=tf.Graph()) as sess:
tf.saved_model.loader.load(sess, ["mytag"], "./save6")
sess.run(tf.global_variables_initializer())
x = sess.graph.get_tensor_by_name('input_x:0')
#获取到keep_prob
keep_prob = sess.graph.get_tensor_by_name('keep:0')
y = sess.graph.get_tensor_by_name('predict:0')
#然后传入 keep_prob:1.0 就不报错了
scores = sess.run(y,feed_dict={x:x_img,keep_prob:1.0})
print("predict: %d" % (np.argmax(scores, 1)))