张量板不显示标量



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

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

首先,您必须定义一个文件编写器:

fw = tf.summary.FileWriter(LOGS_DIR) # LOGS_DIR should correspond to the path you want to save the summaries in

接下来,将所有摘要合并到一个操作中:

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 --logdir=LOGS_DIR

最新更新