Skip to content

Commit 2cfbc58

Browse files
committed
Test for the first time
1 parent 6612fe7 commit 2cfbc58

File tree

7 files changed

+45
-64
lines changed

7 files changed

+45
-64
lines changed

ESR_Test.m

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,57 @@
11
function ESR_Test()
22
%% load parameters
3-
params = Train_params;
3+
params = Test_params;
44
% create paralllel local jobs note
55
if isempty(gcp('nocreate'))
66
parpool(2);
77
end
88
%% load data
99
if exist('Data/train_init.mat', 'file')
1010
load('Data/train_init.mat', 'data');
11+
initSet = data;
12+
clear data;
1113
else
12-
data = loadsamples('D:\Dataset\lfpw\annotations\testset', 'png');
13-
%mkdir Data;
14-
save('Data/train_init.mat', 'data');
14+
disp('lack of initial set of shapes');
1515
end
1616

17+
Data = loadsamples('/Volumes/LG_SDJet/Datasets/lfpw/annotations/trainset', 'png');
18+
params.N_img = size(Data, 1);
1719
load('Data/InitialShape_68');
1820
dist_pupils_ms = getDistPupils(S0);
1921
params.meanshape = S0(params.ind_usedpts, :);
2022
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');
2725
%%
2826
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);
3228
figure
33-
imshow(test_images{i}.faceimg)
29+
imshow(Data{i}.img_gray)
3430
hold on
3531
plot(Prediction(:, 1), Prediction(:, 2), 'g+');
3632
hold off
3733
end
3834

3935
end
4036

41-
function predict = ShapeRegression(image, bbx, bbx_aug, pts_aug, Model, params)
37+
function predict = ShapeRegression(data, initSet, Model, params)
4238
% Multiple initializations
4339

4440
%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+
6143
for t = 1: params.T
6244
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;
6647
end
6748
end
68-
predict = mean(current_shapes, 3);
49+
predict = mean(ctshapes, 3);
6950
end
7051

7152
function prediction_delta = fernCascadeTest(image, current_shape, fernCascade, params)
7253
image.intermediate_bbx = getbbox(current_shape);
73-
meanshape = reprojectShape(params.mean_shape, image.intermediate_bbx);
54+
meanshape = resetshape(image.intermediate_bbx, params.meanshape);
7455
image.tf2meanshape = fitgeotrans(bsxfun(@minus, current_shape, mean(current_shape)), ...
7556
bsxfun(@minus, meanshape, mean(meanshape)),...
7657
'nonreflectivesimilarity');
@@ -79,8 +60,8 @@ function ESR_Test()
7960
'nonreflectivesimilarity');
8061

8162
%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;
8465
intensities = zeros(1, params.P);
8566
for j = 1: params.P
8667
x = candidate_pixel_location(j, 1)*image.intermediate_bbx(3);
@@ -90,12 +71,12 @@ function ESR_Test()
9071

9172
real_x = round(project_x + current_shape(index, 1));
9273
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);
9677
end
9778

98-
delta_shape = zeros(size(params.mean_shape));
79+
delta_shape = zeros(size(params.meanshape));
9980
for i = 1: params.K
10081
fern = fernCascade.ferns{i}.fern;
10182
delta_shape = delta_shape + fernTest(intensities, fern, params);
@@ -104,7 +85,7 @@ function ESR_Test()
10485
%convert to the currentshape model
10586
[u, v] = transformPointsForward(image.meanshape2tf, delta_shape(:, 1), delta_shape(:, 2));
10687
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)]);
10889
end
10990

11091
function fern_pred = fernTest(intensities, fern, params)

ESR_Train.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function ESR_Train()
99
if exist('Data/train_init.mat', 'file')
1010
load('Data/train_init.mat', 'data');
1111
else
12-
data = loadsamples('D:\Dataset\lfpw\annotations\trainset', 'png');
12+
data = loadsamples('/Volumes/LG_SDJet/Datasets/lfpw/annotations/trainset', 'png');
1313
%mkdir Data;
1414
save('Data/train_init.mat', 'data');
1515
end
@@ -32,7 +32,7 @@ function ESR_Train()
3232
end
3333
%% augment the data
3434
Data = augmtdata(Data, params);
35-
Data = Data(1:10); % test
35+
%Data = Data(1:10); % test
3636

