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!