我已经用MNIST数据集训练了一个挤压和激励卷积神经网络模型。我已经将训练好的模型保存在一个文件夹中。
为了在生产中使用经过训练的模型,我已将其还原并尝试对新数据进行预测,但出现以下错误消息。
tensorflow.python.framework.errors_impl.InvalidArgumentError:您必须 用dtype bool输入占位符张量'Placeholder'的值 [[{{node占位符}}] [[accuracy / accuracy_var / _3191]]
模型还原代码:
import tensorflow as tf
from cifar10 import *
init_learning_rate = 0.1
train_x, train_y, test_x, test_y = prepare_data()
train_x, test_x = color_preprocessing(train_x, test_x)
tf.reset_default_graph()
saver = tf.train.import_meta_graph("./model/ResNeXt.ckpt.meta")
with tf.Session() as sess:
ckpt = tf.train.get_checkpoint_state('./model')
if ckpt and tf.train.checkpoint_exists(ckpt.model_checkpoint_path):
saver.restore(sess, ckpt.model_checkpoint_path)
graph = tf.get_default_graph()
for n in graph.as_graph_def().node:
print(n.name)
cost = graph.get_tensor_by_name("cost_reduce_mean:0")
accuracy = graph.get_tensor_by_name("accuracy/accuracy_var:0")
test_batch_x = test_x[0: 1000]
test_batch_y = test_y[0: 1000]
x = graph.get_tensor_by_name("placeholder_x_input:0")
label = graph.get_tensor_by_name("placeholder_label_input:0")
training_flag = tf.placeholder(tf.bool, name='tr_fg_99999')
learning_rate = tf.placeholder(tf.float32, name='learning_rate_99999')
test_feed_dict = {x: test_batch_x,label: test_batch_y,learning_rate: 0.1,training_flag: False}
loss_, acc_ = sess.run([cost, accuracy], feed_dict=test_feed_dict)
total_acc = acc_
行-loss_, acc_ = sess.run([cost, accuracy], feed_dict=test_feed_dict)
一旦执行,就会出现错误。