Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 917
freude Avatar asked Apr 10 '17 11:04

freude


People also ask

Does TensorFlow creates a computational graph?

In TensorFlow, machine learning algorithms are represented as computational graphs. A computational graph is a type of directed graph where nodes describe operations, while edges represent the data (tensor) flowing between those operations.

What is TensorFlow computational graph?

Graphs are data structures that contain a set of tf. Operation objects, which represent units of computation; and tf. Tensor objects, which represent the units of data that flow between operations. They are defined in a tf. Graph context.

Why TensorFlow use computational graphs?

Why tensorflow uses computational graphs? Exp: Tensorflow uses computational graphs because calculations can be done in parallel.


2 Answers

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()
like image 81
Juan Leni Avatar answered Oct 28 '22 08:10

Juan Leni


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)
like image 1
Cauchyzhou Avatar answered Oct 28 '22 07:10

Cauchyzhou