TensorFlow數值加減-認識Variable
阿新 • • 發佈:2018-11-30
tensorflow教程順序有點亂,其實這個應該放在第二篇的,大夥湊合看吧^_^
硬體:NVIDIA-GTX1080
軟體:Windows7、python3.6.5、tensorflow-gpu-1.4.0
一、基礎知識
當tf定義variable時,需要在session定義之後初始化一次!
二、程式碼展示
import tensorflow as tf state = tf.Variable(0, name='counter') #print(state.name) one = tf.constant(1) new_value = tf.add(state, one) update = tf.assign(state, new_value) init = tf.global_variables_initializer() #must have if define variable with tf.Session() as sess: sess.run(init) #must have if define session for i in range(3): sess.run(update) print(sess.run(state))
三、結果展示
1
2
3
任何問題請加唯一QQ2258205918(名稱samylee)!