计算分类准确性训练后一个“pretrained模式”

57视图(30天)
如何calcualte MSE,梅RMSE或任何其他pretrained模型的分类精度?
下一个是我的代码:
imd = imageDatastore ( “C: \ \用户Rayan \桌面\ \ 9 _5_work_on_4_groups \ 9 _1 \ R_9_1_GSM工作” ,
“IncludeSubfolders” ,真的,
“LabelSource” , “foldernames” );
[imdsTrain, imdsValidation] = splitEachLabel (imd, 0.7, “随机” );
numTrainImages =元素个数(imdsTrain.Labels);
idx = randperm (numTrainImages 16);
网= resnet50;
deepNetworkDesigner(净)
analyzeNetwork(净)
inputSize = net.Layers (1) .InputSize;
lgraph = layerGraph(净);
编辑(fullfile (matlabroot, “例子” , “nnet” , “主要” , “findLayersToReplace.m” ))
[learnableLayer, classLayer] = findLayersToReplace (lgraph);
[learnableLayer, classLayer] % #好< NOPTS >
numClasses =元素个数(类别(imdsTrain.Labels));
% numClasses = 3
如果isa (learnableLayer, “nnet.cnn.layer.FullyConnectedLayer” )
newLearnableLayer = fullyConnectedLayer (numClasses,
“名字” , “new_fc” ,
“WeightLearnRateFactor” 10
“BiasLearnRateFactor” 10);
elseif isa (learnableLayer “nnet.cnn.layer.Convolution2DLayer” )
numClasses newLearnableLayer = convolution2dLayer (1,
“名字” , “new_conv” ,
“WeightLearnRateFactor” 10
“BiasLearnRateFactor” 10);
结束
lgraph = replaceLayer (lgraph learnableLayer.Name newLearnableLayer);
newClassLayer = classificationLayer ( “名字” , “new_classoutput” );
lgraph = replaceLayer (lgraph classLayer.Name newClassLayer);
层= lgraph.Layers;
连接= lgraph.Connections;
层(1:20)= freezeWeights(层(1:20));
lgraph = createLgraphUsingConnections(层,连接);
augimdsTrain = augmentedImageDatastore (inputSize (1:2), imdsTrain)
augimdsValidation = augmentedImageDatastore (inputSize (1:2), imdsValidation);
miniBatchSize = 10;
valFrequency =地板(元素个数(augimdsTrain.Files) / miniBatchSize);
选择= trainingOptions ( “个” ,
“MiniBatchSize” 10
“MaxEpochs” 6
“InitialLearnRate” ,0.0007,
“洗牌” , “every-epoch” ,
“ValidationFrequency” valFrequency,
“ValidationData” augimdsValidation,
“详细” 假的,
“阴谋” , “训练进步” );
网= trainNetwork (augimdsTrain、lgraph选项);
(YPred,聚合氯化铝)=(网络,augimdsValidation)进行分类;
精度=意味着(YPred = = imdsValidation.Labels);
idx = randperm(元素个数(imdsValidation.Files), 100);
R = 1;
j =一24
图(j)
i = 1:4
次要情节(2,2,我)
I = readimage (imdsValidation idx (R));
imshow(我)
标签= YPred (idx (R));
标题(string(标签)+ ”、“ + num2str(100 *马克斯(聚合氯化铝(idx (R),:)), 3) + “%” );
R = R + 1;
结束
结束

接受的答案

Andreas Apostolatos
Andreas Apostolatos 2022年6月28日
嗨Rayan,
从你的代码片段分享看来你训练一个神经网络分类然后进行推理时一些验证数据,
网= trainNetwork (augimdsTrain、lgraph选项);
(YPred,聚合氯化铝)=(网络,augimdsValidation)进行分类;
精度=意味着(YPred = = imdsValidation.Labels);
错误等措施 平均平方电路误差 (MSE)或 均方根误差 (RMSE)适合于回归问题的响应变量是连续的,而不是分类问题。
评估分类器的性能更适当的使用 混淆矩阵 或计算的比例反应,正确预测的分类器。相应的工作流是在以下链接下划线,
我希望你找到这些信息有用的需求。
亲切的问候
安德烈亚斯
1评论
Rayan Matlob
Rayan Matlob 2022年6月29日
编辑:Rayan Matlob 2022年6月29日
训练后previeus的例子中,如果我使用(SVM),我能找到MSE,梅RMSE或任何其他分类精度
遵循:
% workspace_5。垫,然后运行下面的代码来完成支持向量机金宝app
%尝试SVM # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
[imdsTrain, imdsTest augimdsValidation] = splitEachLabel (imd, 0.7, 0.2, 0.1, “随机” );
numTrainImages =元素个数(imdsTrain.Labels);
% inputSize = net.Layers (1) .InputSize;
augimdsTrain = augmentedImageDatastore (inputSize (1:2), imdsTrain);
augimdsTest = augmentedImageDatastore (inputSize (1:2), imdsTest);
augimdsValidation = augmentedImageDatastore (inputSize (1:2), imdsValidation);
层= ' avg_pool ' ;
featuresTrain =激活(净、augimdsTrain层, “OutputAs” , “行” );
featuresTest =激活(净、augimdsTest层, “OutputAs” , “行” );
featuresTrain
YTrain = imdsTrain.Labels;
欧美= imdsTest.Labels;
YVal = imdsValidation.Labels;
分类器= fitcecoc (featuresTrain YTrain);
YPred =预测(分类器,featuresTest);
精度=意味着(YPred = =次)
层= ' activation_46_relu ' ;
featuresTrain =激活(净、augimdsTrain层);
featuresTest =激活(净、augimdsTest层);
featuresTrain
featuresTrain =挤压(平均(featuresTrain [1 - 2])) ';
featuresTest =挤压(平均(featuresTest [1 - 2])) ';
featuresTrain
分类器= fitcecoc (featuresTrain YTrain);
YPred =预测(分类器,featuresTest);
精度=意味着(YPred = =次)
% activation_46_relu, - - - - - - >精度= 0.9846
augimdsValidation = augmentedImageDatastore (inputSize (1:2), imdsValidation);
(YPred,聚合氯化铝)=(网络,augimdsValidation)进行分类;
%测试
idx = randperm(元素个数(imdsValidation.Files), 8);
R = 1;
j = 1:2
图(j)
i = 1:4
次要情节(2,2,我)
I = readimage (imdsValidation idx (R));
imshow(我)
标签= YPred (idx (R));
标题(string(标签)+ ”、“ + num2str(100 *马克斯(聚合氯化铝(idx (R),:)), 3) + “%” );
R = R + 1;
结束
结束

登录置评。

更多的答案(0)

社区寻宝

找到宝藏在MATLAB中央,发现社区如何帮助你!

开始狩猎!