我N先训练了网络并将其与保护程序一起保存到检查点Checkpoint_N.其中定义了一些变量范围N.
现在,我想使用这个训练有素的网络构建一个暹罗网络N,如下所示:
with tf.variable_scope('siameseN',reuse=False) as scope:
networkN = N()
embedding_1 = networkN.buildN()
# this defines the network graph and all the variables.
tf.train.Saver().restore(session_variable,Checkpoint_N)
scope.reuse_variables()
embedding_2 = networkN.buildN()
# define 2nd branch of the Siamese, by reusing previously restored variables.
Run Code Online (Sandbox Code Playgroud)
当我做以上,恢复语句抛出一个Key Error是siameseN/conv1不是在为每一个变量检查点文件中N的图表.
有没有办法做到这一点,而不改变代码N?我只是基本上为每个变量和操作添加了一个父作用域N.我可以通过告诉tensorflow忽略父范围或其他东西来将权重恢复到正确的变量吗?
这与以下内容有关:如何使用不同名称但形状相同的Tensorflow恢复权重?
tf.train.Saver(var_list={'variable_name_in_checkpoint':var_to_be_restored_to,...'})
可以获取要恢复的变量列表或字典
(e.g. 'variable_name_in_checkpoint':var_to_be_restored_to,...)
Run Code Online (Sandbox Code Playgroud)
您可以通过遍历当前会话变量中的所有变量来准备上面的词典,并使用会话变量作为值并获取当前变量的名称,并从变量名称中删除“ siameseN /”并用作键。从理论上讲,它应该起作用。
| 归档时间: |
|
| 查看次数: |
1809 次 |
| 最近记录: |