python中使用tensorflow框架出现“valueError: Variable rnn/basic_rnn_cell/kernel already exists...”的解决办法

在jupyter-notebook中运行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 
    class Command(BaseCommand):

解决办法如下:

当第一次运行模型时(打开一个新的python控制台),是不会报这种错误的。此时需要清除运算图,将以下代码放在脚本的开头来实现:

tf.reset_default_graph()

成功解决。

你可能感兴趣的:(tensorflow学习,python,python,tensorflow,神经网络,机器学习张量)