Search code examples
pythontensorflowtensorboard

tensorboard average of scalar summaries


I am trying to visualize my output loss values with TensorBoard. The way I do it is straightforward. I just add a summary.scalar after each iteration over a minibatch. In the end of one epoch tensorboard will show me all the losses after each iteration. I want to get the average of all these iterations, meaning I want tensorboard to show me one loss value for each epoch.

Thank you.


Solution

  • Try to create another scalar average and for every step in an epoch calculate a running average like this:

    average = 0
    epoch = 0
    tf.summary.scalar('loss_av', average)
    for step in max_step:
        #other stuff
        average = (average*(step-1)+loss)/step
        if step % steps_per_epoch == 0:
            epoch = epoch + 1
            av = sess.run(tf.constant(average))
            summary_writer.add_summary(av, epoch)