Reputation: 3832
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?
Upvotes: 10
Views: 5272
Reputation: 3
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
Upvotes: 0
Reputation: 31
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)
Upvotes: 1
Reputation: 7638
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()
Upvotes: 18