Increasing Validation Accuracy for CNN

7 views (last 30 days)
tyler seudath
tyler seudath on 18 Dec 2021
Answered: Prince Kumar on 7 Apr 2022
Dear all,
I am trying to increase my validation accuracy since it it too small around 27%. Is it possible you can suggest a method to increase it?
Here is the code. Thanks a mil.
% SPLITTING COMPLEX DATA INTO TRAINING, TESTING AND VALIDATION
%Then extract the Re and Imaginary parts from each dataset
Train_inputX1 =All_data_segments; %5000 segments x 400 samples
Train_outputX1 =Modulation_Schemes ;% 5000 segments x 1
Test_X1 =ceil(0.1 *size(All_data_segments,1)); % 10% is catered for testing
idx1_t= randperm(size(All_data_segments,1),Test_X1);%This will generate the 10% of the random test numbers from 1 to 5000
%
% % Now I'm gonna partition the data accordingly...
testX1_input = All_data_segments(idx1_t',:); %Phase test input
testX1_output = Modulation_Schemes(idx1_t); %Phase test output
Train_inputX1(idx1_t',:) = []; % assigning '[]' to matrix entries deletes them.
Train_outputX1(idx1_t',:) =[]; % Deletes the outputs that was used to test input
%
% %Now we need to repeat to find the validation data
Train1_inputX1 = Train_inputX1; %5000 segments x 400 samples
Train1_outputX1 =Train_outputX1;% 5000 segments x 1
Val_X1 =ceil(0.2 *size(Train_outputX1,1)); % 10% is catered for Validation
idx1_v= randperm(size(Train_outputX1,1),Val_X1);%This will generate the 10% of the random test numbers from 1 to 5000
%
% Now I'm gonna partition the data accordingly...
ValX1_input =Train1_inputX1(idx1_v',:); %Val input
ValX1_output =Train_outputX1(idx1_v); % Val output
Train1_inputX1(idx1_v',:) = []; % assigning '[]' to matrix entries deletes them.
Train1_outputX1(idx1_v',:) =[]; % Deletes the outputs that was used to validation input
% You have a two dimensional array; call it Data for the moment. The rows correspond to different segments and the columns correspond to different samples, so Data(SegmentNumber, SampleNumber)
%is one piece of information. That information has a real and an imaginary part, so you have real(Data(SegmentNumber, SampleNumber)) and imag(Data(SegmentNumber, SampleNumber)) .
%So you have number of segments times number of samples times two (real + imaginary) pieces of information overall.
% But to store number of segments by number of samples by two pieces of information,
%you can store that in an array that is (NumberOfSegments by NumberOfSamples by 2) large:
DataParts = zeros(size(Train1_inputX1,1), size(Train1_inputX1,2),1,2); %(4500,400,1,2)
DataParts(:,:,:,1) = real(cell2mat(Train1_inputX1));
DataParts(:,:,:,2) = imag(cell2mat(Train1_inputX1)) ;
XTrain=(reshape(DataParts, [400,1,2,3600])); %Train data
DataParts1 = zeros(size(testX1_input,1), size(testX1_input,2),1, 2);
DataParts1(:,:,:,1) = real(cell2mat(testX1_input));
DataParts1(:,:,:,2) = imag(cell2mat(testX1_input)) ;
Ttrain=(reshape(DataParts1,[400,1,2,500])); %Test data
DataParts2 = zeros(size(ValX1_input,1), size(ValX1_input,2),1, 2);
DataParts2(:,:,:,1) = real(cell2mat(ValX1_input));
DataParts2(:,:,:,2) = imag(cell2mat(ValX1_input));
Vtrain =(reshape(DataParts2,[400,1,2,900])); %450 is the number of segments %400 is the number of samples
Valoutfinal= categorical(ValX1_output); %450 values
testoutfinal =categorical(testX1_output); %500 values
Trainoutfinal=categorical(Train1_outputX1);%4050 values
%% NETWORK ARCHITECTURE
layers = [imageInputLayer([400 1 2]) % Creating the image layer
convolution2dLayer([300 1],3,'Stride',1)
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
batchNormalizationLayer
leakyReluLayer
fullyConnectedLayer(4)
softmaxLayer
classificationLayer];
layers2 = [
imageInputLayer([400 1 2])
convolution2dLayer([3 1],8,'Padding',[0 0 0 1])
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer([3 1],16,'Padding',[0 0 0 1])
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer([3 1],32,'Padding',[0 0 0 1])
batchNormalizationLayer
reluLayer
fullyConnectedLayer(4)
softmaxLayer
classificationLayer];
% Specify training options.
opts = trainingOptions('adam', ...
'MaxEpochs',40, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, ...
'ValidationData',{Vtrain,(Valoutfinal)},...
'ValidationPatience',Inf);
opts1 = trainingOptions('adam', ...
'MaxEpochs',100, ...
'InitialLearnRate',1e-3, ...
'Plots','training-progress', ...
'Verbose',false, ...
'ValidationData',{Vtrain,(Valoutfinal)},...
'ValidationPatience',Inf);
%% Train network
%analyzeNetwork(layers)
net1 = trainNetwork(XTrain,Trainoutfinal,layers,opts);

Answers (1)

Prince Kumar
Prince Kumar on 7 Apr 2022
Hi,
Please refer to the following answer :
Hope this helps!

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!