Search code examples
pythontensorflowmachine-learningtensorboard

Tensorflow summary: adding a variable which does not belong to computational graph


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?


Solution

  • 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()