tensorflow - Tensorboard scalars and graphs duplicated -


i'm using tensorboard visualize network metrics , graph.

i create session sess = tf.interactivesession() , build graph in jupyter notebook.

in graph, include 2 summary scalars:

with tf.variable_scope('summary') scope:        loss_summary = tf.summary.scalar('loss', cross_entropy)    train_accuracy_summary = tf.summary.scalar('train_accuracy', accuracy) 

i create summary_writer = tf.summary.filewriter(logdir, sess.graph) , run:

_,loss_sum,train_accuracy_sum=sess.run([...],feed_dict=feed_dict)

i write metrics:

summary_writer.add_summary(loss_sum, i) summary_writer.add_summary(train_accuracy_sum, i)  

i run code 3 times.

each time run, re-import tf , create new interactive session.

but, in tensorboard, separate scalar window created each run:

enter image description here

also, graph appears duplicated if check data last run:

enter image description here

how prevent duplication of graph , scalar window each time run?

  • i want data appear in same scalar plots (with multiple series / plot).
  • i want each run reference single graph visualization.

i suspect problem arises because running code 3 times in process (same script, jupyter notebook, or whatever), , invocations share same "default graph" in tensorflow. tensorflow needs give each node in graph unique name, appends "_1" , "_2" names of summary nodes in second , third invocations.

how avoid this? easiest way create new graph each time run code. there (at least) 3 ways this:

  • wrap code in with tf.graph().as_default(): block, constructs new tf.graph object , sets default graph extent of with block.

  • if construct session before creating graph, can construct session sess = tf.interactivesession(graph=tf.graph()). newly constructed tf.graph object remains default graph until call sess.close().

  • call tf.reset_default_graph() between invocations of code.

the with-block approach "most structured" way things, , might best if writing standalone script. however, since using tf.interactivesession, assume using interactive repl of kind, , other 2 approaches more useful (e.g. splitting execution across multiple cells).


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -