如何进行Tensorflow中Session和InteractiveSession的比较-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
如何进行Tensorflow中Session和InteractiveSession的比较

如何进行Tensorflow中Session和InteractiveSession的比较,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

成都创新互联公司服务项目包括宾县网站建设、宾县网站制作、宾县网页制作以及宾县网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,宾县网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到宾县省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

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

看完上述内容,你们掌握如何进行Tensorflow中Session和InteractiveSession的比较的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


当前标题:如何进行Tensorflow中Session和InteractiveSession的比较
标题网址:http://scgulin.cn/article/iiiigc.html