感觉没什么好的学习材料和网站,网上资料本就很少,有代码的更少,而且呢,这些代码还基本上都是TensorFlow1.x版本的,和2.x不兼容,需要修改
我想了想既然我一直在debug,那不如把这一篇文章写成一个debug集锦,也方便以后解决问题
error No1
Using TensorFlow backend.
Traceback (most recent call last):
File "E:/Code/pythoprogram/Reinforcement-learning-with-tensorflow-master/contents/5_Deep_Q_Network/run_this.py", line 2, in <module>
from RL_brain import DeepQNetwork
File "E:\Code\pythoprogram\Reinforcement-learning-with-tensorflow-master\contents\5_Deep_Q_Network\RL_brain.py", line 18, in <module>
tf.set_random_seed(1)
AttributeError: module 'tensorflow' has no attribute 'set_random_seed'
solution No1
tf.random.set_seed(1)
error No2
Using TensorFlow backend.
Traceback (most recent call last):
File "E:/Code/pythoprogram/Reinforcement-learning-with-tensorflow-master/contents/5_Deep_Q_Network/run_this.py", line 47, in <module>
memory_size=2000,
File "E:\Code\pythoprogram\Reinforcement-learning-with-tensorflow-master\contents\5_Deep_Q_Network\RL_brain.py", line 54, in __init__
self._build_net()
File "E:\Code\pythoprogram\Reinforcement-learning-with-tensorflow-master\contents\5_Deep_Q_Network\RL_brain.py", line 71, in _build_net
self.s = tf.placeholder(tf.float32, [None, self.n_features], name='s') # input
AttributeError: module 'tensorflow' has no attribute 'placeholder'
solution No2
self.s = tf.Variable(tf.zeros([None, self.n_features]), dtype=tf.float32, name='s')
error No3
Traceback (most recent call last):
File "E:/Code/pythoprogram/Reinforcement-learning-with-tensorflow-master/contents/5_Deep_Q_Network/run_this.py", line 47, in <module>
memory_size=2000,
File "E:\Code\pythoprogram\Reinforcement-learning-with-tensorflow-master\contents\5_Deep_Q_Network\RL_brain.py", line 54, in __init__
self._build_net()
File "E:\Code\pythoprogram\Reinforcement-learning-with-tensorflow-master\contents\5_Deep_Q_Network\RL_brain.py", line 74, in _build_net
with tf.variable_scope('eval_net'):
AttributeError: module 'tensorflow' has no attribute 'variable_scope'
solution No3
tf.compat.v1.variable_scope
error No4
Traceback (most recent call last):
File "E:/Code/pythoprogram/Reinforcement-learning-with-tensorflow-master/contents/5_Deep_Q_Network/run_this.py", line 47, in <module>
memory_size=2000,
File "E:\Code\pythoprogram\Reinforcement-learning-with-tensorflow-master\contents\5_Deep_Q_Network\RL_brain.py", line 54, in __init__
self._build_net()
File "E:\Code\pythoprogram\Reinforcement-learning-with-tensorflow-master\contents\5_Deep_Q_Network\RL_brain.py", line 77, in _build_net
['eval_net_params', tf.GraphKeys.GLOBAL_VARIABLES], 10, \
AttributeError: module 'tensorflow' has no attribute 'GraphKeys'
solution No4
['eval_net_params', 'variables']
'variables’替换tf.GraphKeys.GLOBAL_VARIABLES
error No5
Traceback (most recent call last):
File "E:/Code/pythoprogram/Reinforcement-learning-with-tensorflow-master/contents/5_Deep_Q_Network/run_this.py", line 47, in <module>
memory_size=2000,
File "E:\Code\pythoprogram\Reinforcement-learning-with-tensorflow-master\contents\5_Deep_Q_Network\RL_brain.py", line 54, in __init__
self._build_net()
File "E:\Code\pythoprogram\Reinforcement-learning-with-tensorflow-master\contents\5_Deep_Q_Network\RL_brain.py", line 82, in _build_net
w1 = tf.get_variable('w1', [self.n_features, n_l1], initializer=w_initializer, collections=c_names)
AttributeError: module 'tensorflow' has no attribute 'get_variable'
solution No5
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
问题成环了,这就是死循环啊
回到了error No1