Reputation: 435
I wrote mnist code using Multi Layer Perceptrons. But it doesn't show scalars of accuracy and loss function.(but it successfully shows a graph of a model) If you know, could you give me a clue? Tensorflow version:1.2.0
These are the functions which I want to show in 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
Upvotes: 1
Views: 1357
Reputation: 839
One thing you might be missing is to actually fetch these summaries and write them to disk.
First, you have to define a FileWriter:
fw = tf.summary.FileWriter(LOGS_DIR) # LOGS_DIR should correspond to the path you want to save the summaries in
Next, merge all your summaries into a single op:
summaries_op = tf.summary.merge_all()
Now, within your training loop, make sure you write the summaries to disk:
for i in range(NUM_ITR):
_, summaries_str = sess.run([train_op, summaries_op])
fw.add_summary(summaries_str, global_step=i)
In order to see these summaries in tensorboard run:
tensorboard --logdir=LOGS_DIR
Upvotes: 1