奇怪的Tensorflow尺寸不匹配

时间:2018-06-21 00:41:59

标签: tensorflow machine-learning

我正在运行以下代码:

    obs = observation[0][0].reshape(self.n_features)
    actions_value = self.sess.run(self.q_eval, feed_dict={self.s: obs})

obs的形状为:(272,)

我有错误:

  File "qlearning/tf_dqn.py", line 124, in choose_action
    actions_value = self.sess.run(self.q_eval, feed_dict={self.s: obs})
  File "/Users/anaconda/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 889, in run
    run_metadata_ptr)
  File "/Users/anaconda/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1096, in _run
    % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (272,) for Tensor u's:0', which has shape '(?, 272)'

输入尺寸正是占位符wtf中指定的尺寸?

1 个答案:

答案 0 :(得分:0)

似乎您有一个功能实例。 您需要像这样重新塑形,在您的情况下,batch_size为1我猜

 obs = observation[0][0].reshape(batch_size,self.n_features)

这是不指定obs是列向量还是行向量的问题,在您的情况下,obs是行向量,而在占位符中,您指定了列向量