創建在TensorFlow一個Variable
:如何更改TensorFlow中變量的值?
c = tf.Variable([1.0, 2.0, 3.0], tf.float32)
然後我定義的佔位符:
x = tf.placeholder(tf.float32)
之後我定義一個函數(計算圖)組合兩個定義的對象之上:
y = x + c
之後我「初始化」全局變量:
s = tf.Session()
init = tf.global_variables_initializer()
s.run(init)
最後,我可以運行我的功能:
s.run(y, {x : [10.0, 20.0, 30.0]})
現在,我要換c
值。在TensorFlow中可能嗎?我試過,例如:
c = tf.assign(c, [1.0, 1.0, 1.0])
也:
c = tf.Variable([1.0, 1.0, 1.0], tf.float32)
沒有什麼工作。每當我打電話
s.run(y, {x : [10.0, 20.0, 30.0]})
我仍然得到舊的結果(對應於c
老/初始值)。
那麼,如何爲TensorFlow中的全局變量賦值?