ValueError:变量rnn/basic_rnn_cell/kernel已存在,不允许使用.您是要在VarScope中设置"reuse = True"还是"reuse = tf.AUTO_REUSE"? [英] ValueError: Variable rnn/basic_rnn_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?

查看:881
本文介绍了ValueError:变量rnn/basic_rnn_cell/kernel已存在,不允许使用.您是要在VarScope中设置"reuse = True"还是"reuse = tf.AUTO_REUSE"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何想法如何解决下面显示的问题?根据我在网上找到的信息,它与重用张量流范围的问题有关,但是没有任何效果.

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.

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)

还有这个

with tf.variable_scope('scope', reuse = True ):
 states_series, current_state = tf.nn.dynamic_rnn(cell=cell, inputs=batchX_placeholder, dtype=tf.float32)

还有这个

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)

有什么想法吗?

推荐答案

第一次运行模型(打开新的python控制台时)会发生这种情况吗?

Does this happen when you run the model for the first time (upon opening a new python console)?

如果不是,则需要清除计算图.您可以通过在脚本的开头放置这一行来做到这一点.

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()

这篇关于ValueError:变量rnn/basic_rnn_cell/kernel已存在,不允许使用.您是要在VarScope中设置"reuse = True"还是"reuse = tf.AUTO_REUSE"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