How to find the confusion matrix of a given network?

%%
Folder = 'C:\Users\Vishal\Desktop\Rokesh\NntestCopy\Bacteria';
if ~isdir(Folder)
Message = sprintf('Error: cant find the folder:\n%s', Folder);
uiwait(warndlg(Message));
else Message = sprintf('Folder exists:\n%s', Folder);
uiwait(warndlg(Message));
return;
end
%%
DataPath = fullfile(Folder)
%%
imgdts = imageDatastore(DataPath,'IncludeSubfolders',true,'LabelSource','foldernames')
%%
imgdts.countEachLabel
%%
trainingNumFiles = 46;
rng(1)
[imgdtsTrain,imgdtsValidation] = splitEachLabel(imgdts,...
trainingNumFiles,'randomize')
%%
layers=[...
imageInputLayer([566 804 3])
convolution2dLayer(5,20,'stride',2)
reluLayer
maxPooling2dLayer(5,'stride',1)
convolution2dLayer(5,20,'stride',2)
reluLayer
maxPooling2dLayer(5,'stride',1)
convolution2dLayer(5,20,'stride',2)
reluLayer
maxPooling2dLayer(5,'stride',1)
convolution2dLayer(5,4,'stride',2,'padding',[1 1])
reluLayer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer()]
%analyzeNetwork(layers)
%%
options = trainingOptions('sgdm',...
'MaxEpochs',25,...
'ValidationData',{imgdtsTrain,imgdtsValidation},...
'ValidationFrequency',2,...
'Momentum',0.8,...
'ValidationPatience',1,...
'InitialLearnRate',0.0001,...
'MiniBatchSize',4,...
'Verbose',true,...
'executionenvironment','auto',...
'Shuffle','every-epoch',...
'Plots','training-progress')
%%
microbenet=trainNetwork(imgdts,layers,options)
%%
i=imread('ccb23.jpg');
figure,imshow(i);
%%
output=classify(microbenet,i)
Here, I have 104 images and then labeled them as four species as a,b,c,d. Each label consists of 26 images. I wanted a confusion matrix of this network.

1 Commento

At first, it would be better if you go through, what is confusion matrix?

Risposte (1)

Hi,
The Deep Learning Toolbox in MATLAB has ‘confusion’ and ‘plotconfusion’ functions to extract the confusion matrix. Please go through the following links for more details:
I hope it will help you.

Questa domanda è chiusa.

Chiuso:

il 20 Ago 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by