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就可以正常运行

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容