CNN-LSTM regerssion

2 次查看(过去 30 天)
hu ying
hu ying 2022-5-11
回答: Himanshu 2025-1-17
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

回答(1 个)

Himanshu
Himanshu 2025-1-17
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.

类别

Help CenterFile Exchange 中查找有关 Timing and presenting 2D and 3D stimuli 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by