In [7]:
import pickle
import tensorflow as tf

Save model


In [2]:
x = tf.Variable([1.], name="x")
y = tf.Variable([2.], name="y")
tf.add_to_collection("vars", x)
tf.add_to_collection("vars", y)

In [3]:
sess = tf.Session()
sess.run(tf.global_variables_initializer())

In [4]:
model_saver = tf.train.Saver()
model_saver.save(sess, "./my-model")


Out[4]:
'./my-model'

Load model


In [5]:
sess = tf.Session()
new_saver = tf.train.import_meta_graph('./my-model.meta')
new_saver.restore(sess, "./my-model")
#new_saver.restore(sess, tf.train.latest_checkpoint('./'))

In [6]:
# tf.get_collection() returns a list. In this example we only want the
all_vars = tf.get_collection("vars")

for v in all_vars:
    v_ = sess.run(v)
    print(v_)


[ 1.]
[ 2.]
[ 1.]
[ 2.]

In [ ]: