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

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.

主站蜘蛛池模板: 浙江省| 富民县| 河源市| 铜川市| 株洲县| 永济市| 梅州市| 上虞市| 甘谷县| 常山县| 罗定市| 得荣县| 黑山县| 河池市| 柳州市| 古浪县| 蕉岭县| 石首市| 浦县| 炉霍县| 岑巩县| 博乐市| 右玉县| 中超| 大田县| 阜南县| 临泉县| 财经| 金阳县| 二连浩特市| 上饶市| 陇南市| 舞阳县| 黑河市| 邢台市| 郯城县| 墨脱县| 久治县| 溧阳市| 华坪县| 清河县|