Error with CNN and LSTM network
4 views (last 30 days)
Show older comments
Good day,
I am attempting to do a combined cnn and lstm network with the following layers:
tempLayers = [
sequenceInputLayer(InputSize,"Name","sequence")
sequenceFoldingLayer("Name","seqfold")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
% Layer 1: 3 filters, stride of 1, length of filter is 102, no padding.
convolution2dLayer([40 1],32,'Stride',1,"Name","conv_1")
batchNormalizationLayer("Name","batchnorm_1")
leakyReluLayer("Name","relu_1")
maxPooling2dLayer([4 1],'Padding',"same","Name","maxpool_1")
dropoutLayer(0.1,"Name","dropout_1")
convolution2dLayer([40 1],32,'Stride',1,"Name","conv_2")
batchNormalizationLayer("Name","batchnorm_2")
leakyReluLayer("Name","relu_2")
maxPooling2dLayer([4 1],'Padding',"same","Name","maxpool_2")
dropoutLayer(0.1,"Name","dropout_2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
sequenceUnfoldingLayer("Name","sequnfold")
flattenLayer("Name","flatten")
lstmLayer(128,"Name","lstm_1","OutputMode","last")
lstmLayer(128,"Name","lstm_2","OutputMode","last")
fullyConnectedLayer(1,"Name","fc")
%softmaxLayer("Name","softmaxlayer")
%classificationLayer("Name","classificationoutput")
regressionLayer("Name","regressionoutput")
];
lgraph = addLayers(lgraph,tempLayers);
%% Connect Layer Branches
clear tempLayers;
lgraph = connectLayers(lgraph,"seqfold/out","conv_1");
lgraph = connectLayers(lgraph,"seqfold/miniBatchSize","sequnfold/miniBatchSize");
lgraph = connectLayers(lgraph,"dropout_2","sequnfold/in");
However when i try to train the network using a train input that is a 4d double and output that is a 200 column vector with hr data i receive the following error:
"Error using trainNetwork (line 183)
Invalid training data. For a recurrent layer with output mode 'last', inputs must be cell arrays.
Error in ecng_6700_cw1_hw4_test_codem (line 235)
net = trainNetwork(train_input,estimator_train_output,lgraph,opts);"
I am unsure what the issue is with my data in trying to train it.
1 Comment
James Lu
on 4 Feb 2022
have you tried changing the first LSTM layer to
lstmLayer(128,"Name","lstm_1","OutputMode","sequence")
Answers (1)
yanqi liu
on 8 Feb 2022
yes,sir,as James Lu idea,may be use
tempLayers = [
sequenceUnfoldingLayer("Name","sequnfold")
flattenLayer("Name","flatten")
lstmLayer(128,"Name","lstm_1","OutputMode","sequence")
lstmLayer(128,"Name","lstm_2","OutputMode","sequence")
fullyConnectedLayer(1,"Name","fc")
%softmaxLayer("Name","softmaxlayer")
%classificationLayer("Name","classificationoutput")
regressionLayer("Name","regressionoutput")
];
or make data to cells,such as
[XTrain,YTrain] = japaneseVowelsTrainData;
XTrain
now we can see the cell data,then you can use origin net layers to try
0 Comments
See Also
Categories
Find more on Deep Learning with Time Series and Sequence Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!