首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >variables_to_restore有NotFoundError

variables_to_restore有NotFoundError
EN

Stack Overflow用户
提问于 2018-02-19 15:19:07
回答 1查看 236关注 0票数 0

我有一个变量v,并想对它应用移动平均。我应用了以下步骤来保存它:

代码语言:javascript
复制
import tensorflow as tf
v=tf.Variable(0,dtype=tf.float32,name='v')
ema=tf.train.ExponentialMovingAverage(0.99)
maintain_averages_op=ema.apply(tf.global_variables())
init=tf.global_variables_initializer()
saver=tf.train.Saver()
with tf.Session() as sess:
    sess.run(init)
    sess.run(tf.assign(v,10))
    sess.run(maintain_averages_op)
    saver.save(sess, 'C:/Users/User/PycharmProjects/Neural_Network.model.ckpt')
    sess.run([v, ema.average(v)])

保存此会话后,我想恢复它,并使用variables_to_restore直接将'v/ExponentialMovingAverage'分配给v。以下是代码:

代码语言:javascript
复制
v=tf.Variable(0,dtype=tf.float32,name='v')
ema=tf.train.ExponentialMovingAverage(0.99)
print(ema.variables_to_restore())
saver=tf.train.Saver(ema.variables_to_restore())
with tf.Session() as sess:
    saver.restore(sess,'C:/Users/User/PycharmProjects/Neural_Network.model.ckpt')
    sess.run(v)

但是,也有NotFoundError:

代码语言:javascript
复制
NotFoundError (see above for traceback): Key v/ExponentialMovingAverage/ExponentialMovingAverage_1 not found in checkpoint

我对print(ema.variables_to_restore())的输出有点困惑

代码语言:javascript
复制
{'v/ExponentialMovingAverage/ExponentialMovingAverage_1': <tf.Variable 'v/ExponentialMovingAverage:0' shape=() dtype=float32_ref>, 'v_1/ExponentialMovingAverage_1': <tf.Variable 'v_1:0' shape=() dtype=float32_ref>, 'v_3/ExponentialMovingAverage': <tf.Variable 'v_3:0' shape=() dtype=float32_ref>, 'v/ExponentialMovingAverage_2': <tf.Variable 'v:0' shape=() dtype=float32_ref>, 'v_2/ExponentialMovingAverage_1': <tf.Variable 'v_2:0' shape=() dtype=float32_ref>, 'v/ExponentialMovingAverage_1': <tf.Variable 'v/ExponentialMovingAverage_1:0' shape=() dtype=float32_ref>, 'v_1/ExponentialMovingAverage': <tf.Variable 'v_1/ExponentialMovingAverage:0' shape=() dtype=float32_ref>, 'v/ExponentialMovingAverage/ExponentialMovingAverage': <tf.Variable 'v/ExponentialMovingAverage/ExponentialMovingAverage:0' shape=() dtype=float32_ref>, 'v_2/ExponentialMovingAverage': <tf.Variable 'v_2/ExponentialMovingAverage:0' shape=() dtype=float32_ref>}

为什么有这么多变量,v_1, v_2等等?如何使用variables_to_restore校正NotFoundError并计算v的移动平均值

EN

回答 1

Stack Overflow用户

发布于 2018-08-16 05:21:02

如果在同一程序中调用tf.train.ExponentialMovingAverage(0.99)两次,则会创建ExponentialMovingAverage_1。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48861215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档