with tf.variable_scope('model_1'):
model one declaration here
...
with tf.variable_scope('model_2'):
model one declaration here
...
with tf.variable_scope('model_3'):
model one declaration here
...
with tf.variable_scope('model_1'):
model one declaration here
...
model_1_variables = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope="model_1")
saver = tf.train.Saver(model_1_variables)
sess = tf.Session()
saver.restore(sess, 'my-model')`
1 回答
最好的方法是使用tensorflow变量范围 . 假设您有model_1,model_2和model_3,并且您只想保存model_1:
首先,在训练代码中定义模型:
接下来,为model_1的变量定义保护程序:
训练时你可以像你提到的那样保存一个检查点:
训练完成后,如果要在评估代码中恢复权重,请确保以相同的方式定义model_1和saver: