Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import tensorflow as tf
  2. import numpy as np
  3. ## save to a file
  4. ## need to use the same shape and dtype when restore
  5. W = tf.Variable([[1,2,3],[3,4,5]], dtype=tf.float32, name='W')
  6. b = tf.Variable([[1,2,3]],dtype=tf.float32, name='b')
  7.  
  8.  
  9. # initialization
  10. init = tf.global_variables_initializer()
  11. saver = tf.train.Saver()
  12.  
  13. with tf.Session() as sess:
  14. sess.run(init)
  15. saver.save(sess, '/tmp/save.ckpt')
  16.  
  17. tf.reset_default_graph()
  18.  
  19. W = tf.Variable(np.arange(6).reshape((2,3)), dtype=tf.float32, name='W')
  20. b = tf.Variable(np.arange(3).reshape((1,3)), dtype=tf.float32, name='b')
  21.  
  22.  
  23. saver = tf.train.Saver()
  24. with tf.Session() as sess:
  25. saver.restore(sess, '/tmp/save.ckpt')
  26. print('weights', sess.run(W))
  27. print('biases', sess.run(b))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement