필터 지우기
필터 지우기

CNN-LSTM in MATLAB

조회 수: 29 (최근 30일)
nazanin behfar
nazanin behfar 2022년 8월 27일
답변: H W 2022년 11월 3일
I'm trying to implement a CNN + LSTM, but I have an error:
Invalid training data. If the network outputs sequences, then regression responses must be a cell array
of numeric sequences, or a single numeric sequence.
or
Invalid training data. Responses must be a matrix of numeric responses, or a N-by-1 cell array of
sequences, where N is the number of sequences. The feature dimension of all sequences must be the same.
or
Invalid training data. X and Y must have the same number of observations.
what is my mistake?
my code is:
inputSize = [20 25 3];
filterSize = 5;
numFilters = 20;
numHiddenUnits = 5;
numResponses = 1;
layers = [ ...
sequenceInputLayer(inputSize,'Name','input')
sequenceFoldingLayer('Name','fold')
convolution2dLayer(filterSize,numFilters,'Padding','same','Name','conv')
batchNormalizationLayer('Name','bn')
reluLayer('Name','relu')
sequenceUnfoldingLayer('Name','unfold')
flattenLayer('Name','flatten')
lstmLayer(numHiddenUnits,'OutputMode','sequence','Name','lstm')
fullyConnectedLayer(1, 'Name','fc')
regressionLayer('Name','regression')];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');
options = trainingOptions('adam', ...
'MaxEpochs',100, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(input_train,target_train,lgraph,options);
My input_train is a 4-D double that its size is (20,25,3,58) in other words I have 3 sets of images that each set containes 58 set of images with size of 20x25
and when I set target_train a matrix of (58,500) or a 4-D double that its size is (1,500,1,58) or a 4-D double that its size is (1,20,25,58) and
fully connected layer to fullyConnectedLayer(500, 'Name','fc') or fullyConnectedLayer(1, 'Name','fc') or fullyConnectedLayer([20 25], 'Name','fc') the error is:
in all cases the error is:
"Invalid training data. Sequence responses must have the same sequence length as the corresponding
predictors."
  댓글 수: 2
HONGYI LI
HONGYI LI 2022년 9월 27일
I have the same issue, do you have solved? thanks
nazanin behfar
nazanin behfar 2022년 9월 29일
Unfortunately no.

댓글을 달려면 로그인하십시오.

답변 (1개)

H W
H W 2022년 11월 3일
添加层分支
将网络分支添加到层次图中。每个分支均为一个线性层组。
tempLayers = [
sequenceInputLayer([20 25 3],"Name","sequence")
sequenceFoldingLayer("Name","seqfold")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
convolution2dLayer([5 5],32,"Name","conv","Padding","same")
batchNormalizationLayer("Name","batchnorm")
reluLayer("Name","relu")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
sequenceUnfoldingLayer("Name","sequnfold")
flattenLayer("Name","flatten")
lstmLayer(5,"Name","lstm")
fullyConnectedLayer(1,"Name","fc")
regressionLayer("Name","regressionoutput")];
lgraph = addLayers(lgraph,tempLayers);
% 清理辅助变量
clear tempLayers;
连接层分支
连接网络的所有分支以创建网络图。
lgraph = connectLayers(lgraph,"seqfold/out","conv");
lgraph = connectLayers(lgraph,"seqfold/miniBatchSize","sequnfold/miniBatchSize");
lgraph = connectLayers(lgraph,"relu","sequnfold/in");

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by