It's not duplicate of How to assign value to a tensorflow variable?
I was trying to do simpliest thing: just swap variables Tensorflow: how to swap variables between scopes and set variables in scope from another, and I still can't do it.
BUT now I know that assign
changes even copy of tensor which I get with tf.identity
. I don't want this. I need copy of variable for swapping.
In [10]: a = tf.Variable(1)
In [11]: b = tf.identity(a)
In [12]: a += 1
In [14]: sess.run(a)
Out[14]: 2
In [15]: sess.run(b)
Out[15]: 1
In [16]: a = tf.Variable(1)
In [17]: b = tf.identity(a)
In [18]: assign_t = a.assign(2)
In [20]: sess.run(tf.initialize_all_variables())
In [21]: sess.run(a)
Out[21]: 1
In [22]: sess.run(assign_t)
Out[22]: 2
In [23]: sess.run(a)
Out[23]: 2
In [24]: sess.run(b)
Out[24]: 2
How can I assign value to a
without changing b
?