The program always alerts the error of using trainNetwork (line 184) subscript out of range or 184 iThrowCNNException(e). Can anyone help?

조회 수: 3 (최근 30일)
xtrain = mat2cell(data, [3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]);
for i = 1:25
xtrain{i}= xtrain{i}(~isnan(xtrain{i}));
xtrain{i} = reshape(xtrain{i},3,[]);
end
%%
data01 =readcell("数据提取.xlsx",Sheet="label02",NumHeaderLines=1);
data01 = data01';
ytrain =mat2cell(data01 ,[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]);
for i = 1:25
ytrain{i} = string(ytrain{i}) ;
ytrain{i} = rmmissing(ytrain{i});
ytrain{i} = categorical(ytrain{i});
end
%%
numFeatures = 3;
numHiddenUnits = 200;
numClasses = 6;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits,'OutputMode','sequence')
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
%
options = trainingOptions('adam', ...
'MaxEpochs',60, ...
'GradientThreshold',2, ...
'Verbose',0, ...
'Plots','training-progress');
%%
net = trainNetwork(xtrain,ytrain,layers,options);

답변 (1개)

Aneela
Aneela 2024년 10월 8일
Hello @change yang,
The error you are encountering with the “trainNetwork” function is due to the mismatch between the dimensions of “xTrain” and “yTrain”.
Ensure that both “xTrain” and “yTrain” have same number of sequences before and after preprocessing:
disp(length(xTrain));
disp(length(yTrain));
For more information on “trainNetwork”, refer to the following MathWorks documentation: https://www.mathworks.com/help/deeplearning/ref/trainnetwork.html
Also, it is recommended to use “trainnet” instead of “trainNetwork”: https://www.mathworks.com/help/deeplearning/ref/trainnet.html

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by