ValueError: Variable rnn/basic_lstm_cell/kernel already exists, disallowed.

用spyder运行mnist_lstm.py

第一次没问题,修改n_hidden_units后运行报错

ValueError: Variable rnn/basic_lstm_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

File "/media/oliver/工具/deep-60/day4/mnist_lstm.py", line 44, in RNN outputs, states = tf.nn.dynamic_rnn(lstm_cell, x_in, initial_state=_init_state, time_major=False)

File "/media/oliver/工具/deep-60/day4/mnist_lstm.py", line 55, in pred = RNN(x, weights, biases)

File "/home/oliver/.conda/envs/tf-gpu/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 101, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

解决方案:

添加函数:tf.reset_default_graph() 

重置graph就可以正常运行

你可能感兴趣的:(ValueError: Variable rnn/basic_lstm_cell/kernel already exists, disallowed.)