如何解决Tensorflow中的NoneType对象错误?

时间:2019-07-18 20:20:06

标签: python tensorflow reinforcement-learning

我正在RL中的Actor Critic上关注以下github代码:https://github.com/MorvanZhou/Reinforcement-learning-with-tensorflow/blob/master/contents/8_Actor_Critic_Advantage/AC_CartPole.py

使用s = s[np.newaxis, :]行时,Actor的choice_action函数出现错误。我得到以下信息:

Traceback (most recent call last):
  File "main_dac.py", line 142, in <module>
    main();
  File "main_dac.py", line 122, in main
    a.append(actors[i].choose_action(s));
  File "main_dac.py", line 52, in choose_action
    s = s[np.newaxis, :];
TypeError: 'NoneType' object has no attribute '__getitem__'

我正在用以下方式初始化演员:

def __init__(self, sess, n_features, n_actions, lr=0.001):
    self.sess = sess;
    self.s = tf.placeholder(tf.float32, [1,n_features], "state");
    self.a = tf.placeholder(tf.int32, None, "act");
    self.td_error = tf.placeholder(tf.float32, None, "td_error");

我将函数称为:

while True:
    if RENDER: env.render();
    a = [];
    for i in range(0, num_agents):
        a.append(actors[i].choose_action(s));

我是Tensorflow的新手,所以我提前致歉。非常感谢您提供任何帮助,谢谢!

0 个答案:

没有答案