使用alexnet从头开始训练,100分类问题。数据集采用的是caltech101,大概9000张图片,一共102类。但是在训练中测试集和数据集准确率一直都是0,loss也不降了...请教各位到底是什么原因?
matlab代码段:
clc
%加载数据
imds = imageDatastore('./Caltech101', 'IncludeSubfolders',true,'LabelSource','foldernames');
[imdsTrain,imdsValidation] = splitEachLabel(imds,30,'randomized');
% 加载预训练网络
layers = alexnet('Weights', 'none');
inputSize = layers(1).InputSize;
layersTransfer = layers(1:end-3);
numClasses = numel(categories(imdsTrain.Labels));
layers = [
layersTransfer
fullyConnectedLayer(numClasses,'WeightLearnRateFactor',20,'BiasLearnRateFactor',20)
softmaxLayer
classificationLayer];
%数据增强
pixelRange = [-30 30];
imageAugmenter = imageDataAugmenter( ...
'RandXReflection',true, ...
'RandXTranslation',pixelRange, ...
'RandYTranslation',pixelRange);
augimdsTrain = augmentedImageDatastore(inputSize(1:3),imdsTrain,'DataAugmentation',imageAugmenter,'ColorPreprocessing','gray2rgb');
augimdsValidation = augmentedImageDatastore(inputSize(1:3),imdsValidation,'ColorPreprocessing','gray2rgb');
%训练
options = trainingOptions('sgdm', ...
'MiniBatchSize',64, ...
'MaxEpochs',50, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',augimdsValidation, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'Plots','training-progress');
netTransfer = trainNetwork(augimdsTrain,layers,options);
感觉是数据的问题,建议将数据打印一下,看看是否每次取出来的数据都正确
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps: 问答会员【8折】购 ,仅需→¥23.2,即可享受5次/月 有问必答服务,了解详情>>>https://t.csdnimg.cn/RW5m
问题我自己看了看,原因是参数没有初始化,这样会导致都是0,无法训练。