x_train
и y_train
- это входные и выходные данные моей модели с формами (6508, 500, 5), (6508, 5)
соответственно.
И модель выглядит так:
model = Sequential()
model.add(LSTM(units=96, return_sequences=True, input_shape=x_train.shape[1:]))
model.add(Dropout(0.2))
model.add(LSTM(units=96, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=96))
model.add(Dropout(0.2))
model.add(Dense(units=5))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['mse'])
model.fit(x_train, y_train, epochs=epochs, batch_size=batch_size)
Описание модели:
Model: "sequential_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm_1 (LSTM) (None, 500, 96) 39168
_________________________________________________________________
dropout_1 (Dropout) (None, 500, 96) 0
_________________________________________________________________
lstm_2 (LSTM) (None, 500, 96) 74112
_________________________________________________________________
dropout_2 (Dropout) (None, 500, 96) 0
_________________________________________________________________
lstm_3 (LSTM) (None, 96) 74112
_________________________________________________________________
dropout_3 (Dropout) (None, 96) 0
_________________________________________________________________
dense_1 (Dense) (None, 5) 485
=================================================================
Total params: 187,877
Trainable params: 187,877
Non-trainable params: 0
Проблема в том, что lstm_1
требует input_shape (500, 2), и моя форма данных (500, 5):
ValueError: Error when checking input: expected lstm_1_input to have shape (500, 2) but got array with shape (500, 5)
И я печатаю форму слоев:
for layer in model.layers:
print(layer.input_shape, end='\t')
# (None, 500, 5) (None, 500, 96) (None, 500, 96) (None, 500, 96) (None, 500, 96) (None, 96) (None, 96)
Он печатает (None, 500, 5)
для lstm_1
, поэтому я не могу понять проблему.
Keras==2.3.0
tf==1.14.0
ОБНОВЛЕНИЕ:
Использование keras==2.2.5
или tf.keras
решает проблему.