How do I make this code exceed 80 percent?
Show older comments
%Classify PQD Signals Using Continuous Wavelet Transform and AlexNet
clc;
%clear;
close all;
% This signal is a matrix of size N x 45000. So it means that it carries N Power Quality Des. signals of size 45000 samples each.
% PQD = load('/home/draadel/Desktop/physionet_ECG_data-main/PQD_DATA/Noise_Data.mat'); %load ecg
% data=PQD.DATA_noise.Data;
% labels=PQD.DATA_noise.Labels; %getting labels
%
% % PQD signal to image conversion using cwt
% SAG = data(1:50,:);
% SWELL = data(51:100,:);
% HARMONICS = data(101:150,:);
% signallength = 450;
% Fs = 2500 ;
% %Defining filters for CWT with 48 filtering per octave
%
% fb = cwtfilterbank('SignalLength',signallength,'SamplingFrequency',Fs, ...
% 'VoicesPerOctave',48); %cwtfilterbank
%
% % ecgtype is a cell array that carries the names of the signal by string.
% PQDtype = {'Sag', 'Swell', 'Harmonics'};
%
% %Function to convert ECG to image
% PDQ2cwtscg_cnn(SAG, fb, PQDtype{1});
% PDQ2cwtscg_cnn(SWELL, fb, PQDtype{2});
% PDQ2cwtscg_cnn(HARMONICS, fb, PQDtype{3});
%
% % Training and validation using AlexNet
% DatasetPath = '/MATLAB Drive/CNN';
%
% % reading images from the image database folder
% images = imageDatastore(DatasetPath, "IncludeSubfolders", true, "LabelSource", "foldernames");
%
% % Distributing images in the set of training and testing
% numTrainFiles = 875; % 70% of the data
% [TrainImages, TestImages] = splitEachLabel(images, numTrainFiles, "randomized");
% numTrainFiles_for_training = 700 ; % *0 % of the training data
% [TrainImages_for_training, TrainImages_for_Validation] = splitEachLabel(TrainImages, numTrainFiles_for_training, "randomized");
%% Code for Design and Training - CNN from Scratch
% Resize the images to match the network input layer.
augimdsTrain = augmentedImageDatastore([240 240 3],TrainImages_for_training);
augimdsValidation = augmentedImageDatastore([240 240 3],TrainImages_for_Validation);
%training options
opts = trainingOptions("sgdm",...
"ExecutionEnvironment","auto",...
"InitialLearnRate",0.01,...
"LearnRateSchedule",'piecewise',...
"LearnRateDropFactor",0.1,...
"LearnRateDropPeriod",10,...
"L2Regularization",0.0001,...
"MaxEpochs",20,...
"MiniBatchSize",128,...
"Shuffle","once",...
"ValidationFrequency",50,...
"Plots","training-progress",...
"ValidationData",augimdsValidation);
%create an array of layers
layers = [
imageInputLayer([240 240 3],"Name","imageinput")
convolution2dLayer([3 8],32,"Name","conv_1","Padding","same")
batchNormalizationLayer("Name","batchnorm_1")
reluLayer("Name","relu_1")
maxPooling2dLayer([2 2],"Name","maxpool_1","Padding","same","Stride",[2 2])
convolution2dLayer([3 16],32,"Name","conv_2","Padding","same")
batchNormalizationLayer("Name","batchnorm_2")
reluLayer("Name","relu_2")
maxPooling2dLayer([2 2],"Name","maxpool_2","Padding","same","Stride",[2 2])
convolution2dLayer([3 32],32,"Name","conv_3","Padding","same")
batchNormalizationLayer("Name","batchnorm_3")
reluLayer("Name","relu_3")
maxPooling2dLayer([2 2],"Name","maxpool_3","Padding","same","Stride",[2 2])
convolution2dLayer([3 64],32,"Name","conv_4","Padding","same")
batchNormalizationLayer("Name","batchnorm_4")
reluLayer("Name","relu_4")
maxPooling2dLayer([2 2],"Name","maxpool_4","Padding","same","Stride",[2 2])
convolution2dLayer([3 128],32,"Name","conv_5","Padding","same")
batchNormalizationLayer("Name","batchnorm_5")
reluLayer("Name","relu_5")
fullyConnectedLayer(3,"Name","fc","BiasLearnRateFactor",10, ...
"WeightLearnRateFactor",10)
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")];
%train cnn
[net, traininfo] = trainNetwork(augimdsTrain,layers,opts);
%% Plot Training Performance
%Classifying images
YPred = classify(net, TestImages);
YValidation = TestImages.Labels;
accuracy = sum(YPred == YValidation)/numel(YValidation);
%plotting Confusion Matrix
plotconfusion(YValidation, YPred)
Answers (1)
Categories
Find more on Wavelet 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!