After inspecting a checkpoint (let's call it model 1) I obtained the following list of variable names in it (shortened for simplicity):
var_list = ["ex1_model/fc2/b",
"ex1_model/fc2/b/Adam",
"ex1_model/fc2/b/Adam_1",
"ex1_model/fc2/w",
"ex1_model/fc2/w/Adam"]
Suppose I have a much bigger model 2 and want to initialize parts of it with the values from model 1.
Obtain variables from names as described here (because I didn't find an easy way to do it):
def get_vars_by_name(names):
return [v for v in tf.global_variables() if v.name in names]
Build model 2 and a saver to restore:
logits = build_model(inputs)
saver = tf.train.Saver(var_list=get_vars_by_name(var_list))
At
saver.restore(sess, tf.train.latest_checkpoint(checkpoints_dir))
I receive the error:
"ex1_model/fc2/w/Adam" [...] raise ValueError("No variables to save")
Please help me find the mistake I made. I'd also be grateful for a simpler way because this is terrible. Thank you.