0

I am on Eager Mode, and I am trying to plot the evolution of some scalars in TensorBoard. I have managed to do it for one - the loss function - by using:

        summary_writer = tf.contrib.summary.create_file_writer(log_dir, flush_millis=10000)
        with summary_writer.as_default(), tf.contrib.summary.always_record_summaries():
        tf.contrib.summary.scalar("loss", curr_loss)

However, if I add another line of code with

        tf.contrib.summary.scalar("phi", phi)

then it does not get recorded (or at least it does not show up in TensorBoard). I couldn't find many references for this, but the ones I did find made me write it like this...

Does anyone know how to do this properly? Thanks!

python_enthusiast
  • 896
  • 2
  • 7
  • 26

1 Answers1

1

If you follow the guide closely you will have 3 crutial steps to get your summary written: 1. Create summaries

phi_summary_op = tf.contrib.summary.scalar("phi", phi)

1.2. (optional) Collect all summaries in one operations

merged = tf.summary.merge_all()

2. Execute summary op in your session along with traing (or validation) step:

summary, _ = sess.run([merged, train_step], feed_dict=feed_dict(True))

3. Write the result into corresponding log file:

train_writer = tf.summary.FileWriter(FLAGS.summaries_dir + '/train',
                                      sess.graph)
train_writer.add_summary(summary, i)

I hope it helps

y.selivonchyk
  • 8,987
  • 8
  • 54
  • 77
  • Sorry, I forgot to say that I am using eager mode. I cannot use sess or tf.summary.FileWriter. This is why I am using tf.contrib.summary.create_file_writer to write the summary. – python_enthusiast May 18 '19 at 03:02
  • @python_enthusiast did you try summary_writer.flush() asfter call to scalar(...) ? – y.selivonchyk May 18 '19 at 03:06
  • I tried it now (didn't know it existed, to be honest). I am running tf.contrib.summary.scalar("loss", curr_loss) tf.contrib.summary.scalar("phi", self.phi) tf.contrib.summary.merge_all() tf.contrib.summary.flush(). But it does not work yet. – python_enthusiast May 18 '19 at 03:10
  • Than I would also check 1) your tensorboad script points to the folder with log files 2) log files changes size when training is running – y.selivonchyk May 18 '19 at 03:22
  • 1
    For (1) it does because when I run the code I get a new plot for the loss function on TensorBoard. For (2) I don't know how to check. But I think I have found what the problem is. My phi is not a tensor like the loss function is. It is just a constant. I will try changing this to see if it works. – python_enthusiast May 18 '19 at 03:29
  • It worked! Thank you for your help. Sorry, I am new to Tensorflow =) – python_enthusiast May 18 '19 at 03:33
  • 1
    We all've been there, no worries) – y.selivonchyk May 18 '19 at 03:37