Reputation: 928
I'm trying to send some values to tensorboard from Jupyter notebook
with tf.Session() as sess:
param = tf.Variable(0.1)
param_summary = tf.scalar_summary("param", param)
merge_op = tf.merge_all_summaries()
writer = tf.train.SummaryWriter("/tmp/tflogs/test_tb", sess.graph)
init = tf.initialize_all_variables()
sess.run(init)
for i in range(10):
ass = tf.assign(param, i*0.5)
sess.run(ass)
mo = sess.run(merge_op) # Fails with "Duplicate tag param found in summary inputs" message
writer.add_summary(mo,i)
writer.flush()
The problem is that it fails after the first run with InvalidArgumentError: Duplicate tag param found in summary inputs
message (full text here: http://pastebin.com/dTBdCkHc)
How do I make it work with consequent runs?
Upvotes: 2
Views: 5801
Reputation: 161
I wrote a Jupyter extension for tensorboard integration. It can:
Github: https://github.com/lspvic/jupyter_tensorboard
jupyter tensorboard integration
Upvotes: 1
Reputation: 421
You could try this
First cell, only run once. This is where you create your graph.
sess = tf.Session()
param = tf.Variable(0.1)
param_summary = tf.scalar_summary("param", param)
merge_op = tf.merge_all_summaries()
writer = tf.train.SummaryWriter("/tmp/tflogs/test_tb", sess.graph)
Second cell, run as many times as you want. This is where you initialize and run your graph (you could also not run the initialization operation every time). You will be writing the summaries to the same tensorboard file every time unless you use a new writer.
init = tf.global_variables_initializer() #tf.initialize_all_variables() is deprecated
sess.run(init)
for i in range(10):
ass = tf.assign(param, i*0.5)
sess.run(ass)
mo = sess.run(merge_op) # Fails with "Duplicate tag param found in summary inputs" message
writer.add_summary(mo,i)
writer.flush()
What is happening is that with every call to your cell you are adding a new variable and summary to the graph, duplicating the names of the summary, causing an error. tf.reset_default_graph()
also works because it removes all the nodes and then you can create them again, but this is not needed.
Upvotes: 1
Reputation: 4717
I was experiencing a different kind of error in jupyter when running tensorboard:
InvalidArgumentError: You must feed a value for placeholder tensor...
but this was solved by the same recipe as above - first run this on a cell:
tf.reset_default_graph()
then re-run again the graph
Upvotes: 1
Reputation: 5162
I got around this by adding this at the end of the cell or in another cell to be run in between runs.
tf.reset_default_graph()
The other thing you could try is to use
sess = tf.InteractiveSession()
Upvotes: 3