دنبال کننده ها

۱۳۹۶ مهر ۹, یکشنبه

How to save the current value of a variable to another variable in tensorflow?

[ad_1]



I want to save a current value of variable (a_times_two) to the variable (result) , it seems to be an easy task, but it is not.
My first attempt : result = a_times_two
My second attempt: result = tf.assign(a_times_two)





import tensorflow as tf
a = tf.Variable(2, name="scalar")
a_times_two = a.assign(a * 2)
init = tf.global_variables_initializer()

with tf.Session() as sess:
sess.run(init)
print(sess.run(a_times_two))# >> 4
print(sess.run(a_times_two))# >> 8
print(sess.run(a_times_two))# >> 16
**result = a_times_two**1st attempt**
**result = tf.assign(a_times_two)**2nd attempt**
print (sess.run(result))





i want it to print out 4 8 16 16
But it always returns 4 8 16 32
I have no idea about this case, i think it may be a bug. I hope someone could help me. I am new with tensorflow




[ad_2]

لینک منبع