3737
params.N_img = size(Data, 1);
3838
params.k = params.k*dist_pupils_ms;
@@ -94,7 +94,7 @@ function ESR_Train()
9494
fprintf('Mean Root Square Error in %d iteration is %f\n', t, Error(t+1));
9595
Model{t}.fernCascade = fernCascade;
9696
end
97-
save('../../Data/Model.mat', 'Model');
97+
save('Data/Model.mat', 'Model');
9898
bar(Error);
9999
end
100100

Test_params.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
params.K = 50; % default = 500, the number of fern on the internal-level boosted regression
55
params.k = [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3];
66
% the local scale of search, it set 0.3 times of the distance between two pupils on the mean shape
7-
params.N_init = 5; % initial number
87
params.F = 5; % the number of features in fern
98

10-
load('../../Data/mean_shape.mat', 'S0');
11-
params.mean_shape = S0;
9+
params.N_init = 5; % initial number
10+
%params.N_aug = 1;
1211

13-
params.N_fp = size(params.mean_shape, 1);
12+
params.N_fp = 0;% size(params.mean_shape, 1);
1413
params.N_img = 0;
1514

16-
params.k = params.k*pdist([mean([params.mean_shape(20, :); params.mean_shape(23, :)]);...
17-
mean([params.mean_shape(26, :); params.mean_shape(29, :)])])/2;
15+
params.ind_usedpts = 18:68;
16+
% params.k = params.k*pdist([mean([params.mean_shape(20, :); params.mean_shape(23, :)]);...
17+
% mean([params.mean_shape(26, :); params.mean_shape(29, :)])])/2;
1818
end

Train_params.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
function params = Train_params()
22
params.T = 10; % the iteration stages
3-
params.P = 40; % default = 400, the pixel number sampled on the images
4-
params.K = 50; % default = 500, the number of fern on the internal-level boosted regression
3+
params.P = 400; % default = 400, the pixel number sampled on the images
4+
params.K = 500; % default = 500, the number of fern on the internal-level boosted regression
55
params.k = [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3];
66
% the local scale of search, it set 0.3 times of the distance between two pupils on the mean shape
77
params.F = 5; % the number of features in fern
88

9-
%params.mean_shape = S0;
10-
119
params.N_aug = 20;
1210

1311
params.N_fp = 0; %size(params.mean_shape, 1);

augmtdata.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
for j = 1: params.N_aug
1414
r_index = rand_index_(j);
1515
% copy the original stuff
16-
data_index = (j-1)*data_len + i;
16+
data_index = (i-1)*params.N_aug + j;
1717
data_aug{data_index}.img_gray = data{i}.img_gray;
1818
data_aug{data_index}.width_orig = data{i}.width_orig;
1919
data_aug{data_index}.height_orig = data{i}.height_orig;

initialTest.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function [CShapes]= initialTest(image, bbx, train_bbx, train_pts, params)
2-
N_train_img = size(train_pts, 1);
1+
function CShapes = initialTest(data, initSet, params)
2+
N_train_img = size(initSet, 1);
33
Index_init = randperm(N_train_img, params.N_init);
44

55
% Images = cell(params.N_init, 1);
@@ -10,10 +10,12 @@
1010

1111
% Images{i} = image;
1212
% Bbxes{i} = bbx;
13-
current_shape = train_pts{Index_init(i)}.pts_chs;
14-
current_bbx = train_bbx{Index_init(i)}.bbx_chs;
15-
current_shape = projectShape(current_shape, current_bbx);
16-
CShapes(:, :, i) = reprojectShape(current_shape, bbx.bbx_chs);
13+
current_shape = initSet{Index_init(i)}.shape_gt(params.ind_usedpts,:);
14+
current_bbx = data.bbox_gt;
15+
temp = resetshape(current_bbx, current_shape);
16+
CShapes(:, :, i) = temp;
17+
% current_shape = projectShape(current_shape, current_bbx);
18+
% CShapes(:, :, i) = reprojectShape(current_shape, bbx.bbx_chs);
1719

1820
% figure
1921
% currentshape = CShapes(:, :, i);

resetshape.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [shape_initial] = resetshape(bbox, shape_union)
1+
function shape_initial = resetshape(bbox, shape_union)
22
%RESETSHAPE Summary of this function goes here
33
% Function: reset the initial shape according to the groundtruth shape and union shape for all faces
44
% Detailed explanation goes here

0 commit comments

Comments
 (0)