LoginSignup
12
9

More than 5 years have passed since last update.

TensorFlow > link > tf.InteractiveSession() > tf.Session()との違い

Last updated at Posted at 2016-10-24

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())
12
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
9