虽然我正在尝试 Openai 的 keras 和 Gym,但我不断收到此错误
ValueError: Error when checking input: expected reshape_1_input to have shape (None, 979, 1) but got array with shape (979, 1, 1)
我收集我的数据如下:
def getData():
rewardc = 0
rewardo = 0
labels = np.array([])
data = np.array([])
for i in range(11):
print("run",i)
for _ in range (10000):
print("---------------------------------------------------------------------------")
print("action", _)
#env.render()
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
if done:
env.reset()
break
rewardc = rewardo - reward
rewardo = reward
observationo = observation
rewardco = rewardc
ohobservation = np.array(observationo)
ohobservation = np.append(ohobservation, rewardo)
ohobservation = np.append(ohobservation, rewardco)
#print ("whole observation",ohobservation)
#print("data", data)
labelsb = np.array([action])
if labels.size == 0:
labels = labelsb
else:
labels = np.vstack((labels,action))
if data.size == 0:
data = ohobservation
else:
data = np.vstack((data, ohobservation))
return labels, data
我的 x 数组将如下所示:
[ [2] [0] [2] [3] [0] [0] .. [2] [3]]
我的 Y:
Y [[ 1.15792274e-02 9.40991027e-01 5.85608387e-01 ..., 0.00000000e+00
-5.27112172e-01 5.27112172e-01]
[ 1.74466133e-02 9.40591342e-01 5.95346880e-01 ..., 0.00000000e+00
-1.88372436e+00 1.35661219e+00]
[ 2.32508659e-02 9.39789397e-01 5.87415648e-01 ..., 0.00000000e+00
-4.41631844e-02 -1.83956118e+00]
网络代码:
model = Sequential()
model.add(Dense(units= 64, input_dim= 100))
model.add(Activation('relu'))
model.add(Dense(units=10))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='sgd',
metrics=['accuracy'])
model.fit(X,Y, epochs=5)
但是我无论如何都不能在 Keras 中喂它。如果有人可以帮助我解决它,那就太好了,谢谢!