What's the difference between tf.Session() and tf.InteractiveSession()?

前端 未结 4 1735
-上瘾入骨i
-上瘾入骨i 2020-12-12 13:28

In which cases should tf.Session() and tf.InteractiveSession() be considered for what purpose?

When I tried to use the former one, some fun

4条回答
  •  执念已碎
    2020-12-12 14:25

    Mainly taken from official documentation:

    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 allows to use interactive context, like shell, as it avoids having to pass an explicit Session object to run op:

    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()
    

    It is also possible to say, that InteractiveSession supports less typing, as allows to run variables without needing to constantly refer to the session object.

提交回复
热议问题