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일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2022년 5월 11일

답변:

2025년 1월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by