Created
March 29, 2017 19:40
-
-
Save mrry/01e2de711e62c84018a7c6102925c5ec to your computer and use it in GitHub Desktop.
Saver SO question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import numpy as np | |
## save to a file | |
## need to use the same shape and dtype when restore | |
W = tf.Variable([[1,2,3],[3,4,5]], dtype=tf.float32, name='W') | |
b = tf.Variable([[1,2,3]],dtype=tf.float32, name='b') | |
# initialization | |
init = tf.global_variables_initializer() | |
saver = tf.train.Saver() | |
with tf.Session() as sess: | |
sess.run(init) | |
saver.save(sess, '/tmp/save.ckpt') | |
tf.reset_default_graph() | |
W = tf.Variable(np.arange(6).reshape((2,3)), dtype=tf.float32, name='W') | |
b = tf.Variable(np.arange(3).reshape((1,3)), dtype=tf.float32, name='b') | |
saver = tf.train.Saver() | |
with tf.Session() as sess: | |
saver.restore(sess, '/tmp/save.ckpt') | |
print('weights', sess.run(W)) | |
print('biases', sess.run(b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment