tf.session()


tf.session對象是執行Operation運算的一個封裝環境。Tensor對象會在此執行。

比如:

 1 # Build a graph.
 2 a = tf.constant(5.0)
 3 b = tf.constant(6.0)
 4 c = a * b
 5 
 6 # Launch the graph in a session.
 7 sess = tf.compat.v1.Session()
 8 
 9 # Evaluate the tensor `c`.
10 print(sess.run(c)) # prints 30.0

 

一個Session會話在調用完成之后是需要釋放的,使用close()方法來釋放session。

1 # Using the `close()` method.
2 sess = tf.compat.v1.Session()
3 sess.run(...)
4 sess.close()

除此之外,也可以使用with語句來打開Session

1 with tf.compat.v1.Session() as sess:
2   sess.run(...)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM