-
Notifications
You must be signed in to change notification settings - Fork 2
/
CNN_2.m
54 lines (39 loc) · 1.09 KB
/
CNN_2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
clc;
clear all;
close all;
load data_for_cnn.mat;
load class_label.mat;
for j=1:1000
ecg_in_window(:,j)=ecg_in_window(:,j)/max(abs(ecg_in_window(:,j)));
end
height = 1;
width = 1000;
channels = 1;
C = cvpartition(label,'HoldOut',0.3);
tr = C.training;
te = C.test;
Xtr = ecg_in_window(tr,:);
Xte = ecg_in_window(te,:);
Ytr = label(tr,:);
Yte = label(te,:);
Xtr = reshape(Xtr,[height width channels 700]);
Xte = reshape(Xte,[height width channels 300]);
Ytr = categorical(Ytr);
Yte = categorical(Yte);
layers = [
imageInputLayer([height width channels])
convolution2dLayer([1, 25],10)
batchNormalizationLayer
reluLayer
maxPooling2dLayer([1 20])
fullyConnectedLayer(20)
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.001, ...
'MaxEpochs',200, 'Plots','training-progress');
net = trainNetwork(Xtr,Ytr,layers,options);
YPred = classify(net,Xte);
YValidation = Yte;
accuracy = sum(YPred == YValidation)/numel(YValidation);