tensorflow函数解析: tf.Session() 和tf.InteractiveSession()

链接如下:

http://stackoverflow.com/questions/41791469/difference-between-tf-session-and-tf-interactivesession

英文

Question:

Questions says everything, for taking sess= tf.Session() and sess=tf.InteractiveSession() which cases should be considered for what purpose ? When I am using former one some function didn't work and when changed to the later it worked (for example .eval()).

Answer:

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.

中文

问题: tf.Session()tf.InteractiveSession()的区别?

答案:

唯一的区别在于:tf.InteractiveSession()加载它自身作为默认构建的session,tensor.eval()和operation.run()取决于默认的session.

换句话说:InteractiveSession 输入的代码少,原因就是它允许变量不需要使用session就可以产生结构。


  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值