CNN的模型只预测了三个班级中的一个?

29意见(过去30天)
威拉
威拉 2020年5月14日
回答: 威拉2020年7月24日
你好,
我正在训练一个CNN模型,用于使用图像分类识别路面损坏。我有三种类型的缺陷(鳄鱼裂缝,凹坑和车辙)。当我运行我的模型时,它只预测了三个类中的一个,使我的模型精度达到33.33%。我尝试改变训练参数/选项,但结果是一样的。我希望有人能帮我找出原因。我使用的代码如下所示。提前谢谢。
_______________________________________________________________________________________________________________________________________
rootFolder = fullfile ('CNN输入');
类别= {'鳄鱼裂缝','坑洼','rutting'};
IMDS = imageageAtastore(fullfile(rootfolder,类别),'labelsource','foldernames');
TBL = CONSECHANCHLABEL(IMDS);
minsetcount = min(tbl {:,2});
CountAckeLabel(IMDS);
alligatorcracks = find(imds.labels =='鳄鱼裂缝',1);
凹坑=找到(imd)。标签= =“坑坑洼洼”,1);
rutting = find(imds.labels =='rutting',1);
net = alexnet();
rng(“违约”);
net.Layers (1);
Net.Layers(END);
numel(net.layers(结束).classnames);
[trainingSet, testSet, validationSet] = splitEachLabel(imds,0.75,0.15,'randomize');
图象尺寸= net.Layers (1) .InputSize;
AugmentedTrainingset = AugmentedimageGedAtastore(图像化,培训集,'ColorPrepossing','Gray2RGB');
AugmentedTestset = AugmentedimageDataStore(图像,测试集,'ColorPrepossing','Gray2RGB');
augmentedValidationSet = augmentedImageDatastore(图象尺寸、validationSet ' ColorPreprocessing ', ' gray2rgb ');
w1 = net.layers(2)。重量;
w1 = mat2gray(w1);
featurelayer =“drop7”;
TrainingFeatures =激活(Net,AugmentedTraininget,FeatureLayer,'Minibatchsize',32,'Outputas','列');
选项= TrainingOptions('sgdm',...
“LearnRateSchedule”、“分段”,…
'Searchratedropfactor',0.2,...
'searnratedropperiod',1,...
“MaxEpochs”8…
'Minibatchsize',16,......
'Plots','培训 - 进步',......
“洗牌”、“一次”);
numclasses = 3;
layersTransfer = net.Layers (1: end-3);
层= [
图案转移
全连接列(numcrasses,'weyrlearnratefactor',20,'biaslearnratefactor',20)
softmaxlayer.
ClassificationLayer];
TrousaInnet = Trainnetwork(AugmentedTraininget,图层,选项);
traininglabels =培训。标签;
分类器= fitcecoc(TrainingFeatures,培训标签,'学习者','线性','编码','OneVsall','观察','列');
testFeatures =激活(trainedNet,augmentedTestSet, featurelayer,'MiniBatchSize', 32,'OutputAs', 'columns');
validationFeatures =激活(trainedNet,augmentedValidationSet, featurelayer,'MiniBatchSize', 32,'OutputAs', 'columns');
predictlabels =预测(分类器,testfeatures,'观察','列');
validationFeatures predictLabelss =预测(分类器,“ObservationsIn”,“列”);
testLables = testSet.Labels;
validationLables = validationSet.Labels;
Confmat =困惑硕士(避孕网,预测标签);
confmatt = confusionmat(验证,预测标签);
= bsxfun(@rdivide, confMat, sum(confMat,2));
confmatt = bsxfun(@rdivide,confmatt,sum(confmatt,2));
意思是(诊断接头(confMat));
意思(Dig(Confmatt));

接受答案

Shishir Singhal
Shishir Singhal 20月22日
嗨,你面临这个问题可能是因为类不平衡。
只需检查每个类中的数据点数。
要处理类别不平衡,您可以使用数据增强技术。
对于MATLAB中的数据增强,您可以参考此链接: //www.tatmou.com/help/deeplearning/ref/imagedataaugmenter.html
3评论
威拉
威拉 20月27日
谢谢你的回答。我会尝试多个奥姆图。
我相信每堂课上的图像都是相同的数字,但我会仔细研究,看看数据是如何分布的。你能给我提供行代码来做那个或者任何能帮助我做那个的链接吗?正如我之前提到的,我对MATLAB不是很了解,我刚刚开始学习CNN。
您的帮助确实非常感激。
非常感谢。

登录评论。

答案(1)

威拉
威拉 2020年7月24日
我发现我的模型通过改变培训选项来工作。人们可以尝试不同的基本学习率和小批量大小以及时代数量的组合。这真的是一个选择的问题,但你必须找到适合你问题的组合。