-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdemo.m
45 lines (37 loc) · 1.06 KB
/
demo.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
close all
clear
clc
% add MatConNet toolbox
run pathToMatConvNet/matlab/vl_setupnn.m;
% set gpuOn to your GPU index, set the value to 0 for CPU mode
gpuOn = 1;
% load a pre-trained CNN model
load('./model/cnn6_v1_aflw.mat');
net = dagnn.DagNN.loadobj(net);
if gpuOn
gpuDevice(gpuOn);
net.move('gpu');
end
imglist = dir('./imgs/*.jpg');
inImgSize = net.meta.inputSize(1);
% apply the model to cropped face images for facial landmark localisation
for i = 1:length(imglist)
img = imread(['./imgs/' imglist(i).name]);
tmpImg = imresize(img, [inImgSize, inImgSize]);
tmpImg = im2single(tmpImg);
if gpuOn
tmpImg = gpuArray(tmpImg);
end
net.eval({'input', tmpImg});
if gpuOn
lmks = squeeze(gather(net.vars(end).value)) / inImgSize * size(img,1);
else
lmks = squeeze(net.vars(end).value) / inImgSize * size(img,1);
end
imshow(img);
hold on;
plot(lmks(1:end/2), lmks(end/2+1:end), 'ko', 'MarkerFaceColor', 'yellow');
title('Press any key to the next image!');
hold off;
pause();
end