CNN-LSTM regerssion

2 visualizzazioni (ultimi 30 giorni)
hu ying
hu ying il 11 Mag 2022
Risposto: Himanshu il 17 Gen 2025
Incorrect use of trainNetwork (line 184)
Invalid training data. Sequence responses must have the same sequence length as the corresponding predictors.
numFeatures = 6;
numResponses = 1;
numHiddenUnits = 200;
filterSize = 3;
numFilters = 8;
miniBatchSize = 8;
layers = [ ...
sequenceInputLayer([numFeatures 1 1],'Name','input')
sequenceFoldingLayer('Name','fold')
convolution2dLayer([filterSize 1],numFilters,'Padding','same','Name','conv')
batchNormalizationLayer('Name','bn')
reluLayer('Name','relu')
sequenceUnfoldingLayer('Name','unfold')
flattenLayer('Name','flatten')
lstmLayer(numHiddenUnits,'OutputMode','sequence','Name','lstm')
dropoutLayer(0.1,'Name','drop')
fullyConnectedLayer(numResponses, 'Name','fc')
regressionLayer('Name','regression')];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');
options = trainingOptions('adam', ...
'MaxEpochs',250, ...
'MiniBatchSize',miniBatchSize, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
'Plots','training-progress');
net = trainNetwork(trainD,targetD,lgraph,options);
trainD is 6x1x1x100 matrix,targetD is 100x1 matrix

Risposte (1)

Himanshu
Himanshu il 17 Gen 2025
Hello,
I see that you are facing an error related to mismatched sequence lengths in your training data for a CNN-LSTM regression network.
The following pointers can resolve the issue you are facing:
  1. Ensure that the sequence lengths of "trainD" and "targetD" match. "trainD" should have a size of 6x1x1x100, while "targetD" should be 1x100.
  2. Reshape "targetD" to have the same sequence length as "trainD". Adjust "targetD" to have dimensions 1x1x1x100.
  3. Confirm that "trainD" and "targetD" are correctly formatted as cell arrays if required by "trainNetwork".
  4. Check that "trainD" and "targetD" are appropriately preprocessed to ensure compatibility with the network architecture.
I hope this helps.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by