I am trying to train a simple LSTM based RNN model in Keras using return_sequences. As I want all the timestep output. Here is the code I am using:
model = Sequential()
model.add(LSTM(10, return_sequences = True, input_shape = (8, 8)))
model.add(Activation('softmax'))
model.compile(loss = 'categorical_crossentropy', optimizer = adam, metrics = ['accuracy'])
model.fit(X_train, y_train, batch_size = 1, epochs = 1000, verbose = 1)
But I get the following error:
model.fit(X_train, y_train, batch_size = 1, epochs = 1000, verbose = 1)
File "C:\Program Files\Anaconda3\lib\site-packages\keras\models.py", line 1002, in fit
validation_steps=validation_steps)
File "C:\Program Files\Anaconda3\lib\site-packages\keras\engine\training.py", line 1630, in fit
batch_size=batch_size)
File "C:\Program Files\Anaconda3\lib\site-packages\keras\engine\training.py", line 1480, in _standardize_user_data
exception_prefix='target')
File "C:\Program Files\Anaconda3\lib\site-packages\keras\engine\training.py", line 113, in _standardize_input_data
'with shape ' + str(data_shape))
ValueError: Error when checking target: expected activation_1 to have 3 dimensions, but got array with shape (1437, 10)
But the same code works fine when I change the line from:
model.add(LSTM(10, return_sequences = True, input_shape = (8, 8)))
to:
model.add(LSTM(10, return_sequences = False, input_shape = (8, 8)))
I am assuming I will have to change the Activation('softmax') layer definition, but not sure how. Can someone help me in resolving this?
TIA
X_trainandy_train? - todayy_trainis (1437, 10) and the output of theActivationlayer is (None, 8, 10) when return_sequences=True. So, I understand it's the shape mismatch of Activation output shape and the y_train shape. I want return_sequences only after LSTM layer and not after activation layer. - Rachit Agrawalreturn_sequences=True? If you insist on doing it, you can first flatten the output of LSTM layer and then have a Dense layer with 10 units as the last layer which its activation function is softmax. - today