Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 仅1个标量的Tensorboard摘要标量错误_Python_Tensorflow_Machine Learning_Tensorboard - Fatal编程技术网

Python 仅1个标量的Tensorboard摘要标量错误

Python 仅1个标量的Tensorboard摘要标量错误,python,tensorflow,machine-learning,tensorboard,Python,Tensorflow,Machine Learning,Tensorboard,我通过张力板显示了3个标量。其中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(cr

我通过张力板显示了3个标量。其中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 = 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
如果我删除这一行,错误就会消失,tensorboard工作正常:

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

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

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