2016-06-14 21:55:16 +00:00
|
|
|
% Perform static model prediction using images
|
|
|
|
|
|
|
|
clear
|
|
|
|
|
|
|
|
addpath('./helpers');
|
|
|
|
|
|
|
|
find_Bosphorus;
|
|
|
|
out_loc = './out_bosph/';
|
|
|
|
|
|
|
|
%%
|
2017-12-18 12:17:53 +00:00
|
|
|
if(isunix)
|
|
|
|
executable = '"../../build/bin/FeatureExtraction"';
|
|
|
|
else
|
|
|
|
executable = '"../../x64/Release/FeatureExtraction.exe"';
|
|
|
|
end
|
2016-06-14 21:55:16 +00: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];
|
2017-12-06 15:43:55 +00:00
|
|
|
command = cat(2, command, [' -fdir "' input_dir '" -out_dir "' out_loc '"']);
|
|
|
|
command = cat(2, command, ' -multi_view 1 -wild -aus ');
|
2016-06-14 21:55:16 +00:00
|
|
|
|
2017-12-18 12:17:53 +00:00
|
|
|
if(isunix)
|
|
|
|
unix(command, '-echo')
|
|
|
|
else
|
|
|
|
dos(command);
|
|
|
|
end
|
2016-06-14 21:55:16 +00: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
|
|
|
|
|
2017-12-06 15:43:55 +00:00
|
|
|
% 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 21:55:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
%%
|
|
|
|
labels_pred = zeros(size(labels_gt));
|
|
|
|
for i=1:numel(filenames)
|
|
|
|
|
|
|
|
% Will need to read the relevant AUs only
|
2017-12-06 15:43:55 +00:00
|
|
|
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 21:55:16 +00:00
|
|
|
end
|
|
|
|
end
|
2017-12-06 15:43:55 +00:00
|
|
|
|
2016-06-14 21:55:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
%%
|
2016-07-22 13:35:50 +00:00
|
|
|
f = fopen('results/Bosphorus_res_class.txt', 'w');
|
2016-06-14 21:55:16 +00:00
|
|
|
labels_gt_bin = labels_gt;
|
|
|
|
labels_gt_bin(labels_gt_bin > 1) = 1;
|
2017-10-23 19:59:54 +00:00
|
|
|
f1s_class = zeros(1, numel(aus_Bosph));
|
2016-06-14 21:55:16 +00: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 19:59:54 +00:00
|
|
|
f1s_class(au) = f1;
|
2016-06-14 21:55:16 +00: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
|
|
|
|
|
2017-12-06 15:43:55 +00:00
|
|
|
% 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 21:55:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
%%
|
|
|
|
labels_pred = zeros(size(labels_gt));
|
|
|
|
for i=1:numel(filenames)
|
|
|
|
|
|
|
|
% Will need to read the relevant AUs only
|
2017-12-06 15:43:55 +00:00
|
|
|
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 21:55:16 +00:00
|
|
|
end
|
|
|
|
end
|
2017-12-06 15:43:55 +00:00
|
|
|
|
2016-06-14 21:55:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
%%
|
2016-07-22 13:35:50 +00:00
|
|
|
f = fopen('results/Bosphorus_res_int.txt', 'w');
|
2017-10-23 19:59:54 +00:00
|
|
|
cccs_reg = zeros(1, numel(aus_Bosph));
|
2016-06-14 21:55:16 +00:00
|
|
|
for au = 1:numel(aus_Bosph)
|
|
|
|
|
2016-07-22 13:35:50 +00:00
|
|
|
[ ~, ~, corrs, ccc, rms, ~ ] = evaluate_regression_results( labels_pred(:, au), labels_gt(:, au));
|
|
|
|
|
2017-10-23 19:59:54 +00:00
|
|
|
cccs_reg(au) = ccc;
|
|
|
|
|
2016-07-22 13:35:50 +00:00
|
|
|
fprintf(f, 'AU%d intensity, Corr - %.3f, RMS - %.3f, CCC - %.3f\n', aus_Bosph(au), corrs, rms, ccc);
|
2016-06-14 21:55:16 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
fclose(f);
|