On Tensorflow 1.12 I'm trying to edit a variable, but even after running the assignment operation, the updated value is not being saved.
import tensorflow as tf
tf.reset_default_graph()
g = tf.Graph()
with g.as_default(), tf.Session(graph=g) as sess:
w = tf.Variable(2,name = "VARIABLE")
sess.run(tf.global_variables_initializer())
y = sess.run(w)
print('initial value', y)
ww = tf.assign(w, 3)
y = sess.run(ww)
print('changed value', y)
saver = tf.train.Saver()
save_path = saver.save(sess, './test_1')
model_path = "./test_1.meta"
g = tf.Graph()
with g.as_default():
sess = tf.Session(graph=g)
saver = tf.train.import_meta_graph(model_path, clear_devices=True)
saver.restore(sess, model_path.replace('.meta', ''))
sess.run(tf.global_variables_initializer())
gb = tf.global_variables()
print(gb)
w = gb[0]
y = sess.run(w)
print('loaded value', y)
outputs
('initial value', 2)
('changed value', 3)
INFO:tensorflow:Restoring parameters from ./test_1
[<tf.Variable 'VARIABLE:0' shape=() dtype=int32_ref>]
('loaded value', 2)
where the loaded value is not giving the expected value 3.