值错误:变量rnn/basic\u rnn\u cell/kernel已存在,不允许。您的意思是在VarScope中设置reuse=True还是reuse=tf.AUTO_reuse?

2024-05-18 23:40:16 发布

您现在位置:Python中文网/ 问答频道 /正文

有什么办法可以解决下面的问题吗?根据我在web上找到的信息,它与重用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):

我试过像这样的东西

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)

有什么想法吗?


Tags: intfcelldynamicnncurrentplaceholderseries
1条回答
网友
1楼 · 发布于 2024-05-18 23:40:16

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

如果不是,你需要清除你的计算图。你可以把这一行放在脚本的开头。

tf.reset_default_graph()

相关问题 更多 >

    热门问题