mnist_with_summaries.py
にある以下のコード
sess = tf.InteractiveSession()
tf.Session()と何が違うのかというのは以下を見つけた。
The only difference with a regular Session is that an InteractiveSession installs itself as the default session on construction. The methods Tensor.eval() and Operation.run() will use that session to run ops.
This is convenient in interactive shells and IPython notebooks, as it avoids having to pass an explicit Session object to run ops.
InteractiveSession()の場合
sess = tf.InteractiveSession()
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b
# We can just use 'c.eval()' without passing 'sess'
print(c.eval())
sess.close()
Session()の場合
Session()で同じようなことをする場合 with 構文が必要になりそう。
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b
with tf.Session():
# We can also use 'c.eval()' here.
print(c.eval())