-
Notifications
You must be signed in to change notification settings - Fork 23
/
deepsig_mcnet_running.m
32 lines (27 loc) · 1.13 KB
/
deepsig_mcnet_running.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
imds = imageDatastore('DeepSig\','IncludeSubfolders',true,'LabelSource','foldernames','FileExtensions',{'.mat'});
[imdsTrain,imdsTest] = splitEachLabel(imds,0.8,'randomized');
imdsTrain.Labels = categorical(imdsTrain.Labels);
imdsTrain.ReadFcn = @readFcnMatFile;
imdsTest.Labels = categorical(imdsTest.Labels);
imdsTest.ReadFcn = @readFcnMatFile;
batchSize = 128;
ValFre = fix(length(imdsTrain.Files)/batchSize);
options = trainingOptions('sgdm', ...
'MiniBatchSize',batchSize, ...
'MaxEpochs',60, ...
'Shuffle','every-epoch',...
'InitialLearnRate',0.01, ...
'LearnRateSchedule','piecewise',...
'LearnRateDropPeriod',30,...
'LearnRateDropFactor',0.1,...
'ValidationData',imdsTest, ...
'ValidationFrequency',ValFre, ...
'ValidationPatience',Inf, ...
'Verbose',true ,...
'VerboseFrequency',ValFre,...
'Plots','training-progress',...
'ExecutionEnvironment','gpu');
trainednet = trainNetwork(imdsTrain,lgraph,options);
YPred = classify(trainednet,imdsTest,'ExecutionEnvironment','gpu');
YTest = imdsTest.Labels;
accuracy = sum(YPred == YTest)/numel(YTest);