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 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by