How to compare Session and InteractiveSession in Tensorflow
How to compare Session and InteractiveSession in Tensorflow? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
01
Session
Each Session maintains a copy of its own variable.
As follows:
W = tf.Variable (10)
Sess1 = tf.Session ()
Sess2 = tf.Session ()
Sess1.run (W.initializer)
Sess2.run (W.initializer)
Print sess1.run (W.assign_add (10)) # > > 20
Print sess2.run (W.assign_sub (2)) # > >?
? The equal sign 8 sess2 maintains W respectively, so an increase of 10 W in sess1 does not affect the W of sess2, so it is equal to 10-2-8.
02
Session vs InteractiveSession
Sometimes we see: InteractiveSession, not Session, what's the difference?
One major change is the use of an InteractiveSession, which allows us to run variables without needing to constantly refer to the session object (less typing!).
InteractiveSession ()
Sess = tf.InteractiveSession ()
A = tf.constant (5.0)
B = tf.constant (6. 0)
C = a * b
# We can just use 'c.eval ()' without specifying the context 'sess'
Print (c.eval ())
Sess.close ()
Session ()
Sess = tf.Session ()
A = tf.constant (5.0)
B = tf.constant (6. 0)
C = a * b
With tf.Session () as sess:
Sess.run (print (c.eval ()
After reading the above, have you mastered how to compare Session and InteractiveSession in Tensorflow? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!