我使用Multi Layer Perceptrons编写了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
答案 0 :(得分:1)
您可能缺少的一件事是实际获取这些摘要并将其写入磁盘。
首先,您必须定义一个FileWriter:
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中查看这些摘要:
tensorboard --logdir=LOGS_DIR