简体   繁体   中英

dimensionality of LSTM model in keras

Say, This is the training and test data:

X_matrix.shape = (5, 115318, 4) ; Y_matrix.shape = (5, 115318, 51)

and the LSTM model I used is:

model = Sequential()
model.add(LSTM(128, dropout=0.2, recurrent_dropout=0.2))
model.add(Dense(51, activation='softmax'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

however, when I run the model, it turns out that :

Dense layer expected 2 dimensions but gotten 3

As far As I know, I don't have to define the input_shape of the output layer(Dense layer), so why this happens?

The problem is your Y matrix is three dimensional, when it should be two dimensional. Based on the network setup, your Y matrix should be shape (5,52). Although, You could also add return_sequesnce=True to your lstm layer and the network will run as is. Also, as a note if you have 52 possible categories, your loss function should be categorical_crossentropy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM