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

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.

主站蜘蛛池模板: 搜索| 营口市| 广宗县| 开化县| 古丈县| 碌曲县| 盱眙县| 茌平县| 玛沁县| 肇州县| 山西省| 乌鲁木齐市| 自治县| 永胜县| 景洪市| 陆河县| 塘沽区| 临湘市| 合江县| 班戈县| 延寿县| 内江市| 麦盖提县| 绍兴市| 禄丰县| 中牟县| 南投市| 扶余县| 浏阳市| 玛纳斯县| 天镇县| 河北省| 东兰县| 渝北区| 疏附县| 淳安县| 卓尼县| 巧家县| 宁武县| 双柏县| 县级市|