ValueError:变量rnn/basic_rnn_cell/kernel已经存在,不允许.您是不是要在VarScope中设置reuse = True或reuse = tf.AUTO_REUSE?

20 python machine-learning neural-network python-3.x 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):
Run Code Online (Sandbox Code Playgroud)

我试过这样的事情

with tf.variable_scope('scope'):
 states_series, current_state = tf.nn.dynamic_rnn(cell=cell, inputs=batchX_placeholder, dtype=tf.float32)
Run Code Online (Sandbox Code Playgroud)

还有这个

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

还有这个

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)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Zoe*_*Zoe 63

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

如果没有,您需要清除计算图.您可以将此行放在脚本的开头.

tf.reset_default_graph()
Run Code Online (Sandbox Code Playgroud)