MATLAB: Is it possible to implement a LSTM layer after a CNN layer

cnnconvolutional neural networksdeep learningDeep Learning Toolboxlstm

I'm trying to implement a CNN layer + a LSTM layer, but I have an error: "Network: Incompatible layer types". Is it not possible to implement this combination in MATLAB or am I just writing it not properly?
My code:
layers = [ ...
sequenceInputLayer(inputSize)
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer
];
Error:
Error using trainNetwork (line 154)
Invalid network.
Caused by:
Network: Incompatible layer types. The network contains layer types not supported with recurrent layers.
Detected recurrent layers:
layer 6 (LSTM)
Detected incompatible layers:
layer 2 (Convolution)
layer 3 (Batch Normalization)
layer 5 (Max Pooling)
Layer 2: Input size mismatch. Size of input to this layer is different from the expected input size.
Inputs to this layer:
from layer 1 (output size 500)

Best Answer

As far as I know, no, you can't combine the two. You can train a CNN independently on your training data, then use the learned features as an input to your LSTM. However, learning and updating CNN weights while training an LSTM is unfortunately not possible.