gpt4 book ai didi

python - 仅 1 个标量的 Tensorboard 摘要标量错误

转载 作者:行者123 更新时间:2023-11-30 09:46:40 25 4
gpt4 key购买 nike

我通过 Tensorboard 显示 3 个标量。其中 2 个标量工作没有问题(交叉熵和准确性)。但是,当我尝试显示第三个标量(learning_rate)时,出现错误。这是我的代码:

这 2 个标量没有错误:

cross_entropy = -tf.reduce_sum(y * tf.log(logits))
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits=Ylogits, labels=Y_)
cross_entropy = tf.reduce_mean(cross_entropy) * 100

correct_prediction = tf.equal(tf.argmax(Y, 1), tf.argmax(Y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

尝试显示learning_rate标量时出错:

learning_rate = 0.0001 + tf.train.exponential_decay(0.003, step, 2000, 1 / math.e)
train_step = tf.train.AdamOptimizer(learning_rate).minimize(cross_entropy)

这是我的张量板代码:

tf.summary.scalar("cross_entropy", cross_entropy)
tf.summary.scalar("training_accuracy", accuracy)
tf.summary.scalar("learning_rate", learning_rate)
tf.summary.image("input", x_image, 3)

with tf.Session() as sess:
sess.run(initializer)
merged_summary = tf.summary.merge_all()
writer = tf.summary.FileWriter("./visualization/1")
writer.add_graph(sess.graph)

for i in range(1000):
batch_x, batch_y = mnist.train.next_batch(100)
if i % 5 == 0:
s = sess.run(merged_summary, feed_dict={X: batch_x, Y_: batch_y})
writer.add_summary(s, i)
sess.run(train_step, feed_dict={X: batch_x, Y_: batch_y, step: i})
print(sess.run(accuracy, feed_dict={X: mnist.test.images, Y_: mnist.test.labels}))

这是我得到的错误:

tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype int32

如果我删除这一行,错误就会消失并且张量板工作正常:

tf.summary.scalar("learning_rate", learning_rate)

最佳答案

看起来您没有发布所有代码。有一个 step 变量可能是一个占位符,您没有将其值传递给摘要运行。由于需要计算当前的学习率,因此我假设您可以通过将 step 添加到 feed_dict 来修复错误:

s = sess.run(merged_summary, feed_dict={X: batch_x, Y_: batch_y, step: i})

关于python - 仅 1 个标量的 Tensorboard 摘要标量错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51583461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com