当在spyder中运行代码时报错如下:
ValueError: Variable eval_net/l1/w1 already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:
File "D:\Tools software\python\lib\site-packages\tensorflow\python\framework\ops.py", line 1768, in __init__
self._traceback = tf_stack.extract_stack()
File "D:\Tools software\python\lib\site-packages\tensorflow\python\framework\ops.py", line 3272, in create_op
op_def=op_def)
File "D:\Tools software\python\lib\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_func
return func(*args, **kwargs)
在Spyder的Python控制台里跑的原因,Python的控制台会保存上次运行结束的变量。有以下两种解决办法:
方法1:重开加载控制台
方法2:在代码的开头加上 tf.reset_default_graph()