10

I have a variable that changes with train iterations. The variable is not computed as a part of the computational graph.

Is it possible to add it to the tensorflow summary in order to visualize it together with the loss function?

3 Answers 3

18

Yes, you can create summaries outside the graph.

Here is an example where the summary is created outside the graph (not as a TF op):

output_path = "/tmp/myTest"
summary_writer = tf.summary.FileWriter(output_path)

for x in range(100):
   myVar = 2*x

   summary=tf.Summary()
   summary.value.add(tag='myVar', simple_value = myVar)
   summary_writer.add_summary(summary, x)

summary_writer.flush()
Sign up to request clarification or add additional context in comments.

Comments

1

if you have other summary, you can add new placeholder for the variable what is not computed as a part of the computational graph.

...
myVar_tf = tf.placeholder(dtype=tf.float32)
tf.summary.scalar('myVar', myVar_tf)
merged_summary = tf.summary.merge_all()
...
...
myVar = 0.1
feed_dict = { myVar_tf : myVar}
summary, step = sess.run([merged_summary, global_step],feed_dict=feed_dict)
summary_writer.add_summary(summary, step)

Comments

0

Example for TF 2.0:

def write_list_toTB(list_myVar, main_directory, variable_name= "myVar"):
    output_path = os.path.join(main_directory, variable_name)
    summary_writer = tf.summary.create_file_writer(output_path)

    with summary_writer.as_default():
        for i,val in enumerate(list_myVar):
            tf.summary.scalar(name=variable_name, data=val,step=i)

    summary_writer.flush()

then write in cmd:

tensorboard --logdir main_directory

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.