Error when using lstm with cnn
XTrain = single(DL_input_reshaped(:,1,1,Training_Ind));
YTrain = single(DL_output_reshaped(1,1,:,Training_Ind)); XValidation = single(DL_input_reshaped(:,1,1,Validation_Ind));
YValidation = single(DL_output_reshaped(1,1,:,Validation_Ind));
YValidation_un = single(DL_output_reshaped_un);
%% DL Model definition with adjusted pooling and convolution layers layers = [ imageInputLayer([size(XTrain,1), 1, 1],’Name’,’input’,’Normalization’,’none’)
convolution2dLayer(3, 64, ‘Padding’, ‘same’, ‘Name’, ‘conv1’)
batchNormalizationLayer(‘Name’, ‘bn1’)
reluLayer(‘Name’, ‘relu1’)
maxPooling2dLayer([3,1], ‘Stride’, [3,1], ‘Name’, ‘maxpool1’)
convolution2dLayer(3, 128, ‘Padding’, ‘same’, ‘Name’, ‘conv2’)
batchNormalizationLayer(‘Name’, ‘bn2’)
reluLayer(‘Name’, ‘relu2’)
maxPooling2dLayer([3,1], ‘Stride’, [3,1], ‘Name’, ‘maxpool2’)
convolution2dLayer(3, 256, ‘Padding’, ‘same’, ‘Name’, ‘conv3’)
batchNormalizationLayer(‘Name’, ‘bn3’)
reluLayer(‘Name’, ‘relu3’)
maxPooling2dLayer([3,1], ‘Stride’, [3,1], ‘Name’, ‘maxpool3’)
flattenLayer(‘Name’, ‘flatten’) % Flatten to 1D per sample
lstmLayer(200, ‘OutputMode’, ‘last’, ‘Name’, ‘lstm1’) % LSTM layer
fullyConnectedLayer(512, ‘Name’, ‘fc1’)
reluLayer(‘Name’, ‘relu4’)
dropoutLayer(0.5, ‘Name’, ‘dropout1’)
fullyConnectedLayer(1024, ‘Name’, ‘fc2’)
reluLayer(‘Name’, ‘relu5’)
dropoutLayer(0.5, ‘Name’, ‘dropout2’)
fullyConnectedLayer(2048, ‘Name’, ‘fc3’)
reluLayer(‘Name’, ‘relu6’)
dropoutLayer(0.5, ‘Name’, ‘dropout3’)
fullyConnectedLayer(size(YTrain,3), ‘Name’, ‘fc4’)
regressionLayer(‘Name’, ‘output’) ];
options = trainingOptions(‘rmsprop’, …
.
.
.
so this error is appear to me
((error useing trainNetwork Invalid training data.
The output size (1024) of the last layer does not match the response size (1).))
so the size or XTrain and YTrain is (features x 1 x 1 x minbatchsize)XTrain = single(DL_input_reshaped(:,1,1,Training_Ind));
YTrain = single(DL_output_reshaped(1,1,:,Training_Ind)); XValidation = single(DL_input_reshaped(:,1,1,Validation_Ind));
YValidation = single(DL_output_reshaped(1,1,:,Validation_Ind));
YValidation_un = single(DL_output_reshaped_un);
%% DL Model definition with adjusted pooling and convolution layers layers = [ imageInputLayer([size(XTrain,1), 1, 1],’Name’,’input’,’Normalization’,’none’)
convolution2dLayer(3, 64, ‘Padding’, ‘same’, ‘Name’, ‘conv1’)
batchNormalizationLayer(‘Name’, ‘bn1’)
reluLayer(‘Name’, ‘relu1’)
maxPooling2dLayer([3,1], ‘Stride’, [3,1], ‘Name’, ‘maxpool1’)
convolution2dLayer(3, 128, ‘Padding’, ‘same’, ‘Name’, ‘conv2’)
batchNormalizationLayer(‘Name’, ‘bn2’)
reluLayer(‘Name’, ‘relu2’)
maxPooling2dLayer([3,1], ‘Stride’, [3,1], ‘Name’, ‘maxpool2’)
convolution2dLayer(3, 256, ‘Padding’, ‘same’, ‘Name’, ‘conv3’)
batchNormalizationLayer(‘Name’, ‘bn3’)
reluLayer(‘Name’, ‘relu3’)
maxPooling2dLayer([3,1], ‘Stride’, [3,1], ‘Name’, ‘maxpool3’)
flattenLayer(‘Name’, ‘flatten’) % Flatten to 1D per sample
lstmLayer(200, ‘OutputMode’, ‘last’, ‘Name’, ‘lstm1’) % LSTM layer
fullyConnectedLayer(512, ‘Name’, ‘fc1’)
reluLayer(‘Name’, ‘relu4’)
dropoutLayer(0.5, ‘Name’, ‘dropout1’)
fullyConnectedLayer(1024, ‘Name’, ‘fc2’)
reluLayer(‘Name’, ‘relu5’)
dropoutLayer(0.5, ‘Name’, ‘dropout2’)
fullyConnectedLayer(2048, ‘Name’, ‘fc3’)
reluLayer(‘Name’, ‘relu6’)
dropoutLayer(0.5, ‘Name’, ‘dropout3’)
fullyConnectedLayer(size(YTrain,3), ‘Name’, ‘fc4’)
regressionLayer(‘Name’, ‘output’) ];
options = trainingOptions(‘rmsprop’, …
.
.
.
so this error is appear to me
((error useing trainNetwork Invalid training data.
The output size (1024) of the last layer does not match the response size (1).))
so the size or XTrain and YTrain is (features x 1 x 1 x minbatchsize) XTrain = single(DL_input_reshaped(:,1,1,Training_Ind));
YTrain = single(DL_output_reshaped(1,1,:,Training_Ind)); XValidation = single(DL_input_reshaped(:,1,1,Validation_Ind));
YValidation = single(DL_output_reshaped(1,1,:,Validation_Ind));
YValidation_un = single(DL_output_reshaped_un);
%% DL Model definition with adjusted pooling and convolution layers layers = [ imageInputLayer([size(XTrain,1), 1, 1],’Name’,’input’,’Normalization’,’none’)
convolution2dLayer(3, 64, ‘Padding’, ‘same’, ‘Name’, ‘conv1’)
batchNormalizationLayer(‘Name’, ‘bn1’)
reluLayer(‘Name’, ‘relu1’)
maxPooling2dLayer([3,1], ‘Stride’, [3,1], ‘Name’, ‘maxpool1’)
convolution2dLayer(3, 128, ‘Padding’, ‘same’, ‘Name’, ‘conv2’)
batchNormalizationLayer(‘Name’, ‘bn2’)
reluLayer(‘Name’, ‘relu2’)
maxPooling2dLayer([3,1], ‘Stride’, [3,1], ‘Name’, ‘maxpool2’)
convolution2dLayer(3, 256, ‘Padding’, ‘same’, ‘Name’, ‘conv3’)
batchNormalizationLayer(‘Name’, ‘bn3’)
reluLayer(‘Name’, ‘relu3’)
maxPooling2dLayer([3,1], ‘Stride’, [3,1], ‘Name’, ‘maxpool3’)
flattenLayer(‘Name’, ‘flatten’) % Flatten to 1D per sample
lstmLayer(200, ‘OutputMode’, ‘last’, ‘Name’, ‘lstm1’) % LSTM layer
fullyConnectedLayer(512, ‘Name’, ‘fc1’)
reluLayer(‘Name’, ‘relu4’)
dropoutLayer(0.5, ‘Name’, ‘dropout1’)
fullyConnectedLayer(1024, ‘Name’, ‘fc2’)
reluLayer(‘Name’, ‘relu5’)
dropoutLayer(0.5, ‘Name’, ‘dropout2’)
fullyConnectedLayer(2048, ‘Name’, ‘fc3’)
reluLayer(‘Name’, ‘relu6’)
dropoutLayer(0.5, ‘Name’, ‘dropout3’)
fullyConnectedLayer(size(YTrain,3), ‘Name’, ‘fc4’)
regressionLayer(‘Name’, ‘output’) ];
options = trainingOptions(‘rmsprop’, …
.
.
.
so this error is appear to me
((error useing trainNetwork Invalid training data.
The output size (1024) of the last layer does not match the response size (1).))
so the size or XTrain and YTrain is (features x 1 x 1 x minbatchsize) cnn, lstm, deep learning MATLAB Answers — New Questions