tensorflow:提示找不到Adam或者RMSProp变量,Did you mean to set reuse=None in VarScope?
来源:互联网 发布:linux 开机卡在进度条 编辑:程序博客网 时间:2024/06/05 07:07
错误的完整信息
Variable discriminator/conv/weights/RMSProp/does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=None in VarScope?
这个错误是在使用优化函数
tf.train.RMSPropOptimizer()tf.train.AdamOptimizer()
引起的,使用梯度下降算法反而没有出现问题,
并且使用了 tf.get_variable_scope().reuse_variables()
原因是使用Adam或者RMSProp优化函数时,Adam函数会创建一个Adam变量,目的是保存你使用tensorflow创建的graph中的每个可训练参数的动量,但是这个Adam是在reuse=True条件下创建的,之后reuse就回不到None或者False上去,当reuse=True,就会在你当前的scope中reuse变量,如果在此scope中进行优化操作,就是使用AdamOptimizer等,他就会重用slot variable,这样子会导致找不到Adam变量,进而报错。
设置reuse=True的地方是
tf.get_variable_scope().reuse_variables()
或者
With tf.variable_scope(name) as scope : Scope.reuse_variables()
一般在运行GAN程序的时候会用到这段代码。解决方法就是将这个scope独立出来,reuse=True
就只在当前scope中起作用,使用
With tf.variable_scope(tf.get_variables_scope())
把它放在需要调用函数的地方,我这里是discriminator函数:
代码更改如下所示:
Wrong:
G = generator(z) D, D_logits = discriminator(images) samples = sampler(z) D_, D_logits_ = discriminator(G, reuse=True)
True:
with tf.variable_scope("for_reuse_scope"): G = generator(z) D, D_logits = discriminator(images) samples = sampler(z) D_, D_logits_ = discriminator(G, reuse=True)
我看有的人说在使用优化函数的上面加with。。。这句话,但是我试用了并没有用。
类似这样:
with tf.variable_scope(tf.get_variable_scope(), reuse=None):#新增 d_optim = tf.train.RMSPropOptimizer(LR).minimize(d_loss,var_list=d_vars, global_step=global_step) g_optim = tf.train.RMSPropOptimizer(LR).minimize(g_loss,var_list=g_vars, global_step=global_step)
另外,出现此问题的原因也可能是在该复用网络参数的时候没有复用,复用时要设置reuse= True
阅读全文
1 0
- tensorflow:提示找不到Adam或者RMSProp变量,Did you mean to set reuse=None in VarScope?
- Variable has existed/does not exist ,Did you mean to set reuse=True/None?
- Multiple substitutions specified in non-positional format; did you mean to add the formatted="false"
- Multiple substitutions specified in non-positional format; did you mean to add the formatted="false"
- Multiple substitutions specified in non-positional format;did you mean to add the formatted="false"
- Codeforces858C Did you mean
- cf434A. Did you mean...
- *** missing separator (did you mean TAB instead of 8 spaces?)或者*** missing separator的解决办法
- error: no type named 'string' in namespace 'std'; did you mean 'std::string'? [3]
- 继承QGraphicsItem 编译错误:error: no member named 'staticMetaObject' in 'QGraphicsItem'; did you mean sim
- Did You Mean: Lucene?-- Tom White
- unknown type name''",did you mean""
- Codeforces Round #434 Did you mean...
- 'NSURL' is not implicitly convertible to 'URL'; did you mean to use 'as' to explicitly convert?异常
- 如何快速解决TeXstudio提示的错误:did you pass the "backend=biber" option to BibLaTeX?
- TensorFlow reuse=True BasicRNNCell
- adb的问题“No command 'adb' found, did you mean:”
- "Did you mean" feature with Apache Lucene Spell-Checker
- AngularJS框架
- CentOS下安装jdk
- 解析最外层为数组的json串
- Spring BcryptPasswordEncorder Log Rounds参数说明
- SpringAop中的相关概念
- tensorflow:提示找不到Adam或者RMSProp变量,Did you mean to set reuse=None in VarScope?
- Codeforces 851 D. Arpa and a list of numbers(技巧)
- 3DSlicer25:Report an Error
- hdu 5773 策略+最长上升子序列
- ZOJ
- 什么是ajax?
- WebUploader 上传图片并提交表单(一)
- iText7---Adding low-level content添加低层级内容
- java每日一练