python - ValueError : Variable rnn/basic_rnn_cell/kernel already exists, 不允许。您的意思是在 VarScope 中设置 reuse=True 或 reuse=tf.AUTO_REUSE 吗?

标签 python python-3.x machine-learning tensorflow neural-network

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

有什么想法吗?

最佳答案

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

如果没有,您需要清除计算图。您可以通过将此行放在脚本的开头来做到这一点。

tf.reset_default_graph()

关于python - ValueError : Variable rnn/basic_rnn_cell/kernel already exists, 不允许。您的意思是在 VarScope 中设置 reuse=True 或 reuse=tf.AUTO_REUSE 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47296969/

相关文章:

python - 使用 Python 从批处理文件中实时输出

machine-learning - 比较 MSE 损失和交叉熵损失的收敛性

pandas - 如何重命名pandas中的一批列?

machine-learning - 如何为神经网络训练(keras)准备不同输入大小的输入?

python - 为什么我的 if 语句会产生关键错误?

python - 在 Python 中编辑多行字符串

python - 将随机图像从目录发布到推特

python - Django:按计算字段过滤

python - Jira POST 和 PUT Rest 调用从 Python 返回错误 400

python - Python Fabric 任务可以调用其他任务并尊重它们的主机列表吗?