当我传入的是一个形状ValueError数组时,我为什么要为我的神经网络得到一个形状(8,1),但是我得到的错误是,神经网络正在抱怨得到一个(1,)。
神经网络:
>>> observation_dimension
(8,)
>>> q_network = Sequential([
Dense(40, input_dim=observation_dimension, activation='relu'),
Dense(40, activation='relu'),
Dense(number_of_actions, activation='linear')
])
>>> obs
array([-0.00371828, 0.93953934, -0.37663383, -0.07161933, 0.00431531,
0.08531308, 0. , 0. ])
>>> obs.shape
(8,)错误:
>>> q_network.predict(obs)
Traceback (most recent call last):
...
...
ValueError: Error when checking input: expected dense_27_input to have shape (8,) but got array with shape (1,)发布于 2018-06-28 09:18:28
model.predict接受一批样本,如果你给它一个形状错误的样本,它会将第一个维度解释为批处理。
一个简单的解决方案是添加一个值为1的维度:
q_network.predict(obs.reshape(1, 8))发布于 2018-06-28 09:00:00
predict方法需要一个2d数组,所以只需重塑您的obs
obs = np.reshape(obs,(-1,len(obs)))https://stackoverflow.com/questions/51078007
复制相似问题