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

조회 수: 63 (최근 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