你好,
我正在训练一个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));