Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow Op Naming for Consecutive Runs in Interactive IPython terminal

I've noticed that on subsequent runs of a Tensorflow script, your graph Ops get numbered names for example:

loss = tf.reduce_mean(tf.nn.l2_loss(y - pred), name="l2_loss")

would get the names:

l2_loss
l2_loss_1
l2_loss_2
...
l2_loss_N

as you continue to make the same runs in the same IPython session. This wouldn't be so annoying, except that later in scripts when you want to save a summary:

x_sample, y_sample = get_sample(X, Y)
feed = {x: x_batch, y: y_batch}
trainer.run(feed_dict=feed)
summary_str = summary_op.eval(feed_dict=feed)

you'll get the following failure:

InvalidArgumentError: You must feed a value for placeholder tensor 'x_input' with dtype float ....

Is there a way to (at the top of a script or something) to void all these old, out-of-date Op definitions and use the current run and correctly obey the name=... imperative when creating variables, placeholders, and constants?

like image 206
dubeegee Avatar asked Dec 19 '22 16:12

dubeegee


1 Answers

To your follow-up question, you might be getting the AssertionError due to redefining your interactive session.

sess = InteractiveSession()
sess = InteractiveSession()
Exception AssertionError: AssertionError("Nesting violated for default stack of <type 'weakref'> objects") in ...

You can avoid this by closing the session first, sess.close().

like image 119
DavidWalz Avatar answered Dec 21 '22 10:12

DavidWalz