Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement