My network is returning both 100 percent training and validation. What seems to be the issue?

4 views (last 30 days)
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);

Answers (1)

Prateek Rai
Prateek Rai on 2 Mar 2022
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by