【发布时间】:2018-08-05 01:14:25
【问题描述】:
我首先训练了网络N,并使用保护程序将其保存到检查点Checkpoint_N。在N 中定义了一些变量范围。
现在,我想使用这个 trained 网络 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.
当我执行上述操作时,restore 语句会抛出一个Key Error,即在N 图表中的每个变量的检查点文件中找不到siameseN/conv1。
有没有办法做到这一点,而无需更改N 的代码?我基本上只是为N 中的每个变量和操作添加了一个父作用域。我可以通过告诉 tensorflow 忽略父范围之类的东西来将权重恢复到正确的变量吗?
【问题讨论】:
标签: python tensorflow