-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCNN.m
29 lines (27 loc) · 893 Bytes
/
CNN.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
layers = [
imageInputLayer([525 700 3])
convolution2dLayer(3,16,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,32,'Padding',1)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(4)
softmaxLayer
classificationLayer];
%opts = trainingOptions('sgdm');
opts = trainingOptions('sgdm',...
'InitialLearnRate',0.001,...
'LearnRateSchedule', 'piecewise',...
'LearnRateDropFactor',0.1,...
'LearnRateDropPeriod',8,...
'L2Regularization',0.004,...
'MaxEpochs',10,...
'MiniBatchSize',10,...
'Verbose',true,...
'Plots','training-progress');
[trainedNet,traininfo]= trainNetwork(trainData,layers,opts);
YPred=classify(trainedNet,testData,'ExecutionEnvironment','cpu')
YTest = testData.Labels;
accuracy = sum(YPred == YTest)/numel(YTest)