So there are actually several ways to do this.
Saving the graph control point approach
- Build your schedule.
- Initialize all variables.
- Starting a session to assign values to each variable.
- save a breakpoint for loading during training.
- use breakpoint in train
Using model initialization and recovery
: Tensorflow Model Recovery. , tf.train.Scaffold init_fn init.
, :
with tf.Graph().as_default():
some code...
sess = tf.Session()
with sess.as_default():
init_op = tf.global_variables_initializer()
sess.run(init_op)
data_dict = np.load('your_pass/model.npy', encoding='latin1').item()
var = tf.get_variable(param_name)
sess.run(var.assign(data_dict))
print('assignment done!')
saver = tf.train.Saver()
save_path = saver.save(sess, FLAGS.train_dir)
print("Model saved in file: %s" % save_path)