1
1
function ESR_Test()
2
2
%% load parameters
3
- params = Train_params ;
3
+ params = Test_params ;
4
4
% create paralllel local jobs note
5
5
if isempty(gcp(' nocreate' ))
6
6
parpool(2 );
7
7
end
8
8
%% load data
9
9
if exist(' Data/train_init.mat' , ' file' )
10
10
load(' Data/train_init.mat' , ' data' );
11
+ initSet = data ;
12
+ clear data ;
11
13
else
12
- data = loadsamples(' D:\Dataset\lfpw\annotations\t estset' , ' png' );
13
- % mkdir Data;
14
- save(' Data/train_init.mat' , ' data' );
14
+ disp(' lack of initial set of shapes' );
15
15
end
16
16
17
+ Data = loadsamples(' /Volumes/LG_SDJet/Datasets/lfpw/annotations/trainset' , ' png' );
18
+ params.N_img = size(Data , 1 );
17
19
load(' Data/InitialShape_68' );
18
20
dist_pupils_ms = getDistPupils(S0 );
19
21
params.meanshape = S0(params .ind_usedpts , : );
20
22
params.N_fp = size(params .meanshape , 1 );
21
- % load('../../Data/toyData.mat', 'bbx_aug', 'pts_aug');
22
- % load('../../Data/Test_Data.mat', 'test_images', 'test_bbx', 'test_pts'); % load the current shapes
23
- load(' ../../Data/Model.mat' , ' Model' );
24
- params = Test_params ;
25
- params.N_img = size(test_images , 1 );
26
-
23
+
24
+ load(' Data/Model.mat' , ' Model' );
27
25
%%
28
26
for i = 1 : 1
29
- image = test_images{i };
30
- bbx = test_bbx{i };
31
- Prediction = ShapeRegression(image , bbx , bbx_aug , pts_aug , Model , params );
27
+ Prediction = ShapeRegression(Data{i }, initSet , Model , params );
32
28
figure
33
- imshow(test_images {i }.faceimg )
29
+ imshow(Data {i }.img_gray )
34
30
hold on
35
31
plot(Prediction(: , 1 ), Prediction(: , 2 ), ' g+' );
36
32
hold off
37
33
end
38
34
39
35
end
40
36
41
- function predict = ShapeRegression(image , bbx , bbx_aug , pts_aug , Model , params )
37
+ function predict = ShapeRegression(data , initSet , Model , params )
42
38
% Multiple initializations
43
39
44
40
% predict = zeros(params.N_fp, 2);
45
- [current_shapes ] = initialTest(image , bbx , bbx_aug , pts_aug , params );
46
- % for i = 1: params.N_init
47
- % current_shape = pts_aug{Index_init(i)}.pts_chs;
48
- % current_bbx = bbx_aug{Index_init(i)}.bbx_chs;
49
- % current_shape = projectShape(current_shape, current_bbx);
50
- % current_shape = reprojectShape(current_shape, bbx.bbx_chs);
51
- %
52
- % for t = 1: params.T
53
- % prediction_delta = fernCascadeTest(image, current_shape, Model{t}.fernCascade, params);
54
- % current_shape = prediction_delta + projectShape(current_shape, bbx.bbx_chs);
55
- % current_shape = reprojectShape(current_shape, bbx.bbx_chs);
56
- % end
57
- %
58
- % predict = predict + current_shape;
59
- % end
60
- % Predictions = zeros(params.N_fp, 2, params.N_init);
41
+ ctshapes = initialTest(data , initSet , params );
42
+
61
43
for t = 1 : params .T
62
44
for i = 1 : params .N_init
63
- prediction_delta = fernCascadeTest(image , current_shapes(: , : , i ), Model{t }.fernCascade, params );
64
- current_norm_shape = prediction_delta + projectShape(current_shapes(: , : , i ), bbx .bbx_chs );
65
- current_shapes(: , : , i ) = reprojectShape(current_norm_shape , bbx .bbx_chs );
45
+ prediction_delta = fernCascadeTest(data , ctshapes(: , : , i ), Model{t }.fernCascade, params );
46
+ ctshapes(: , : , i ) = ctshapes(: , : , i ) + prediction_delta ;
66
47
end
67
48
end
68
- predict = mean(current_shapes , 3 );
49
+ predict = mean(ctshapes , 3 );
69
50
end
70
51
71
52
function prediction_delta = fernCascadeTest(image , current_shape , fernCascade , params )
72
53
image.intermediate_bbx = getbbox(current_shape );
73
- meanshape = reprojectShape( params . mean_shape , image . intermediate_bbx );
54
+ meanshape = resetshape( image . intermediate_bbx , params . meanshape );
74
55
image.tf2meanshape = fitgeotrans(bsxfun(@minus , current_shape , mean(current_shape )), ...
75
56
bsxfun(@minus , meanshape , mean(meanshape )),...
76
57
' nonreflectivesimilarity' );
@@ -79,8 +60,8 @@ function ESR_Test()
79
60
' nonreflectivesimilarity' );
80
61
81
62
% extract shape indexed pixels
82
- candidate_pixel_location = fernCascade .candidate_pixel_locations ;
83
- nearest_landmark_index = fernCascade .selected_nearest_landmark_index ;
63
+ candidate_pixel_location = fernCascade .candidate_pixel_location ;
64
+ nearest_landmark_index = fernCascade .nearest_landmark_index ;
84
65
intensities = zeros(1 , params .P );
85
66
for j = 1 : params .P
86
67
x = candidate_pixel_location(j , 1 )*image .intermediate_bbx(3 );
@@ -90,12 +71,12 @@ function ESR_Test()
90
71
91
72
real_x = round(project_x + current_shape(index , 1 ));
92
73
real_y = round(project_y + current_shape(index , 2 ));
93
- real_x = max(1 , min(real_x , size(image .faceimg , 2 )-1 ));
94
- real_y = max(1 , min(real_y , size(image .faceimg , 1 )-1 ));
95
- intensities(j )= image .faceimg (real_y , real_x );
74
+ real_x = max(1 , min(real_x , size(image .img_gray , 2 )-1 ));
75
+ real_y = max(1 , min(real_y , size(image .img_gray , 1 )-1 ));
76
+ intensities(j )= image .img_gray (real_y , real_x );
96
77
end
97
78
98
- delta_shape = zeros(size(params .mean_shape ));
79
+ delta_shape = zeros(size(params .meanshape ));
99
80
for i = 1 : params .K
100
81
fern = fernCascade.ferns{i }.fern;
101
82
delta_shape = delta_shape + fernTest(intensities , fern , params );
@@ -104,7 +85,7 @@ function ESR_Test()
104
85
% convert to the currentshape model
105
86
[u , v ] = transformPointsForward(image .meanshape2tf , delta_shape(: , 1 ), delta_shape(: , 2 ));
106
87
prediction_delta = [u , v ];
107
- % prediction_delta = bsxfun(@times, delta_shape_interm_coord , [image.intermediate_bbx(3),image.intermediate_bbx(4)]);
88
+ prediction_delta = bsxfun(@times , prediction_delta , [image .intermediate_bbx(3 ),image .intermediate_bbx(4 )]);
108
89
end
109
90
110
91
function fern_pred = fernTest(intensities , fern , params )
0 commit comments