Invalid training data. The output size (2) of the last layer does not match the number of classes (6).

18 次查看(过去 30 天)
% TRAIN THE IMAGE
layers =[imageInputLayer([90 120 1])
%CONVOLUTION FILTER
convolution2dLayer(5,20)
reluLayer
%GET MAXIMUM VALUE FROM LAYER
maxPooling2dLayer(2,'stride',2)
%CONVOLUTION FILTER
convolution2dLayer(5,20)
reluLayer
%GET MAXIMUM VALUE FROM LAYER
maxPooling2dLayer(2,'stride',2)
fullyConnectedLayer(2)
softmaxLayer
classificationLayer()]
%% CLASSIFICATION
im = imresize(im,[90,120]);
options=trainingOptions('sgdm','MaxEpochs',15,'initialLearnRate',0.0001);
convnet=trainNetwork(Data,layers,options);
output=classify(convnet,im);
tf1=[];
for ii=1:2
st=int2str(ii);
tf=ismember(output,st);
tf1=[tf1 tf];
end
output=find(tf1==1);

回答(1 个)

Athul Prakash
Athul Prakash 2020-10-20
Hi Aswin,
The number of outputs from your network would be determined by the last fullyConnectedLayer you have used. Since it has 2 neurons, the final output from the classificationLayer would also have 2.
If you want to classify into 6 categories, you may use fullyConnectedLayer(6) instead.
Hope it helps!

类别

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