CNN-LSTM regerssion

4 vues (au cours des 30 derniers jours)
hu ying
hu ying le 11 Mai 2022
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

Réponses (1)

Himanshu
Himanshu le 17 Jan 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.

Catégories

En savoir plus sur Timing and presenting 2D and 3D stimuli dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by