I want to increase the validation accuracy in CNN deep learning (Really need help)

3 views (last 30 days)
I have 1300 with 5 class.
the problem is when i train the network, the higher the validation data the lower the validation accuracy and the higher the loss validation. I really hope someone can help me figure this out. I dont know what to do.
i need to train for 20%,30% and 40% validation dataset and i want to have about 80-95% accuracy
this is my code
clc
clear all
% Load PV image Dataset.
imds = imageDatastore("C:\Users\ainur\Desktop\CNN dataset","IncludeSubfolders",true,"LabelSource","foldernames");
labelCount = countEachLabel(imds);
imdsTrain = imds;
[imdsTrain,imdsValidation] = splitEachLabel(imdsTrain,0.7);
% Define the CNN Network Architecture
c1=convolution2dLayer([3 3],32,'stride',1);
c2=convolution2dLayer([3 3],64,'stride',1);
c3=convolution2dLayer([3 3],128,'stride',1);
maxPool = maxPooling2dLayer([2 2],'stride',1);
f1 = fullyConnectedLayer(256);
f2 = fullyConnectedLayer(128);
f3 = fullyConnectedLayer(5);
layers = [ imageInputLayer([100 100 3]) ;
c1; reluLayer;
c1; reluLayer;
maxPool; batchNormalizationLayer;
c2; reluLayer;
c2; reluLayer;
maxPool ; batchNormalizationLayer;
c3; reluLayer;
c3; reluLayer;
globalMaxPooling2dLayer; batchNormalizationLayer;
f1; reluLayer;
f2; reluLayer; batchNormalizationLayer;
f3; softmaxLayer;
classificationLayer ];
% specify the training options for the classifier
miniBatchSize = 30;
valFrequency = floor(numel(imdsTrain.Files)/miniBatchSize);
options = trainingOptions('sgdm', ...
'MiniBatchSize',miniBatchSize, ...
'MaxEpochs',16, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropFactor',0.5, ...
'LearnRateDropPeriod',10, ...
'Momentum',1, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',valFrequency, ...
'Verbose',false, ...
'Plots','training-progress');
% Train the network
[net, traininfo] = trainNetwork(imdsTrain,layers,options);
% Classify Validation Images
YPred = classify(net,imdsValidation);
YValidation = imdsValidation.Labels;
accuracy = sum(YPred == YValidation)/numel(YValidation);
cm = confusionchart(YValidation,YPred);
cm.Title = 'Confusion Chart for CNN';
please i really need help.
  1 Comment
Jiaxu Song
Jiaxu Song on 5 Jun 2022
I think you need to create a testing dataset for testing only, here you are using the validation data set to test your accuracy.
[trainImgs,imdsValidation,testImgs] = = splitEachLabel(imds,0.6,0.2...
,0.2,"randomized");

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 6 Jun 2022
Of course when you increase the validation percentage you are taking a higher percentage of images away from the training set, so of course the accuracy will be less -- you're training on fewer images.
And of course the accuracy on the validation images will be less than on the training images for obvious reasons.
You could train longer but it looks like you max out around 300 iterations, 10 epochs. Longer training time may just get it to remember your images better (overfitting) and not necessarily increase accuracy on the validation image set. The other, and best option, is to just get some more images to train with.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!