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

65 vues (au cours des 30 derniers jours)
% 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);

Réponses (1)

Athul Prakash
Athul Prakash le 20 Oct 2020
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!

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by