Why number of class shows 1 ?

2 次查看(过去 30 天)
Ceren Cirit
Ceren Cirit 2021-1-11
I write this code with using HAM 10000 dataset. But I have one problem. Accuracy always show %100. Also I realized when i write :
CLASS = categories(img.Labels);
CLASS gives value of 1 but normally i have 7 class. Can you help why it can be?
img = imageDatastore('HAM10000_images_part_1',...
'IncludeSubfolders',true,...
'LabelSource','foldernames');
figure
Images = length(img.Files);
perm = randperm(Images,40);
for i = 1:40
subplot(8,5,i);
imshow(img.Files{perm(i)});
end
imageSize = [64 64 3];
[imdsTrain,imdsTest] = splitEachLabel(img,0.7,'randomize');
datastore = augmentedImageDatastore(imageSize,imdsTrain);
layers = [
imageInputLayer(imageSize,'Name','input')
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,64,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
fullyConnectedLayer(7)
softmaxLayer
classificationLayer ];
options = trainingOptions('adam', ...
'MaxEpochs',3,...
'InitialLearnRate',0.01, ...
'Verbose',true, ...
'Plots','training-progress');
net = trainNetwork(datastore,layers,options);
YPred = classify(net,imdsTest);
YValidation = imdsTest.Labels;
accuracy = sum(YPred == YValidation)/numel(YValidation);

回答(1 个)

Gaurav Garg
Gaurav Garg 2021-1-25
Hi Ceren,
The given code and the model seem to work fine for me for a DigitDataset, with an accuracy of 99.4%.
Where you might be confused is with the output of the classification layer. A classification layer infers the number of classes from the output size of the previous layer. Hence, you are expected to get a single value as output and which you are getting as well. FOr more information on classification layer, you can refer here.

类别

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