Python ValueError: 变量 rnn/basic_rnn_cell/kernel 已经存在,不允许。您的意思是在 VarScope 中设置重用 = True 或重用 = tf.AUTO_REUSE 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47296969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ValueError: Variable rnn/basic_rnn_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?
提问by Zoe
Any ideas how can I solve problem shown below? With the information that I found on the web it is associated with problem of reusing tensorflow scope however nothing works.
任何想法如何解决下面显示的问题?根据我在网上找到的信息,它与重用 tensorflow 范围的问题有关,但没有任何效果。
ValueError: Variable rnn/basic_rnn_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:
File "/code/backend/management/commands/RNN.py", line 370, in predict
states_series, current_state = tf.nn.dynamic_rnn(cell=cell, inputs=batchX_placeholder, dtype=tf.float32)
File "/code/backend/management/commands/RNN.py", line 499, in Command
predict("string")
File "/code/backend/management/commands/RNN.py", line 12, in <module>
class Command(BaseCommand):
I tried for instance something like this
我尝试过这样的事情
with tf.variable_scope('scope'):
states_series, current_state = tf.nn.dynamic_rnn(cell=cell, inputs=batchX_placeholder, dtype=tf.float32)
and this
和这个
with tf.variable_scope('scope', reuse = True ):
states_series, current_state = tf.nn.dynamic_rnn(cell=cell, inputs=batchX_placeholder, dtype=tf.float32)
and this
和这个
with tf.variable_scope('scope', reuse = tf.AUTO_REUSE ):
states_series, current_state = tf.nn.dynamic_rnn(cell=cell, inputs=batchX_placeholder, dtype=tf.float32)
Any ideas?
有任何想法吗?
回答by Zoe
Does this happen when you run the model for the first time (upon opening a new python console)?
当您第一次运行模型时(打开一个新的 python 控制台时)会发生这种情况吗?
If not, you need to clear you computational graph. You can do that by putting this line at the beginning of your script.
如果没有,您需要清除计算图。您可以通过将此行放在脚本的开头来做到这一点。
tf.reset_default_graph()