My network is returning both 100 percent training and validation. What seems to be the issue?
2 次查看(过去 30 天)
显示 更早的评论
myfolder = 'C:\Users\MigueLegaspi\Downloads\fall dataset\rgb';
dataDir = fullfile(myfolder);
imdir = fullfile(dataDir);
myfolder2 = 'C:\Users\MigueLegaspi\Downloads\Validation\rgb';
dataDir2 = fullfile(myfolder2);
imdir2 = fullfile(dataDir2);
imds = imageDatastore(imdir, "IncludeSubfolders",true ,"LabelSource","foldernames");
imds2 = imageDatastore(imdir2,"IncludeSubfolders",true,"LabelSource","foldernames");
numTrainfiles =6963;
numValidfiles = 6598;
[imdsTrain] = splitEachLabel(imds,numTrainfiles,'randomized');
[imdsValidation] = splitEachLabel(imds2,numValidfiles,'randomized');
%definingarchitecture
numClasses = numel(categories(imdsTrain.Labels));
numClasses2 = numel(categories(imdsValidation.Labels));
layers = [
imageInputLayer([240 320 3])
convolution2dLayer(3,16,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,"Stride",2)
convolution2dLayer(3,32,'Padding',1)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
%trainetwork
options = trainingOptions('sgdm', ...
'MaxEpochs',4, ...
'MiniBatchSize',64,...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(imdsTrain,layers,options);
YPred = classify(net,imdsValidation);
yvalidation = imdsValidation.Labels;
accuracy = mean(Ypred == yvalidation);
0 个评论
回答(1 个)
Prateek Rai
2022-3-2
To my understanding, you are trying to train the network and the network is returning both 100 percent training and validation.
One possible reason for this could be that your datastore is not created properly. Your folder might contain only one subfolder and hence creating only one class in imds which might be leading to 100 percent training and validation accuracy.
Try checking the dataset once. You can refer to the imageDatastore MathWorks Documentation page to learn more about creating a datastore for image data.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!