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

  • 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.

主站蜘蛛池模板: 汝阳县| 泽普县| 盱眙县| 云霄县| 库车县| 五河县| 岗巴县| 盐山县| 房山区| 辽宁省| 浏阳市| 兰考县| 郁南县| 平原县| 盐源县| 荥阳市| 岑巩县| 区。| 苏尼特左旗| 宾阳县| 纳雍县| 九龙县| 于都县| 原平市| 金湖县| 磴口县| 秦皇岛市| 乌鲁木齐县| 甘德县| 德格县| 蒙自县| 宁海县| 阿勒泰市| 丹棱县| 如皋市| 买车| 仁布县| 南陵县| 枣阳市| 工布江达县| 黄山市|