Perform sensitivity, specificity, precision, recall, f_measure in CNN

29 ビュー (過去 30 日間)
HK
HK 2021 年 11 月 30 日
コメント済み: Arya Faturrahman 2022 年 10 月 11 日
Hello experts,
I want to perform [sensitivity, specificity, precision, recall, f_measure] in the following script, but I dont' know how.
Please help me how to write code to evaluate them!
outputFolder = fullfile('Caltech')
rootFolder = fullfile(outputFolder, '101_ObjectCategories')
categories = {'data1', 'data2'}
imds = imageDatastore(fullfile(rootFolder,categories), 'LabelSource','foldernames')
tbl = countEachLabel(imds)
minSetCount = min(tbl{:,2})
imds = splitEachLabel(imds, minSetCount, 'randomize')
countEachLabel(imds)
net = resnet50();
lgraph = layerGraph(net);
clear net;
numClasses = 2;
%numel(lgraph.Layers(end).ClassNames);
[trainingSet, testSet] = splitEachLabel(imds, 0.7, 'randomize');
imageSize = [224 224 3];
augmentedTrainingSet = augmentedImageDatastore(imageSize,...
trainingSet, 'ColorPreprocessing', 'gray2rgb');
augmentedTestSet = augmentedImageDatastore(imageSize,...
testSet, 'ColorPreprocessing', 'gray2rgb');
% New Learnable Layer
newLearnableLayer = fullyConnectedLayer(numClasses, ...
'Name','new_fc', ...
'WeightLearnRateFactor',10,...
'BiasLearnRateFactor',10);
% Replacing the last layers with new layers
lgraph = replaceLayer(lgraph,'fc1000',newLearnableLayer);
newsoftmaxLayer = softmaxLayer('Name','new_softmax');
lgraph = replaceLayer(lgraph,'fc1000_softmax',newsoftmaxLayer);
newClassLayer = classificationLayer('Name','new_classoutput');
lgraph = replaceLayer(lgraph,'ClassificationLayer_fc1000',newClassLayer);
options = trainingOptions('adam',...
'MaxEpochs',6,'MiniBatchSize',8,...
'Shuffle','every-epoch', ...
'ValidationData', augmentedTestSet, ...
'ValidationFrequency', 30, ...
'InitialLearnRate',1e-4, ...
'Verbose',false, ...
'Plots','training-progress');
netTransfer = trainNetwork(augmentedTrainingSet,lgraph,options);

採用された回答

Pratyush Roy
Pratyush Roy 2021 年 12 月 3 日
Hi,
The predict function might be helpful to predict the labels for the test images using the following command:
YPred = predict(netransfer, imds_test) %imds_test is the image dastore containing the test images.
After obtaining the predicted labels "YPred" the function perfcurve can be used the get the precision and recall values using the following command:
[Xpr,Ypr,Tpr,AUCpr] =perfcurve(targets, scores, 1, 'xCrit', 'reca', 'yCrit', 'prec');
Here Xpr and YPr represents recall and pres=cision respectively.
You can also use the confusion function to obtain the "Matrix of percentages" using the following command:
[c,cm,ind,per] = confusion(targets,outputs) %per represents the Matrix of percentages. Please refer to the doc for more details.
Hope this helps!
  1 件のコメント
Arya Faturrahman
Arya Faturrahman 2022 年 10 月 11 日
I Get Error code
Error in DAGNetwork/predict (line 118)
Y = predictBatch( ...
Error in test_resnet (line 1)
YPred = predict(netTransfer, testSet.Labels);
%imds_test is the image dastore containing the
test images.
How to fix and run program i need example for this code. Can you give me example to run testing code about this because i very need this outputs.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by