官术网_书友最值得收藏!

  • Python Reinforcement Learning
  • Sudharsan Ravichandiran Sean Saito Rajalingappaa Shanmugamani Yang Wenzhuo
  • 178字
  • 2021-06-24 15:17:29

Sessions

Computation graphs will only be defined; in order to execute the computation graph, we use TensorFlow sessions:

sess = tf.Session()

We can create the session for our computation graph using the tf.Session() method, which will allocate the memory for storing the current value of the variable. After creating the session, we can execute our graph with the sess.run() method.

In order to run anything in TensorFlow, we need to start the TensorFlow session for an instance; please refer to the code:

import tensorflow as tf
a = tf.multiply(2,3)
print(a)

It will print a TensorFlow object instead of 6. As already said, whenever we import TensorFlow a default computation graph will automatically be created and all nodes a that we created will get attached to the graph. In order to execute the graph, we need to initialize a TensorFlow session as follows:

#Import tensorflow 
import tensorflow as tf

#Initialize variables
a = tf.multiply(2,3)

#create tensorflow session for executing the session
with tf.Session() as sess:
#run the session
print(sess.run(a))

The preceding code will print 6.

主站蜘蛛池模板: 广西| 醴陵市| 景泰县| 奉化市| 韶山市| 广德县| 湖州市| 丰宁| 三亚市| 巨野县| 手游| 兴和县| 额敏县| 新密市| 田东县| 孟连| 乌兰县| 利津县| 马公市| 阿拉善左旗| 彭州市| 双辽市| 长沙市| 叶城县| 赞皇县| 藁城市| 竹溪县| 广东省| 仲巴县| 清水河县| 司法| 西贡区| 阿城市| 孝感市| 嘉禾县| 三台县| 北流市| 临澧县| 永丰县| 栖霞市| 乳山市|