I want to restore a variable object. That is, I want to have an object of type tensorflow.Variablesafter deserialization.
I am trying to use MetaGraph . Here is a minimal example. Serialization:
import tensorflow as tf
var = tf.Variable(101)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver()
tf.add_to_collection('var', var)
saver.save(sess, 'data/sess')
Deserialization
import tensorflow as tf
with tf.Session() as sess:
saver = tf.train.import_meta_graph('data/sess.meta')
saver.restore(sess, 'data/sess')
var = tf.get_collection('var')[0]
print(var)
print(type(var))
print(tf.get_collection('variables'))
test_var = tf.get_collection('variables')[0]
print(test_var.name)
The problem is that the object tf.get_collectionreturns tf.Tensor, not
tf.Variable. But I see objects tf.Variablein the collection variables.
What is the correct way to restore an object Variable?
source
share