<reponame>simonfong6/micro-projects
# restore.py

import tensorflow as tf

tf.reset_default_graph()
# Create some variables.
v1 = tf.get_variable("v1", [3], initializer = tf.zeros_initializer)
v2 = tf.get_variable("v2", [5], initializer = tf.zeros_initializer)

# Add ops to save and restore only `v2` using the name "v2"
saver = tf.train.Saver({"v2": v2})

# Use the saver object normally after that.
with tf.Session() as sess:
  # Initialize v1 since the saver will not.
  v1.initializer.run()
  saver.restore(sess, "./model.ckpt")

  print("v1 : %s" % v1.eval())
  print("v2 : %s" % v2.eval())

# restore.py

import tensorflow as tf

tf.reset_default_graph()
# Create some variables.
v1 = tf.get_variable("v1", [3], initializer = tf.zeros_initializer)
v2 = tf.get_variable("v2", [5], initializer = tf.zeros_initializer)

# Add ops to save and restore only `v2` using the name "v2"
saver = tf.train.Saver({"v2": v2})

# Use the saver object normally after that.
with tf.Session() as sess:
  # Initialize v1 since the saver will not.
  v1.initializer.run()
  saver.restore(sess, "./model.ckpt")

  print("v1 : %s" % v1.eval())
  print("v2 : %s" % v2.eval())
# restore.py # Create some variables. # Add ops to save and restore only `v2` using the name "v2" # Use the saver object normally after that. # Initialize v1 since the saver will not.