-
Notifications
You must be signed in to change notification settings - Fork 9
/
Test.m
62 lines (47 loc) · 1.81 KB
/
Test.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
55
56
57
58
59
60
61
62
%% Set up dependencies
addpath('utility');
MatConvNetDir = 'D:\Repo\matconvnet'; % Change this to your MatConvNet path
VLFeatDir = 'D:\Libs\vlfeat-0.9.20'; % Change this to your VLFeat path
addpath(fullfile(VLFeatDir, 'toolbox')); vl_setup;
run(fullfile(MatConvNetDir, 'matlab', 'vl_setupnn.m'));
%% Settings
opts = struct;
opts.testDir = 'examples';
opts.modelDir = 'models';
opts.outDir = 'out';
opts.batchSize = 1;
%%
fileList = [dir(fullfile(opts.testDir, '*.jpg')); dir(fullfile(opts.testDir, '*.png'))];
fileList = arrayfun(@(x)(fullfile(opts.testDir, x.name)), fileList, 'UniformOutput', false);
faceDetPath = fullfile(opts.testDir, 'bbxDet.mat');
fprintf('Loading face detection (%s)\n', faceDetPath);
ldata = load(faceDetPath);
bbxDet = ldata.bbxDet;
if ~exist('model', 'var') || ~exist('net', 'var')
modelPath = fullfile(opts.modelDir, 'pre-trained.mat');
fprintf('Loading the model (%s)\n', modelPath);
model = load(modelPath);
net = dagnn.DagNN.loadobj(model.net);
net.move('gpu');
net.mode = 'test';
model.net = net;
end
%%
fprintf('Refining the detection\n');
bbxRef = refinedet(fileList, bbxDet, model);
%%
fprintf('Classifying\n');
lmCluster = model.lmCluster;
optstt = struct;
optstt.outDir = fullfile(opts.outDir, 'classification');
optstt.bbxDet = bbxRef;
optstt.batchSize = opts.batchSize;
[lmPredict, infoClassify, labels, bbxMargin] = batchtestdiscrete(net, fileList, lmCluster, optstt);
%%
fprintf('Post-processing regression (trained with the same example sharing idea)\n');
initShape = lmPredict;
regModelDir = fullfile(opts.modelDir, 'ppreg');
optsreg = struct;
optsreg.outDir = opts.outDir;
optsreg.bbxDet = bbxRef;
[lmPredict, bbxMarginTest, info] = batchtestCReg(regModelDir, fileList, labels, initShape, optsreg);