Keras LSTM input signal size adjustment

I tried to train the LSTM model with kera, but I think something is wrong with me here.

I got an error

Err value: error while checking input: it is expected that lstm_17_input will have 3 sizes, but received an array with the form (10000, 0, 20)

while my code looks like

model = Sequential()
model.add(LSTM(256, activation="relu", dropout=0.25, recurrent_dropout=0.25, input_shape=(None, 20, 64)))
model.add(Dense(1, activation="sigmoid"))
model.compile(loss='binary_crossentropy',
          optimizer='adam',
          metrics=['accuracy'])
model.fit(X_train, y_train,
      batch_size=batch_size,
      epochs=10)

where it X_trainhas a shape (10000, 20), and the first few data points are similar to

array([[ 0,  0,  0, ..., 40, 40,  9],
   [ 0,  0,  0, ..., 33, 20, 51],
   [ 0,  0,  0, ..., 54, 54, 50],
...

and y_trainhas a form (10000, )that is a binary (0/1) array of labels.

Can someone point out where I'm wrong here?

+5
source share
1 answer

For completeness, this is what happened.

, LSTM, Keras, : input_shape batch_input_shape. , input_shape , batch_input_shape - , .

, input_shape=(None, 20, 64) keras 4- , , . (20,).

. LSTM- , (batch_size, timesteps, input_dim). input_shape=(20, 1) batch_input_shape=(10000, 20, 1). , , , 20 1 .

, :

X_train = np.expand_dims(X_train, 2)  # makes it (10000,20,1)
...
model = Sequential()
model.add(LSTM(..., input_shape=(20, 1)))
+5

Source: https://habr.com/ru/post/1691857/


All Articles