Я пытаюсь сделать прогноз с моей моделью, shape
массива, который я передаю, отображается как (24,)
при печати.При попытке передать массив в метод predict
, он генерирует эту ошибку: ValueError: Error when checking input: expected dense_1_input to have shape (24,) but got array with shape (1,)
, однако я знаю, что форма моего массива (24,)
.Почему он по-прежнему выдает ошибку?
для справки, вот моя модель:
model = MySequential()
model.add(Dense(units=128, activation='relu', input_shape=(24,)))
model.add(Dense(128, activation='relu'))
model.add(Dense(action_size, activation='softmax'))
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
и этот класс MySequential
здесь, это подкласс keras.models.Sequential
:
class MySequential(Sequential):
score = 0
def set_score(self, score):
self.score = score
def get_score(self):
return self.score
цикл, в котором я его запускаю:
for i in range(100):
new_model = create_model(action_size)
new_model.__class__ = Sequential
reward = 0
state = env.reset()
while True:
env.render()
print(state.shape)
input_arr = state
input_arr = np.reshape(input_arr, (1, 24))
action = new_model.predict(input_arr)
state, reward, done, info = env.step(action)
if done:
break
env.reset()
Вот полный стек ошибок
Traceback (most recent call last):
File "BipedalWalker.py", line 79, in <module>
state, reward, done, info = env.step(action)
File "/Users/arjunbemarkar/Python/MachineLearning/gym/gym/wrappers/time_limit.py", line 31, in step
observation, reward, done, info = self.env.step(action)
File "/Users/arjunbemarkar/Python/MachineLearning/gym/gym/envs/box2d/bipedal_walker.py", line 385, in step
self.joints[0].motorSpeed = float(SPEED_HIP * np.sign(action[0]))
TypeError: only size-1 arrays can be converted to Python scalars