I am a bit confused by how the following code segment runs.
import tensorflow as tf
x = tf.Variable(0)
init_op = tf.initialize_all_variables()
modify_op = x.assign(5)
with tf.Session() as sess:
sess.run(init_op)
print(sess.run(x))
x += 3
print(sess.run(x))
sess.run(init_op) # Trying to initialize x once again to 0
print(sess.run(x)) # Gives out 3, which leaves me confused.
print(sess.run(modify_op))
print(sess.run(x)) # Gives out 8, even more confusing
This is the output:
0
3
3
5
8
Is it that the line x += 3 is not part of the default graph? Or something else is going on? Some help will be appreciated, thanks!