How do I create and plot a confusion matrix for my trained convolutional neural network?
조회 수: 20 (최근 30일)
이전 댓글 표시
I can't seem to create a confusion matrix for my validation accuracy outcome of my trained convolutional neural network. Below is the code I am using, and thanks in advance for any help!
-----------------------------------------------------------------------------------
clear
rng('shuffle')
outputFolder = fullfile('D:\Large_grains\Training_set');
trainDigitData = imageDatastore(outputFolder,'IncludeSubfolders',true,'LabelSource','foldernames');
outputFolder = fullfile('D:\Large_grains\Validation_set');
testDigitData = imageDatastore(outputFolder,'IncludeSubfolders',true,'LabelSource','foldernames');
inputSize = [224 224 3];
augimdsTrain = augmentedImageDatastore(inputSize,trainDigitData,'ColorPreprocessing','gray2rgb');
augimdsValidation = augmentedImageDatastore(inputSize,testDigitData,'ColorPreprocessing','gray2rgb');
numClasses = 9;
problem2; % load ResNet-18
miniBatchSize = 32;
validationFrequency = floor(numel(trainDigitData.Labels)/miniBatchSize);
options = trainingOptions('sgdm',...
'LearnRateSchedule','piecewise',...
'LearnRateDropFactor',0.1,...
'LearnRateDropPeriod',2,...
'MaxEpochs',10,...
'InitialLearnRate',0.001,...
'MiniBatchSize',miniBatchSize,...
'ValidationData',augimdsValidation, ...
'ValidationFrequency',validationFrequency);
convnet = trainNetwork(augimdsTrain,lgraph,options);
[YPred] = classify(convnet,augimdsValidation);
plotconfusion(augimdsValidation.Labels,YPred)
댓글 수: 2
Shivam Singh
2021년 11월 29일
Hello Steven,
Can you share what is error which you are facing with code? Also, can you share more information about the model ("lgraph") and the dataset used?
답변 (1개)
yanqi liu
2021년 12월 2일
yes,sir,if want get the data information,may be use
[c,cm,ind,per] = confusion(augimdsValidation.Labels,YPred)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Recognition, Object Detection, and Semantic Segmentation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!