Validation Accuracy on Neural network
이전 댓글 표시
Hello..I wonder if any of you who have used deep learning on matlab can help me to troubleshoot my problem. I don't understand why I got a sudden drop of my validation accuracy at the end of the graph? It's a simple network with one convolution layer to classify cases with low or high risk of having breast cancer. After the final iteration it displays a validation accuracy of above 80% but then suddenly it dropped to 73% without an iteration. I don't understand that.

Here's my code
%set training dataset folder
digitDatasetPath = fullfile('C:\Users\UOS\Documents\Desiree Data\Run
2\dataBreast\training2');
%training set
imdsTrain = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
%set validation dataset folder
validationPath = fullfile('C:\Users\UOS\Documents\Desiree Data\Run
2\dataBreast\validation2');
%testing set
imdsValidation = imageDatastore(validationPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
%create a clipped ReLu layer
layer = clippedReluLayer(10,'Name','clip1');
% define network architecture
layers = [
imageInputLayer([256 256 1]);
% conv_1
convolution2dLayer(3,32,'Stride',1)
batchNormalizationLayer
clippedReluLayer(10);
maxPooling2dLayer(2,'Stride',2)
%fc
fullyConnectedLayer(100)
dropoutLayer(0.7,'Name','drop1');
%fc
fullyConnectedLayer(25)
dropoutLayer(0.8,'Name','drop2');
% fc layer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
% specify training option
options = trainingOptions('adam', ...
'InitialLearnRate',0.001, ...
'MaxEpochs',15, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
% train network using training data
net = trainNetwork(imdsTrain,layers,options);
% classify validation images and compute accuracy
YPred = classify(net,imdsValidation);
YValidation = imdsValidation.Labels;
%calculate accuracy
accuracy = sum(YPred == YValidation)/numel(YValidation);
댓글 수: 8
Don Mathis
2019년 2월 19일
Does it still happen if you use a much larger MiniBatchSize, say 1000 or 2000?
Andrik Rampun
2019년 2월 19일
편집: Andrik Rampun
2019년 2월 19일
Jon Cherrie
2019년 2월 19일
I think Don means the MiniBatchSize in the training options,
The drop in validation accuracy in the plot might be the same as this:
Andrik Rampun
2019년 2월 19일
Andrik Rampun
2019년 2월 20일
편집: Andrik Rampun
2019년 2월 20일
amir aslam
2019년 4월 16일
I have done the same experiment but accuracy does not drop
code:
clc;
clear;
%set training dataset folder
digitDatasetPath = fullfile('C:\Program Files\MATLAB\R2018aaa\toolbox\nnet\nndemos\nndatasets\Experiments\Train');
%training set
imdsTrain = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
%set validation dataset folder
validationPath = fullfile('C:\Program Files\MATLAB\R2018aaa\toolbox\nnet\nndemos\nndatasets\Experiments\Test');
%testing set
imdsValidation = imageDatastore(validationPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
%create a clipped ReLu layer
%layer = clippedReluLayer(10,'Name','clip1');
% define network architecture
layers = [
imageInputLayer([48 48 3]);
% conv_1
convolution2dLayer(3,32,'Stride',1)
batchNormalizationLayer
reluLayer;
maxPooling2dLayer(2,'Stride',2)
%fc
fullyConnectedLayer(100)
dropoutLayer(0.7,'Name','drop1');
%fc
fullyConnectedLayer(25)
dropoutLayer(0.8,'Name','drop2');
% fc layer
fullyConnectedLayer(7)
softmaxLayer
classificationLayer];
% specify training option
options = trainingOptions('adam', ...
'InitialLearnRate',0.0001, ...
'MaxEpochs',15, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
% train network using training data
net = trainNetwork(imdsTrain,layers,options);
% classify validation images and compute accuracy
YPred = classify(net,imdsValidation);
YValidation = imdsValidation.Labels;
%calculate accuracy
accuracy = sum(YPred == YValidation)/numel(YValidation);

Sridharan K
2021년 3월 10일
i got 100% accuracy. thanks for this program.
Santhosh Surya Kiran
2021년 7월 1일
What u got is wrong..
답변 (4개)
Andrik Rampun
2019년 2월 19일
댓글 수: 18
Don Mathis
2019년 2월 19일
What is the size of your training set?
Andrik Rampun
2019년 2월 20일
Andrik Rampun
2019년 2월 20일
Don Mathis
2019년 2월 20일
편집: Don Mathis
2019년 2월 20일
Your training set has 740 observations, which is a very small training set size, especially for such a large network. Now that you have specified MiniBatchSize=2048, each minibatch contains the entire training set, which we can verify by noticing that the number of iterations is equal to the number of epochs.
Looking at your final plots, I would say there's a good chance that this fixed the problem. The finalized loss is visually identical to the unfinalized loss, and the finalized error rate jumps about 5%, which is probably 5 of your 99 validation observations. I'm not sure why it jumps at all, but 5 observations switching their class seems like noise to me.
You need to run many more iterations. 15 is not enough. I suggest running for at least 100, or until validation error levels off.
Oh, and if you can, try to get your hands on 1 million observations :-)
Andrik Rampun
2019년 2월 20일
Andrik Rampun
2019년 2월 21일
편집: Andrik Rampun
2019년 2월 21일
Don Mathis
2019년 2월 21일
What version of MATLAB are you using? (Which of R2017b, R2018a, R2018b?)
Andrik Rampun
2019년 2월 21일
Don Mathis
2019년 2월 21일
There are 2 ways I'm aware of that BatchNormalization layers can cause this problem:
(1) There is some layer or data transformation that occurs only during training (not during prediction), and which precedes a batchnorm layer (by any distance). For example, if a dropout layer precedes a batchnorm layer, or if your training images have noise added, and your validation images do not.
(2) The mean and variance of your minibatch activations don't match the mean and variance of the full dataset activations.
Unless you're adding noise to your training images in some way, it doesn't appear that either of these scenarios apply to you.
Andrik Rampun
2019년 2월 21일
편집: Andrik Rampun
2019년 2월 21일
Don Mathis
2019년 2월 21일
편집: Don Mathis
2019년 2월 21일
It doesn't look like you're doing anything wrong. I think this is just how these layers behave under these circumstances.
But it's difficult to draw precise conclusions from the experiments you've done because you have used 3 very different networks. The first had 1 conv, 3 fullyConnected, and very high dropout. The second had 1 conv, 1 fullyConnected, and no dropout. The third had 6 conv, 4 fullyConnected, and moderate dropout.
My next hypothesis would be that batchnorm may show this 'drop' effect when the network is too large for the dataset size.
My best guess for removing the 'drop' issue would be:
- Continue to use a large minibatch size (e.g., 2000 or the size of the training set).
- Start with small networks (like your first one) and work up to larger ones gradually.
- Use a dropout rate <= 0.5.
- Do not put dropout before batchnorm in the network.
Andrik Rampun
2019년 2월 22일
Andrik Rampun
2019년 2월 22일
Don Mathis
2019년 2월 22일
Your networks were ok in that regard. You only put dropout after batchnorm. So that's not why you're getting the 'drop' effect.
Andrik Rampun
2019년 2월 26일
Don Mathis
2019년 2월 26일
편집: Don Mathis
2019년 2월 26일
3136 hidden units in each FC layer times batchsize of 2048 adds up to a lot of memory. It's trying to put the whole batch on the GPU at once and failing. This is a common problem. You just need to shrink either the batchsize or parts of the network until it fits.
Andrik Rampun
2019년 2월 26일
Don Mathis
2019년 2월 26일
Yes, MiniBatchSize. And I meant the outputSize of your fullyConnectedLayers could be reduced to something smaller than 3136:
fullyConnectedLayer(3136)
Saira
2020년 6월 15일
0 개 추천
Hi,
I have 5600 training images. I have extracted features using Principal Component Analysis (PCA). Then I am applying CNN on extracted features. My training accuracy is 30%. How to increase training accuracy?
Feature column vector size: 640*1
My training code:
% Convolutional neural network architecture
layers = [
imageInputLayer([1 640 1]);
reluLayer
fullyConnectedLayer(7);
softmaxLayer();
classificationLayer()];
options = trainingOptions('sgdm', 'Momentum',0.95, 'InitialLearnRate',0.0001, 'L2Regularization', 1e-4, 'MaxEpochs',5000, 'MiniBatchSize',8192, 'Verbose', true);
Sevda Kemba
2022년 6월 6일
0 개 추천
@Andrik Rampun Hello. In Matlab, we load the data set with code and limit it in deep learning. But when we train, validation accuracy stays between 40-50%. What can we do to increase it to 90%? We would be very happy if you could help.
Sevda Kemba
2022년 6월 6일
0 개 추천
@Saira Hello. In Matlab, we load the data set with code and limit it in deep learning. But when we train, validation accuracy stays between 40-50%. What can we do to increase it to 90%? We would be very happy if you could help.
카테고리
도움말 센터 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



