Error in deep learning classification code
이전 댓글 표시
Hi. I am writing a deep learning classification code below.
The values in YTrain1 are numbers, and numClass is 5. The error code is as follows:
Error using validateTrueValues (line 45)
Number of channels in predictions (5) must match the number of channels in the targets (1).
Thank you.
clc; clear;
load("paddedData_Train.mat","-mat")
XTrain = paddedData_Train(:,3);
YTrain1 = cell2mat(paddedData_Train(:,1));
dsXTrain = arrayDatastore(XTrain, 'OutputType', 'same');
dsYTrain1 = arrayDatastore(YTrain1);
dsTrainA = combine(dsXTrain, dsYTrain1);
numClass = numel(unique(YTrain1));
net = dlnetwork;
tempNet = [
sequenceInputLayer([440 5 1],"Name","sequenceinput")
convolution2dLayer([3 3],16,"Name","conv_A1")
batchNormalizationLayer("Name","batchnorm_A1")
reluLayer("Name","relu_A1")
convolution2dLayer([3 3],16,"Name","conv_2")
batchNormalizationLayer("Name","batchnorm_2")
reluLayer("Name","relu_2")
flattenLayer("Name","flatten")
lstmLayer(200,"Name","lstm","OutputMode","last")
fullyConnectedLayer(numClass,"Name","fc_1")
softmaxLayer];
net = addLayers(net,tempNet);
plot (net)
options = trainingOptions('sgdm', ...
'MaxEpochs', 10000, ...
'MiniBatchSize', 50, ...
'Shuffle', 'every-epoch', ...
'Plots', 'training-progress');
lossFcnA = @(Y1,dsYTrain1) crossentropy(Y1,dsYTrain1);
net = trainnet(dsTrainA, net, lossFcnA, options);
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!