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,)
model.predict
取一批样本,如果你给它一个形状错误的样本,它会将第一个维度解释为批次的。
一个简单的解决方案是添加一个值为 1 的维度:
q_network.predict(obs.reshape(1, 8))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句