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

92 visualizaciones (últimos 30 días)
% 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);

Respuestas (1)

Athul Prakash
Athul Prakash el 20 de Oct. de 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!

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by