我正在尝试生成神经网络成本/损失函数的标量摘要。以下是我的代码的一部分。
...
cost = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=predictions, labels=y))
cost_summary = tf.summary.scalar(name='cost_summary', tensor=cost)
optimizer = tf.train.AdamOptimizer(learning_rate=0.0001).minimize(cost)
with tf.Session() as sess:
# Step 1. Initializing the session
init = tf.global_variables_initializer()
writer = tf.summary.FileWriter('/home/dileep/Desktop', sess.graph)
sess.run(init)
# Step 2. Dividing x and y to batches
for epoch in range(training_epochs):
avg_cost = 0.0
total_batch = int(len(train_x)//batch_size)
x_batches = np.array_split(train_x, total_batch)
y_batches = np.array_split(train_y, total_batch)
# Step 3. Run session, calculate cost.
for i in range(total_batch):
batch_x, batch_y = x_batches[i], y_batches[i]
_, c = sess.run([optimizer, cost], feed_dict={
x:batch_x,
y:batch_y, keep_prob:0.4})
avg_cost += c/total_batch
# Step 4. Print the outputs
if epoch % display_step == 0:
print("Epoch:", '%0d' % (epoch+1), "cost=", "{:.9f}".format(avg_cost))
summary = sess.run(cost_summary)
writer.add_summary(summary, epoch)
print("Optimization finished!")
correct_prediction = tf.equal(tf.argmax(predictions, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, 'float'))
print('Accuracy:', accuracy.eval({x: test_x, y: test_y, keep_prob:0.8}))
此代码生成以下错误
InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,1]
[[{{node Placeholder_1}}]]
During handling of the above exception, another exception occurred:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-9-ba759ef3de6c> in <module>
21 y:batch_y, keep_prob:0.4})
22 avg_cost += c/total_batch
---> 23 summary = sess.run(cost_summary)
24 # Step 4. Print the outputs
25 if epoch % display_step == 0:
我不明白他们在谈论哪个占位符。谁能告诉我如何解决此错误。 谢谢