Why number of class shows 1 ?
2 ビュー (過去 30 日間)
古いコメントを表示
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);
0 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!