Reputation: 61
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?
Upvotes: 0
Views: 76
Reputation: 9274
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
Upvotes: 1