open source pkg v1

This commit is contained in:
Vijay Yadev
2020-08-04 19:12:31 -04:00
parent bef213dba9
commit c389fc2c47
3708 changed files with 1624220 additions and 1 deletions

View File

@@ -0,0 +1,97 @@
clear
curr_dir = cd('.');
database_root = ['D:\Datasets\Columbia Gaze Data Set\'];
p_dirs = dir([database_root, '0*']);
output = './columbia_out/';
%% Perform actual gaze predictions
command = sprintf('"../../Release/FaceTrackingImg.exe" -fx 19720 -fy 19720 -gaze ');
parfor p=1:numel(p_dirs)
input_loc = ['-fdir "', [database_root, p_dirs(p).name], '" '];
out_img_loc = ['-oidir "', [output, p_dirs(p).name], '" '];
out_p_loc = ['-opdir "', [output, p_dirs(p).name], '" '];
command_c = cat(2, command, input_loc, out_img_loc, out_p_loc);
command_c = cat(2, command_c, ' -clmwild -multi_view 1');
dos(command_c);
end
%% Perform the evaluation (this needs to be changed)
errors_l = [];
errors_r = [];
all_gaze_pred = [];
all_gaze_gt = [];
angle_errs = [];
angle_errs_naive = [];
frontal_faces = [];
% It's approximate as the actual eye gaze is approximate
for p=1:numel(p_dirs)
out_files = dir([output, p_dirs(p).name, '/*.pose']);
for i=1:numel(out_files)
out_file = [output, p_dirs(p).name, '/', out_files(i).name];
A = dlmread(out_file, ' ', 'A79..F79');
g_0 = A(1:3);
g_1 = A(4:6);
g_0 = (g_0 + g_1) / 2;
g_0 = g_0 ./ norm(g_0);
g_1 = g_0;
all_gaze_pred = cat(1, all_gaze_pred, g_0);
all_gaze_pred = cat(1, all_gaze_pred, g_1);
tokens = strsplit(out_files(i).name, '_');
gaze_v_gt = str2double(tokens{4}(1:end-1)) * pi/180;
gaze_h_gt = str2double(tokens{5}(1:end-1)) * pi/180;
person_h_gt = str2double(tokens{3}(1:end-1)) * pi/180;
if(person_h_gt == 0)
frontal_faces = cat(1, frontal_faces, [1;1]);
else
frontal_faces = cat(1, frontal_faces, [0;0]);
end
p_target_x = tan(gaze_h_gt) * 2500;
cam_dist = sqrt(2500^2 + p_target_x^2);
gaze_target_x = tan(gaze_h_gt) * cam_dist;
gaze_target_y = -tan(gaze_v_gt) * cam_dist;
gaze_gt_1 = [gaze_target_x, gaze_target_y, 0] - [0,0,cam_dist];
gaze_gt_1 = gaze_gt_1 ./ norm(gaze_gt_1);
gaze_gt_2 = [gaze_target_x, gaze_target_y, 0] - [0,0,cam_dist];
gaze_gt_2 = gaze_gt_2 ./ norm(gaze_gt_2);
all_gaze_gt = cat(1, all_gaze_gt, gaze_gt_1);
all_gaze_gt = cat(1, all_gaze_gt, gaze_gt_2);
% Gaze gt needs to be rotated based on person location
angle_err_1 = acos(gaze_gt_1 * g_0') * 180/pi;
angle_err_2 = acos(gaze_gt_2 * g_1') * 180/pi;
angle_errs = cat(1, angle_errs, angle_err_1);
angle_errs = cat(1, angle_errs, angle_err_2);
angle_errs_n_1 = acos(gaze_gt_1 * [0;0;-1]) * 180/pi;
angle_errs_n_2 = acos(gaze_gt_2 * [0;0;-1]) * 180/pi;
angle_errs_naive = cat(1, angle_errs_naive, angle_errs_n_1);
angle_errs_naive = cat(1, angle_errs_naive, angle_errs_n_2);
end
end

View File

@@ -0,0 +1,114 @@
clear
curr_dir = cd('.');
% Replace this with your downloaded 300-W train data
if(exist([getenv('USERPROFILE') '/Dropbox/AAM/eye_clm/mpii_data/'], 'file'))
database_root = [getenv('USERPROFILE') '/Dropbox/AAM/eye_clm/mpii_data/'];
elseif(exist('D:\Dropbox/Dropbox/AAM/eye_clm/mpii_data/', 'file'))
database_root = 'D:\Dropbox/Dropbox/AAM/eye_clm/mpii_data/';
elseif(exist('F:\Dropbox/AAM/eye_clm/mpii_data/', 'file'))
database_root = 'F:\Dropbox/AAM/eye_clm/mpii_data/';
elseif(exist('/multicomp/datasets/mpii_gaze/mpii_data/', 'file'))
database_root = '/multicomp/datasets/mpii_gaze/mpii_data/';
elseif(exist('/media/tadas/5E08AE0D08ADE3ED/Dropbox/AAM/eye_clm/mpii_data/', 'file'))
database_root = '/media/tadas/5E08AE0D08ADE3ED/Dropbox/AAM/eye_clm/mpii_data/';
else
fprintf('MPII gaze dataset not found\n');
end
output = './mpii_out/';
%% Perform actual gaze predictions
if(isunix)
executable = '"../../build/bin/FaceLandmarkImg"';
else
executable = '"../../x64/Release/FaceLandmarkImg.exe"';
end
command = sprintf('%s -fx 1028 -fy 1028 ', executable);
p_dirs = dir([database_root, 'p*']);
parfor p=1:numel(p_dirs)
tic
input_loc = ['-gaze -fdir "', [database_root, p_dirs(p).name], '" '];
out_img_loc = ['-out_dir "', [output, p_dirs(p).name], '" '];
command_c = cat(2, command, input_loc, out_img_loc);
if(isunix)
unix(command_c, '-echo');
else
dos(command_c);
end
end
%%
% Extract the results
predictions_l = zeros(750, 3);
predictions_r = zeros(750, 3);
gt_l = zeros(750, 3);
gt_r = zeros(750, 3);
angle_err_l = zeros(750,1);
angle_err_r = zeros(750,1);
p_dirs = dir([database_root, 'p*']);
curr = 1;
for p=1:numel(p_dirs)
load([database_root, p_dirs(p).name, '/Data.mat']);
for i=1:size(filenames, 1)
fname = sprintf('%s/%s/%d_%d_%d_%d_%d_%d_%d.csv', output, p_dirs(p).name,...
filenames(i,1), filenames(i,2), filenames(i,3), filenames(i,4),...
filenames(i,5), filenames(i,6), filenames(i,7));
if(p==1 && i==1)
% First read in the column names
tab = readtable(fname);
column_names = tab.Properties.VariableNames;
gaze_0_ids = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'gaze_0_'));
gaze_1_ids = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'gaze_1_'));
end
if(exist(fname, 'file'))
all_params = dlmread(fname, ',', 1, 0);
else
all_params = [];
end
% If there was a face detected
if(size(all_params,1)>0)
predictions_r(curr,:) = all_params(1,gaze_0_ids);
predictions_l(curr,:) = all_params(1,gaze_1_ids);
else
predictions_r(curr,:) = [0,0,-1];
predictions_l(curr,:) = [0,0,-1];
end
head_rot = headpose(i,1:3);
gt_r(curr,:) = data.right.gaze(i,:)';
gt_r(curr,:) = gt_r(curr,:) / norm(gt_r(curr,:));
gt_l(curr,:) = data.left.gaze(i,:)';
gt_l(curr,:) = gt_l(curr,:) / norm(gt_l(curr,:));
angle_err_l(curr) = acos(predictions_l(curr,:) * gt_l(curr,:)') * 180/pi;
angle_err_r(curr) = acos(predictions_r(curr,:) * gt_r(curr,:)') * 180/pi;
curr = curr + 1;
end
end
all_errors = cat(1, angle_err_l, angle_err_r);
mean_error = mean(all_errors);
median_error = median(all_errors);
save('mpii_1500_errs.mat', 'all_errors', 'mean_error', 'median_error');
f = fopen('mpii_1500_errs.txt', 'w');
fprintf(f, 'Mean error, median error\n');
fprintf(f, '%.3f, %.3f\n', mean_error, median_error);
fclose(f);

View File

@@ -0,0 +1,2 @@
Mean error, median error
9.072, 8.454