This is really simple; just call
sess = tf.InteractiveSession()
in the beginning, and this will act like the block
with tf.Session() as sess:
See the code below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
a = tf.constant(3) | |
b = tf.constant(2) | |
c = tf.multiply(a, b) | |
# non-interactive session | |
with tf.Session() as sess: | |
print sess.run(a) | |
print b.eval() | |
# interactive session | |
sess = tf.InteractiveSession() | |
print c.eval() # or | |
print sess.run(c) |
No comments:
Post a Comment