- Hands-On Reinforcement Learning with Python
- Sudharsan Ravichandiran
- 178字
- 2021-06-18 19:12:08
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.
- AngularJS Testing Cookbook
- FFmpeg入門詳解:音視頻流媒體播放器原理及應用
- Learn Programming in Python with Cody Jackson
- MySQL數據庫管理與開發(慕課版)
- 軟件品質之完美管理:實戰經典
- Tableau 10 Bootcamp
- Java高并發核心編程(卷1):NIO、Netty、Redis、ZooKeeper
- Swift 4 Protocol-Oriented Programming(Third Edition)
- C++語言程序設計
- 區塊鏈項目開發指南
- 零基礎學Python編程(少兒趣味版)
- R語言數據挖掘:實用項目解析
- 從零開始構建深度前饋神經網絡:Python+TensorFlow 2.x
- MATLAB 2020 GUI程序設計從入門到精通
- Offer來了:Java面試核心知識點精講(框架篇)