Tensorboard scalar plotting with epoch number on the horizontal axis

Question:

I am new to TensorFlow, and I recently started to play around a little bit with data visualization using Tensorboard.
I was wondering if it is possible to convert the horizontal axis of the monitoring scalars (I monitor accuracy and loss on train and validation) to show epoch number instead of iteration number.
the only way I can think of how to do it is to change the sampling frequency to one per epoch, but I am interested in keeping the original sampling resolution.

is there a better way?

Asked By: Nir Morgulis

||

Answers:

Yes, you can do this by passing the epoch number to the global_step parameter of the add_summary() method:

summary_writer = tf.summary.FileWriter(log_dir)

my_summary = session.run(my_summary_op, feed_dict)
summary_writer.add_summary(my_summary, global_step=epoch_number)
Answered By: GeertH

One workaround is using add_scalars().

writer = SummaryWriter()
for idx_epoch in range(epochs):
    for idx_batch in range(batches):
        # fetch data
        data, target = None, None
        # compute loss
        loss = nn.L1Loss(data, target)
        # backward propagation

        global_step = idx_epoch*batches+idx_batch
        writer.add_scalars('loss', {'batch':loss}, global_step)
    writer.add_scalars('loss', {'epoch':loss}, global_step)

Note that these codes are actually pseudo codes, which means they cannot run.

Notice that there is a loss writing for every batch as well as every epoch.

Then the tensorboard result will look like this:
enter image description here

Red line records the loss every epoch, while blue line records batchly.

Answered By: zeit
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.