-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproj.m
53 lines (37 loc) · 1.38 KB
/
proj.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
clear; clc;
imSize = [600 800 3];
imds = imageDatastore('images', 'LabelSource', 'foldernames', 'IncludeSubfolders',true);
numTrainFiles = 15;
[imdsTrain,imdsValidation] = splitEachLabel(imds,numTrainFiles,'randomize');
imdsTrain = transform(imdsTrain,@preprocess,'IncludeInfo',true);
imdsValidation = transform(imdsValidation,@preprocess,'IncludeInfo',true);
layers = [
imageInputLayer(imSize)
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer
];
options = trainingOptions('sgdm', ...
'ExecutionEnvironment','gpu', ... # suggestion to change to gpu or paralell, if you have suitable system
'InitialLearnRate',0.01, ...
'MaxEpochs',10, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(imdsTrain,layers,options);
YPred = classify(net,imdsValidation);
YValidation = imdsValidation.UnderlyingDatastore.Labels;
accuracy = sum(YPred == YValidation)/numel(YValidation);