前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Tensorflow|Session和InteractiveSession

Tensorflow|Session和InteractiveSession

作者头像
double
发布2018-04-02 17:13:23
6220
发布2018-04-02 17:13:23
举报
文章被收录于专栏:算法channel算法channel算法channel

01

Session

每一个Session都维护各自变量的副本。

如下所示:

W = tf.Variable(10) sess1 = tf.Session() sess2 = tf.Session() sess1.run(W.initializer) sess2.run(W.initializer) print sess1.run(W.assign_add(10)) # >> 20 print sess2.run(W.assign_sub(2)) # >> ?

?等号8,sess1和sess2各自维护W,所以sess1中W增加10,不会影响sess2的W,所以它等于10-2=8.

02

Session vs InteractiveSession

有时候我们会看到:InteractiveSession,而不是Session,它们区别是?

One major change is the use of an InteractiveSession, which allows us to run variables without needing to constantly refer to the session object (less typing!).

InteractiveSession()

sess = tf.InteractiveSession() a = tf.constant(5.0) b = tf.constant(6.0) c = a * b # We can just use 'c.eval()' without specifying the context 'sess' print(c.eval()) sess.close()

Session()

sess = tf.Session() a = tf.constant(5.0) b = tf.constant(6.0) c = a * b with tf.Session() as sess: sess.run(print(c.eval()))

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-02-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 程序员郭震zhenguo 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档