-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathage_demo.m
53 lines (47 loc) · 1.55 KB
/
age_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
46
47
48
49
50
51
52
53
%% Deep label distribution learning for age estimation
% add the MatConvNet toolbox to MATLAB path
addpath('./utils')
run('./External/matconvnet-1.0-beta18/matlab/vl_setupnn.m');
%% load pre-trained model
% dldl_vggface_chalearn_1.mat is avlaible at
modelPath = './DLDLModels/dldl_vggface_chalearn_1.mat';
load(modelPath, 'net') ;
clear vl_tmove vl_imreadjpeg ;
opts.gpus = 12;
gpuDevice(opts.gpus)
net = dldl_simplenn_move(net, 'gpu');
rgbMean = net.meta.normalization.averageImage;
%% load image
img_name = 'image_525.jpg';
img_path = fullfile('./images/chalearn15_images', img_name);
imt = imread(img_path);
im = imresize(imt, [224,224]);
data = bsxfun(@minus, single(imresize(im, net.meta.normalization.imageSize(1:2))),...
reshape(net.meta.normalization.averageImage, [1,1,3]));
%% forward
res = dldl_simplenn(net, gpuArray(data), [], [], ...
'accumulate', 0, ...
'mode', 'test', ...
'conserveMemory', 1) ;
pred_score = squeeze(gather(res(end).x));
pred_age = (1:85)*pred_score;
%% visialization
close all
figure(1)
imshow(imt)
figure(2)
plot(pred_score,'--ro','LineWidth',2,...
'MarkerEdgeColor','r',...
'MarkerFaceColor','r',...
'MarkerSize',5)
grid on
axis([0 85 0 0.12])
ylabel('Probability','color','blue','FontSize',12)
xlabel('Age','color','blue','FontSize',12)
set(gca,'YTick',0:0.01:max(pred_score));
set(gca,'XTick',0:10:85);
set(gca,'FontSize',10)
axis([1, 85 0 max(max(pred_score), max(pred_score))])
grid on
title(sprintf('PredAge: %.2f', pred_age))
% print(gcf,'-depsc',['figure/chalearn15',img_name,'.eps'])