Это моя первая попытка использовать слой LSTM, и я не могу выполнить эту работу. Я проверил трекер ошибок github и темы SO, но ни одно из доступных решений не решило мою проблему.
Всякий раз, когда я меняю размер плотного слоя или форму данных, я получаю аналогичную ошибку.
Traceback (most recent call last):
File "F:/Programowanie/GitHub Repositories/MYOPM/ui_main.py", line 640, in train_ml_algorithm
self.ml.keras_LSTM_train()
File "F:\Programowanie\GitHub Repositories\MYOPM\machine_learning.py", line 648, in keras_LSTM_train
verbose=2)
File "F:\Programowanie\GitHub Repositories\MYOPM\venv\lib\site-packages\keras\engine\training.py", line 1154, in fit
batch_size=batch_size)
File "F:\Programowanie\GitHub Repositories\MYOPM\venv\lib\site-packages\keras\engine\training.py", line 621, in _standardize_user_data
exception_prefix='target')
File "F:\Programowanie\GitHub Repositories\MYOPM\venv\lib\site-packages\keras\engine\training_utils.py", line 135, in standardize_input_data
'with shape ' + str(data_shape))
ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (20, 84, 1)
Я получил 3D-массивы, содержащие только двоичные данные:
поезд - shape (20, 84, 147)
[[[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
...
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]]
...
[[1 0 0 ... 0 0 0]
[1 0 0 ... 0 0 0]
[1 0 0 ... 0 0 0]
...
[0 0 0 ... 1 0 0]
[0 0 0 ... 1 0 0]
[0 0 0 ... 1 0 0]]
label - shape ( 20, 84, 1)
[[[0]
[0]
[0]
...
[1]
[1]
[1]]
...
[[1]
[1]
[1]
...
[1]
[1]
[1]]
Код:
from keras.models import Sequential
from keras.layers import LSTM
from keras.layers.core import Dense, Dropout, Activation
model = Sequential()
model.add(LSTM(32, input_shape=(84, 147), return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(32, return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(1))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(train,
label,
epochs=100,
batch_size=64,
verbose=2)
