Error While Running Tensorflow A Second Time
Solution 1:
This is a matter of how TF works. One needs to understand that TF has a "hidden" state - a graph being built. Most of the tf functions create ops in this graph (like every tf.Variable call, every arithmetic operation and so on). On the other hand actual "execution" happens in the tf.Session(). Consequently your code will usually look like this:
build_graph()
with tf.Session() as sess:
process_something()
since all actual variables, results etc. leave in session only, if you want to "run it twice" you would do
build_graph()
with tf.Session() as sess:
process_something()
with tf.Session() as sess:
process_something()
Notice that I am building graph once. Graph is an abstract representation of how things look like, it does not hold any state of computations. When you try to do
build_graph()
with tf.Session() as sess:
process_something()
build_graph()
with tf.Session() as sess:
process_something()
you might get errors during second build_graph() due to trying to create variables with the same names (what happens in your case), graph being finalised etc. If you really need to run things this way you simply have to reset graph in between
build_graph()
with tf.Session() as sess:
process_something()
tf.reset_default_graph()
build_graph()
with tf.Session() as sess:
process_something()
will work fine.
Post a Comment for "Error While Running Tensorflow A Second Time"