Python 张量板不';不显示标量

Python 张量板不';不显示标量,python,tensorflow,deep-learning,tensorboard,Python,Tensorflow,Deep Learning,Tensorboard,我使用多层感知器编写了mnist代码。但它并没有显示精度和损失函数的标量(但它成功地显示了模型的图形) 如果你知道,你能给我一个线索吗? Tensorflow版本:1.2.0 这些是我想在Tensorboard中展示的函数 def loss(label,y_inf): # Cost Function basic term with tf.name_scope('loss'): cross_entropy = -tf.reduce_sum(label * tf.lo

我使用多层感知器编写了mnist代码。但它并没有显示精度和损失函数的标量(但它成功地显示了模型的图形) 如果你知道,你能给我一个线索吗? Tensorflow版本:1.2.0

这些是我想在Tensorboard中展示的函数

def loss(label,y_inf):
    # Cost Function basic term
    with tf.name_scope('loss'):
        cross_entropy = -tf.reduce_sum(label * tf.log(y_inf))
    tf.summary.scalar("cross_entropy", cross_entropy)
    return cross_entropy



def accuracy(y_inf, labels):
    with tf.name_scope('accuracy'):
        correct_prediction = tf.equal(tf.argmax(y_inf, 1), tf.argmax(labels, 1))
        accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
    tf.summary.scalar("accuracy", accuracy)
    return accuracy

您可能缺少的一件事是实际获取这些摘要并将其写入磁盘

首先,您必须定义一个FileWriter:

fw = tf.summary.FileWriter(LOGS_DIR) # LOGS_DIR should correspond to the path you want to save the summaries in
接下来,将所有摘要合并到一个op中:

summaries_op = tf.summary.merge_all()
现在,在培训循环中,确保将摘要写入磁盘:

for i in range(NUM_ITR):
    _, summaries_str = sess.run([train_op, summaries_op])
    fw.add_summary(summaries_str, global_step=i)
为了在tensorboard run中查看这些摘要:

tensorboard --logdir=LOGS_DIR