吴裕雄 python 神经网络——TensorFlow 图、张量及会话
生活随笔
收集整理的這篇文章主要介紹了
吴裕雄 python 神经网络——TensorFlow 图、张量及会话
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import tensorflow as tfg1 = tf.Graph()
with g1.as_default():v = tf.get_variable("v", [1], initializer = tf.zeros_initializer()) # 設置初始值為0
g2 = tf.Graph()
with g2.as_default():v = tf.get_variable("v", [1], initializer = tf.ones_initializer()) # 設置初始值為1
with tf.Session(graph = g1) as sess:tf.global_variables_initializer().run()with tf.variable_scope("", reuse=True):print(sess.run(tf.get_variable("v")))with tf.Session(graph = g2) as sess:tf.global_variables_initializer().run()with tf.variable_scope("", reuse=True):print(sess.run(tf.get_variable("v"))) import tensorflow as tfa = tf.constant([1.0, 2.0], name="a")
b = tf.constant([2.0, 3.0], name="b")
result = a + b
print resultsess = tf.InteractiveSession ()
print(result.eval())
sess.close() # 創建一個會話。
sess = tf.Session()# 使用會話得到之前計算的結果。
print(sess.run(result))# 關閉會話使得本次運行中使用到的資源可以被釋放。
sess.close() with tf.Session() as sess:print(sess.run(result)) sess = tf.Session()
with sess.as_default():print(result.eval()) sess = tf.Session()# 下面的兩個命令有相同的功能。
print(sess.run(result))
print(result.eval(session=sess)) sess = tf.InteractiveSession ()
print(result.eval())
sess.close() config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True)
sess1 = tf.InteractiveSession(config=config)
sess2 = tf.Session(config=config)
?
轉載于:https://www.cnblogs.com/tszr/p/10872464.html
總結
以上是生活随笔為你收集整理的吴裕雄 python 神经网络——TensorFlow 图、张量及会话的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA语言程序设计课后习题----第四
- 下一篇: 张爱玲《第二炉香》