sustaining_gazes/matlab_runners/Action Unit Experiments/run_AU_prediction_Bosphorus.m

137 lines
3.6 KiB
Mathematica
Raw Normal View History

2016-06-14 23:55:16 +02:00
% Perform static model prediction using images
clear
addpath('./helpers');
find_Bosphorus;
out_loc = './out_bosph/';
%%
if(isunix)
2017-12-20 08:08:14 +01:00
executable = '"../../build/bin/FaceLandmarkImg"';
else
2017-12-20 08:08:14 +01:00
executable = '"../../x64/Release/FaceLandmarkImg.exe"';
end
2016-06-14 23:55:16 +02:00
bosph_dirs = dir([Bosphorus_dir, '/BosphorusDB/BosphorusDB/bs*']);
%%
parfor f1=1:numel(bosph_dirs)
command = executable;
input_dir = [Bosphorus_dir, '/BosphorusDB/BosphorusDB/', bosph_dirs(f1).name];
command = cat(2, command, [' -fdir "' input_dir '" -out_dir "' out_loc '"']);
command = cat(2, command, ' -multi_view 1 -wild -aus ');
2016-06-14 23:55:16 +02:00
if(isunix)
unix(command, '-echo')
else
dos(command);
end
2016-06-14 23:55:16 +02:00
end
%%
aus_Bosph = [1, 2, 4, 5, 6, 7, 9, 10, 12, 14, 15, 17, 20, 23, 25, 26, 45];
[ labels_gt, valid_ids, filenames] = extract_Bosphorus_labels(Bosphorus_dir, all_recs, aus_Bosph);
%% Read the predicted values
% First read the first file to get the column ids
tab = readtable([out_loc, filenames{1}, '.csv']);
column_names = tab.Properties.VariableNames;
aus_det_id = cellfun(@(x) ~isempty(x) && x==5, strfind(column_names, '_c'));
aus_det_cell = column_names(aus_det_id);
aus_det = zeros(size(aus_det_cell));
for i=1:numel(aus_det)
aus_det(i) = str2num(aus_det_cell{i}(3:4));
2016-06-14 23:55:16 +02:00
end
%%
labels_pred = zeros(size(labels_gt));
for i=1:numel(filenames)
% Will need to read the relevant AUs only
all_params = dlmread([out_loc, filenames{i}, '.csv'], ',', 1, 0);
% if multiple faces detected just take the first row
aus_pred = all_params(1, aus_det_id);
for k=1:numel(aus_det)
if(sum(aus_Bosph == aus_det(k))>0)
labels_pred(i, aus_Bosph == aus_det(k)) = aus_pred(k);
2016-06-14 23:55:16 +02:00
end
end
2016-06-14 23:55:16 +02:00
end
%%
f = fopen('results/Bosphorus_res_class.txt', 'w');
2016-06-14 23:55:16 +02:00
labels_gt_bin = labels_gt;
labels_gt_bin(labels_gt_bin > 1) = 1;
2017-10-23 21:59:54 +02:00
f1s_class = zeros(1, numel(aus_Bosph));
2016-06-14 23:55:16 +02:00
for au = 1:numel(aus_Bosph)
tp = sum(labels_gt_bin(:,au) == 1 & labels_pred(:, au) == 1);
fp = sum(labels_gt_bin(:,au) == 0 & labels_pred(:, au) == 1);
fn = sum(labels_gt_bin(:,au) == 1 & labels_pred(:, au) == 0);
tn = sum(labels_gt_bin(:,au) == 0 & labels_pred(:, au) == 0);
precision = tp./(tp+fp);
recall = tp./(tp+fn);
f1 = 2 * precision .* recall ./ (precision + recall);
2017-10-23 21:59:54 +02:00
f1s_class(au) = f1;
2016-06-14 23:55:16 +02:00
fprintf(f, 'AU%d class, Precision - %.3f, Recall - %.3f, F1 - %.3f\n', aus_Bosph(au), precision, recall, f1);
end
fclose(f);
%% Read the predicted values for intensities
% First read the first file to get the column ids
tab = readtable([out_loc, filenames{1}, '.csv']);
column_names = tab.Properties.VariableNames;
aus_det_id = cellfun(@(x) ~isempty(x) && x==5, strfind(column_names, '_r'));
aus_det_cell = column_names(aus_det_id);
aus_det = zeros(size(aus_det_cell));
for i=1:numel(aus_det)
aus_det(i) = str2num(aus_det_cell{i}(3:4));
2016-06-14 23:55:16 +02:00
end
%%
labels_pred = zeros(size(labels_gt));
for i=1:numel(filenames)
% Will need to read the relevant AUs only
all_params = dlmread([out_loc, filenames{i}, '.csv'], ',', 1, 0);
% if multiple faces detected just take the first row
aus_pred = all_params(1, aus_det_id);
for k=1:numel(aus_det)
if(sum(aus_Bosph == aus_det(k))>0)
labels_pred(i, aus_Bosph == aus_det(k)) = aus_pred(k);
2016-06-14 23:55:16 +02:00
end
end
2016-06-14 23:55:16 +02:00
end
%%
f = fopen('results/Bosphorus_res_int.txt', 'w');
2017-10-23 21:59:54 +02:00
cccs_reg = zeros(1, numel(aus_Bosph));
2016-06-14 23:55:16 +02:00
for au = 1:numel(aus_Bosph)
[ ~, ~, corrs, ccc, rms, ~ ] = evaluate_regression_results( labels_pred(:, au), labels_gt(:, au));
2017-10-23 21:59:54 +02:00
cccs_reg(au) = ccc;
fprintf(f, 'AU%d intensity, Corr - %.3f, RMS - %.3f, CCC - %.3f\n', aus_Bosph(au), corrs, rms, ccc);
2016-06-14 23:55:16 +02:00
end
fclose(f);