Adapting training scripts to new output format (Bosphorus and BP4D).

This commit is contained in:
Tadas Baltrusaitis 2018-02-12 20:16:26 +00:00
parent 89d9647a85
commit 83d8697bcd
23 changed files with 243 additions and 125 deletions

View file

@ -9,10 +9,11 @@ end
find_FERA2011; find_FERA2011;
output_dir = 'E:\datasets\face_datasets_processed\fera2011'; output_dir = 'E:\datasets\face_datasets_processed\fera2011';
FERA2011_dir = [FERA2011_dir, '/../'];
% Go two levels deep % Go two levels deep
fera_dirs = dir([FERA2011_dir, '/train*']); fera_dirs = dir([FERA2011_dir, '*']);
fera_dirs = fera_dirs(3:end);
parfor f1=1:numel(fera_dirs) parfor f1=1:numel(fera_dirs)
fera_dirs_level_2 = dir([FERA2011_dir, fera_dirs(f1).name]); fera_dirs_level_2 = dir([FERA2011_dir, fera_dirs(f1).name]);

View file

@ -10,7 +10,7 @@ find_SEMAINE;
% Go two levels deep % Go two levels deep
semaine_dirs = train_recs; semaine_dirs = train_recs;
output_dir = 'E:\datasets\face_datasets_processed\semaine'; output_dir = 'E:\datasets\face_datasets_processed\semaine\train';
parfor f1=1:numel(semaine_dirs) parfor f1=1:numel(semaine_dirs)
@ -33,7 +33,7 @@ end
%% %%
semaine_dirs = devel_recs; semaine_dirs = devel_recs;
out_loc = [SEMAINE_dir, '../processed_data/devel/']; output_dir = 'E:\datasets\face_datasets_processed\semaine\devel';
parfor f1=1:numel(semaine_dirs) parfor f1=1:numel(semaine_dirs)

View file

@ -6,7 +6,7 @@ else
fprintf('Bosphorus dataset location not found (or not defined)\n'); fprintf('Bosphorus dataset location not found (or not defined)\n');
end end
hog_data_dir = ['D:\Datasets\face_datasets']; hog_data_dir = ['E:\Datasets\face_datasets_processed\bosph'];
all_recs = dir([Bosphorus_dir, '/BosphorusDB/BosphorusDB/bs*']); all_recs = dir([Bosphorus_dir, '/BosphorusDB/BosphorusDB/bs*']);
all_recs_mat = cat(1, all_recs.name); all_recs_mat = cat(1, all_recs.name);

View file

@ -1,5 +1,5 @@
function [data_train, labels_train, data_devel, labels_devel, raw_devel, PC, means_norm, stds_norm, valid_ids_test] = ... function [data_train, labels_train, data_devel, labels_devel, raw_devel, PC, means_norm, stds_norm, valid_ids_test] = ...
Prepare_HOG_AU_data_generic(train_users, devel_users, au_train, bp4d_dir, hog_data_dir, pca_file) Prepare_HOG_AU_data_generic(train_users, devel_users, au_train, bp4d_dir, features_dir)
%% %%
addpath(genpath('../../data extraction/')); addpath(genpath('../../data extraction/'));
@ -11,9 +11,9 @@ labels_other = cat(1, labels_other{:});
% First extracting the labels % First extracting the labels
[ labels_train, valid_ids_train, vid_ids_train ] = extract_BP4D_labels(bp4d_dir, train_users, au_train); [ labels_train, valid_ids_train, vid_ids_train ] = extract_BP4D_labels(bp4d_dir, train_users, au_train);
train_geom_data = Read_geom_files(train_users, hog_data_dir); train_geom_data = Read_geom_files(train_users, features_dir);
% Reading in the HOG data (of only relevant frames) % Reading in the HOG data (of only relevant frames)
[train_appearance_data, valid_ids_train_hog, vid_ids_train_string] = Read_HOG_files(train_users, hog_data_dir); [train_appearance_data, valid_ids_train_hog, vid_ids_train_string] = Read_HOG_files(train_users, features_dir);
train_appearance_data = cat(2, train_appearance_data, train_geom_data); train_appearance_data = cat(2, train_appearance_data, train_geom_data);
% Subsample the data to make training quicker % Subsample the data to make training quicker
@ -67,8 +67,8 @@ vid_ids_train_string = vid_ids_train_string(reduced_inds,:);
[ labels_devel, valid_ids_devel, vid_ids_devel ] = extract_BP4D_labels(bp4d_dir, devel_users, au_train); [ labels_devel, valid_ids_devel, vid_ids_devel ] = extract_BP4D_labels(bp4d_dir, devel_users, au_train);
% Reading in the HOG data (of only relevant frames) % Reading in the HOG data (of only relevant frames)
devel_geom_data = Read_geom_files(devel_users, hog_data_dir); devel_geom_data = Read_geom_files(devel_users, features_dir);
[devel_appearance_data, valid_ids_devel_hog, vid_ids_devel_string] = Read_HOG_files(devel_users, hog_data_dir); [devel_appearance_data, valid_ids_devel_hog, vid_ids_devel_string] = Read_HOG_files(devel_users, features_dir);
devel_appearance_data = cat(2, devel_appearance_data, devel_geom_data); devel_appearance_data = cat(2, devel_appearance_data, devel_geom_data);
labels_devel = cat(1, labels_devel{:}); labels_devel = cat(1, labels_devel{:});

View file

@ -1,5 +1,5 @@
function [data_train, labels_train, vid_ids_train_string, data_devel, labels_devel, vid_ids_devel_string, raw_devel, PC, means_norm, stds_norm, success_devel] = ... function [data_train, labels_train, vid_ids_train_string, data_devel, labels_devel, vid_ids_devel_string, raw_devel, PC, means_norm, stds_norm, success_devel] = ...
Prepare_HOG_AU_data_generic_intensity(train_users, devel_users, au_train, bp4d_dir, hog_data_dir) Prepare_HOG_AU_data_generic_intensity(train_users, devel_users, au_train, bp4d_dir, features_dir)
%% %%
addpath(genpath('../data extraction/')); addpath(genpath('../data extraction/'));
@ -10,10 +10,10 @@ au_other = setdiff([6, 10, 12, 14, 17], au_train);
[ labels_other, ~, ~ ] = extract_BP4D_labels_intensity(bp4d_dir, train_users, au_other); [ labels_other, ~, ~ ] = extract_BP4D_labels_intensity(bp4d_dir, train_users, au_other);
labels_other = cat(1, labels_other{:}); labels_other = cat(1, labels_other{:});
train_geom_data = Read_geom_files(train_users, hog_data_dir); train_geom_data = Read_geom_files(train_users, features_dir);
% Reading in the HOG data (of only relevant frames) % Reading in the HOG data (of only relevant frames)
[train_appearance_data, valid_ids_train_hog, vid_ids_train_string] = Read_HOG_files(train_users, hog_data_dir); [train_appearance_data, valid_ids_train_hog, vid_ids_train_string] = Read_HOG_files(train_users, features_dir);
train_appearance_data = cat(2, train_appearance_data, train_geom_data); train_appearance_data = cat(2, train_appearance_data, train_geom_data);
% Subsample the data to make training quicker % Subsample the data to make training quicker
@ -65,9 +65,9 @@ end
% First extracting the labels % First extracting the labels
[ labels_devel, valid_ids_devel, vid_ids_devel ] = extract_BP4D_labels_intensity(bp4d_dir, devel_users, au_train); [ labels_devel, valid_ids_devel, vid_ids_devel ] = extract_BP4D_labels_intensity(bp4d_dir, devel_users, au_train);
devel_geom_data = Read_geom_files(devel_users, hog_data_dir); devel_geom_data = Read_geom_files(devel_users, features_dir);
% Reading in the HOG data (of only relevant frames) % Reading in the HOG data (of only relevant frames)
[devel_appearance_data, valid_ids_devel_hog, vid_ids_devel_string] = Read_HOG_files(devel_users, hog_data_dir); [devel_appearance_data, valid_ids_devel_hog, vid_ids_devel_string] = Read_HOG_files(devel_users, features_dir);
devel_appearance_data = cat(2, devel_appearance_data, devel_geom_data); devel_appearance_data = cat(2, devel_appearance_data, devel_geom_data);
valid_ids_devel = logical(cat(1, valid_ids_devel{:})); valid_ids_devel = logical(cat(1, valid_ids_devel{:}));

View file

@ -1,5 +1,5 @@
function [data_train, labels_train, vid_ids_train_string, data_devel, labels_devel, vid_ids_devel_string, raw_devel, PC, means_norm, stds_norm, success_devel] = ... function [data_train, labels_train, vid_ids_train_string, data_devel, labels_devel, vid_ids_devel_string, raw_devel, PC, means_norm, stds_norm, success_devel] = ...
Prepare_HOG_AU_data_generic_intensity_dynamic(train_users, devel_users, au_train, bp4d_dir, hog_data_dir) Prepare_HOG_AU_data_generic_intensity_dynamic(train_users, devel_users, au_train, bp4d_dir, features_dir)
%% %%
addpath(genpath('../data extraction/')); addpath(genpath('../data extraction/'));
@ -10,10 +10,10 @@ au_other = setdiff([6, 10, 12, 14, 17], au_train);
[ labels_other, ~, ~ ] = extract_BP4D_labels_intensity(bp4d_dir, train_users, au_other); [ labels_other, ~, ~ ] = extract_BP4D_labels_intensity(bp4d_dir, train_users, au_other);
labels_other = cat(1, labels_other{:}); labels_other = cat(1, labels_other{:});
train_geom_data = Read_geom_files_dynamic(train_users, hog_data_dir); train_geom_data = Read_geom_files_dynamic(train_users, features_dir);
% Reading in the HOG data (of only relevant frames) % Reading in the HOG data (of only relevant frames)
[train_appearance_data, valid_ids_train_hog, vid_ids_train_string] = Read_HOG_files_dynamic_pp(train_users, hog_data_dir); [train_appearance_data, valid_ids_train_hog, vid_ids_train_string] = Read_HOG_files_dynamic_pp(train_users, features_dir);
train_appearance_data = cat(2, train_appearance_data, train_geom_data); train_appearance_data = cat(2, train_appearance_data, train_geom_data);
% Subsample the data to make training quicker % Subsample the data to make training quicker
@ -65,9 +65,9 @@ end
% First extracting the labels % First extracting the labels
[ labels_devel, valid_ids_devel, vid_ids_devel ] = extract_BP4D_labels_intensity(bp4d_dir, devel_users, au_train); [ labels_devel, valid_ids_devel, vid_ids_devel ] = extract_BP4D_labels_intensity(bp4d_dir, devel_users, au_train);
devel_geom_data = Read_geom_files_dynamic(devel_users, hog_data_dir); devel_geom_data = Read_geom_files_dynamic(devel_users, features_dir);
% Reading in the HOG data (of only relevant frames) % Reading in the HOG data (of only relevant frames)
[devel_appearance_data, valid_ids_devel_hog, vid_ids_devel_string] = Read_HOG_files_dynamic_pp(devel_users, hog_data_dir); [devel_appearance_data, valid_ids_devel_hog, vid_ids_devel_string] = Read_HOG_files_dynamic_pp(devel_users, features_dir);
devel_appearance_data = cat(2, devel_appearance_data, devel_geom_data); devel_appearance_data = cat(2, devel_appearance_data, devel_geom_data);
valid_ids_devel = logical(cat(1, valid_ids_devel{:})); valid_ids_devel = logical(cat(1, valid_ids_devel{:}));

View file

@ -7,10 +7,10 @@ function [geom_data, valid_ids] = Read_geom_files(users, hog_data_dir)
for i=1:numel(users) for i=1:numel(users)
geom_files = dir([hog_data_dir, '/train/', users{i} '*.params.txt']); geom_files = dir([hog_data_dir, '/train/', users{i} '*.csv']);
geom_dir = [hog_data_dir, '/train/']; geom_dir = [hog_data_dir, '/train/'];
if(isempty(geom_files)) if(isempty(geom_files))
geom_files = dir([hog_data_dir, '/devel/', users{i} '*.params.txt']); geom_files = dir([hog_data_dir, '/devel/', users{i} '*.csv']);
geom_dir = [hog_data_dir, '/devel/']; geom_dir = [hog_data_dir, '/devel/'];
end end
@ -20,15 +20,26 @@ function [geom_data, valid_ids] = Read_geom_files(users, hog_data_dir)
m_file = [geom_dir, '/' nm '.params.mat']; m_file = [geom_dir, '/' nm '.params.mat'];
if(~exist(m_file, 'file')) if(~exist(m_file, 'file'))
if(i == 1)
tab = readtable(geom_file);
column_names = tab.Properties.VariableNames;
valid_ind = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'valid'));
shape_inds = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'p_'));
end
res = dlmread(geom_file, ',', 1, 0); res = dlmread(geom_file, ',', 1, 0);
save(m_file, 'res');
valid = res(:, valid_ind) > 0.7;
res = res(:, shape_inds);
% Do not consider global parameters
res = res(:, 7:end);
save(m_file, 'res', 'valid');
else else
load(m_file); load(m_file);
end end
valid = res(:, 4);
res = res(:, 11:end);
actual_locs = res * V'; actual_locs = res * V';
res = cat(2, actual_locs, res); res = cat(2, actual_locs, res);

View file

@ -7,10 +7,10 @@ function [geom_data, valid_ids] = Read_geom_files_dynamic(users, hog_data_dir)
for i=1:numel(users) for i=1:numel(users)
geom_files = dir([hog_data_dir, '/train/', users{i} '*.params.txt']); geom_files = dir([hog_data_dir, '/train/', users{i} '*.csv']);
geom_dir = [hog_data_dir, '/train/']; geom_dir = [hog_data_dir, '/train/'];
if(isempty(geom_files)) if(isempty(geom_files))
geom_files = dir([hog_data_dir, '/devel/', users{i} '*.params.txt']); geom_files = dir([hog_data_dir, '/devel/', users{i} '*.csv']);
geom_dir = [hog_data_dir, '/devel/']; geom_dir = [hog_data_dir, '/devel/'];
end end
@ -22,15 +22,26 @@ function [geom_data, valid_ids] = Read_geom_files_dynamic(users, hog_data_dir)
m_file = [geom_dir, '/' nm '.params.mat']; m_file = [geom_dir, '/' nm '.params.mat'];
if(~exist(m_file, 'file')) if(~exist(m_file, 'file'))
if(i == 1)
tab = readtable(geom_file);
column_names = tab.Properties.VariableNames;
valid_ind = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'valid'));
shape_inds = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'p_'));
end
res = dlmread(geom_file, ',', 1, 0); res = dlmread(geom_file, ',', 1, 0);
save(m_file, 'res');
valid = res(:, valid_ind) > 0.7;
res = res(:, shape_inds);
% Do not consider global parameters
res = res(:, 7:end);
save(m_file, 'res', 'valid');
else else
load(m_file); load(m_file);
end end
valid = res(:, 4);
res = res(:, 11:end);
actual_locs = res * V'; actual_locs = res * V';
res = cat(2, actual_locs, res); res = cat(2, actual_locs, res);

View file

@ -32,7 +32,7 @@ for a=1:numel(aus)
rest_aus = setdiff(all_aus, au); rest_aus = setdiff(all_aus, au);
% load the training and testing data for the current fold % load the training and testing data for the current fold
[train_samples, train_labels, valid_samples, valid_labels, ~, PC, means, scaling] = Prepare_HOG_AU_data_generic_dynamic(train_recs, devel_recs, au, BP4D_dir, hog_data_dir_BP4D, pca_loc); [train_samples, train_labels, valid_samples, valid_labels, ~, PC, means, scaling] = Prepare_HOG_AU_data_generic_dynamic(train_recs, devel_recs, au, BP4D_dir, hog_data_dir_BP4D);
train_samples = sparse(train_samples); train_samples = sparse(train_samples);
valid_samples = sparse(valid_samples); valid_samples = sparse(valid_samples);

View file

@ -32,7 +32,7 @@ for a=1:numel(aus)
rest_aus = setdiff(all_aus, au); rest_aus = setdiff(all_aus, au);
% load the training and testing data for the current fold % load the training and testing data for the current fold
[train_samples, train_labels, valid_samples, valid_labels, ~, PC, means, scaling] = Prepare_HOG_AU_data_generic(train_recs, devel_recs, au, BP4D_dir, hog_data_dir_BP4D, pca_loc); [train_samples, train_labels, valid_samples, valid_labels, ~, PC, means, scaling] = Prepare_HOG_AU_data_generic(train_recs, devel_recs, au, BP4D_dir, hog_data_dir_BP4D);
train_samples = sparse(train_samples); train_samples = sparse(train_samples);
valid_samples = sparse(valid_samples); valid_samples = sparse(valid_samples);

View file

@ -35,7 +35,7 @@ for a=1:numel(aus)
rest_aus = setdiff(all_aus, au); rest_aus = setdiff(all_aus, au);
% load the training and testing data for the current fold % load the training and testing data for the current fold
[train_samples, train_labels, ~, valid_samples, valid_labels, vid_ids_devel, ~, PC, means, scaling, success_devel] = Prepare_HOG_AU_data_generic_intensity(train_recs, devel_recs, au, BP4D_dir_int, hog_data_dir_BP4D, pca_loc); [train_samples, train_labels, ~, valid_samples, valid_labels, vid_ids_devel, ~, PC, means, scaling, success_devel] = Prepare_HOG_AU_data_generic_intensity(train_recs, devel_recs, au, BP4D_dir_int, hog_data_dir_BP4D);
ignore = valid_labels == 9; ignore = valid_labels == 9;

View file

@ -35,7 +35,7 @@ for a=1:numel(aus)
rest_aus = setdiff(all_aus, au); rest_aus = setdiff(all_aus, au);
% load the training and testing data for the current fold % load the training and testing data for the current fold
[train_samples, train_labels, ~, valid_samples, valid_labels, vid_ids_devel, ~, PC, means, scaling, success_devel] = Prepare_HOG_AU_data_generic_intensity(train_recs, devel_recs, au, BP4D_dir_int, hog_data_dir_BP4D, pca_loc); [train_samples, train_labels, ~, valid_samples, valid_labels, vid_ids_devel, ~, PC, means, scaling, success_devel] = Prepare_HOG_AU_data_generic_intensity(train_recs, devel_recs, au, BP4D_dir_int, hog_data_dir_BP4D);
ignore = valid_labels == 9; ignore = valid_labels == 9;

View file

@ -28,7 +28,7 @@ else
end end
if(exist('BP4D_dir', 'var')) if(exist('BP4D_dir', 'var'))
hog_data_dir = [BP4D_dir, '../processed_data/']; hog_data_dir = 'E:\datasets\face_datasets_processed\bp4d/';
end end
train_recs = {'F001', 'F003', 'F005', 'F007', 'F009', 'F011', 'F013', 'F015', 'F017', 'F019', 'F021', 'F023', 'M001', 'M003', 'M005', 'M007', 'M009', 'M011', 'M013', 'M015' 'M017'}; train_recs = {'F001', 'F003', 'F005', 'F007', 'F009', 'F011', 'F013', 'F015', 'F017', 'F019', 'F021', 'F023', 'M001', 'M003', 'M005', 'M007', 'M009', 'M011', 'M013', 'M015' 'M017'};

View file

@ -1,5 +1,5 @@
function [data_train, labels_train, data_devel, labels_devel, raw_devel, PC, means_norm, stds_norm, devel_ids, devel_success] = ... function [data_train, labels_train, data_devel, labels_devel, raw_devel, PC, means_norm, stds_norm, devel_ids, devel_success] = ...
Prepare_HOG_AU_data(train_users, devel_users, au_train, rest_aus, Bosphorus_dir, hog_data_dir) Prepare_HOG_AU_data(train_users, devel_users, au_train, rest_aus, Bosphorus_dir, params_data_dir)
%% %%
addpath(genpath('../data extraction/')); addpath(genpath('../data extraction/'));
@ -10,9 +10,8 @@ addpath(genpath('../data extraction/'));
[ labels_other, ~, ~ ] = extract_Bosphorus_labels(Bosphorus_dir, train_users, rest_aus); [ labels_other, ~, ~ ] = extract_Bosphorus_labels(Bosphorus_dir, train_users, rest_aus);
% Reading in the HOG data (of only relevant frames) % Reading in the HOG data (of only relevant frames)
[train_appearance_data, valid_ids_train_hog, vid_ids_train_string] = Read_HOG_files(filenames, [hog_data_dir, '/hog_aligned_rigid_b']); [train_appearance_data, valid_ids_train_hog, vid_ids_train_string] = Read_HOG_files(filenames, params_data_dir);
params_data_dir = [hog_data_dir, '/model_params_b'];
[train_geom_data] = Read_geom_files(filenames, params_data_dir); [train_geom_data] = Read_geom_files(filenames, params_data_dir);
% Subsample the data to rebalance it % Subsample the data to rebalance it
@ -60,7 +59,7 @@ end
[ labels_devel, valid_ids_devel, filenames_devel ] = extract_Bosphorus_labels(Bosphorus_dir, devel_users, au_train); [ labels_devel, valid_ids_devel, filenames_devel ] = extract_Bosphorus_labels(Bosphorus_dir, devel_users, au_train);
% Reading in the HOG data (of only relevant frames) % Reading in the HOG data (of only relevant frames)
[devel_appearance_data, valid_ids_devel_hog, vid_ids_devel_string] = Read_HOG_files(filenames_devel, [hog_data_dir, '/hog_aligned_rigid_b']); [devel_appearance_data, valid_ids_devel_hog, vid_ids_devel_string] = Read_HOG_files(filenames_devel, params_data_dir);
devel_success = valid_ids_devel_hog; devel_success = valid_ids_devel_hog;
devel_ids = vid_ids_devel_string; devel_ids = vid_ids_devel_string;

View file

@ -1,5 +1,5 @@
function [data_train, labels_train, data_devel, labels_devel, raw_devel, PC, means_norm, stds_norm, devel_ids, devel_success] = ... function [data_train, labels_train, data_devel, labels_devel, raw_devel, PC, means_norm, stds_norm, devel_ids, devel_success] = ...
Prepare_HOG_AU_data_dynamic(train_users, devel_users, au_train, rest_aus, Bosphorus_dir, hog_data_dir) Prepare_HOG_AU_data_dynamic(train_users, devel_users, au_train, rest_aus, Bosphorus_dir, params_data_dir)
%% %%
addpath(genpath('../data extraction/')); addpath(genpath('../data extraction/'));
@ -10,9 +10,8 @@ addpath(genpath('../data extraction/'));
[ labels_other, ~, ~ ] = extract_Bosphorus_labels(Bosphorus_dir, train_users, rest_aus); [ labels_other, ~, ~ ] = extract_Bosphorus_labels(Bosphorus_dir, train_users, rest_aus);
% Reading in the HOG data (of only relevant frames) % Reading in the HOG data (of only relevant frames)
[train_appearance_data, valid_ids_train_hog, vid_ids_train_string] = Read_HOG_files_dynamic(filenames, [hog_data_dir, '/hog_aligned_rigid_b']); [train_appearance_data, valid_ids_train_hog, vid_ids_train_string] = Read_HOG_files_dynamic(filenames, params_data_dir);
params_data_dir = [hog_data_dir, '/model_params_b'];
[train_geom_data] = Read_geom_files_dynamic(filenames, params_data_dir); [train_geom_data] = Read_geom_files_dynamic(filenames, params_data_dir);
if(numel(train_users) > 0) if(numel(train_users) > 0)
@ -59,7 +58,7 @@ end
[ labels_devel, valid_ids_devel, devel_files ] = extract_Bosphorus_labels(Bosphorus_dir, devel_users, au_train); [ labels_devel, valid_ids_devel, devel_files ] = extract_Bosphorus_labels(Bosphorus_dir, devel_users, au_train);
% Reading in the HOG data (of only relevant frames) % Reading in the HOG data (of only relevant frames)
[devel_appearance_data, valid_ids_devel_hog, vid_ids_devel_string] = Read_HOG_files_dynamic(devel_files, [hog_data_dir, '/hog_aligned_rigid_b']); [devel_appearance_data, valid_ids_devel_hog, vid_ids_devel_string] = Read_HOG_files_dynamic(devel_files, params_data_dir);
devel_success = valid_ids_devel_hog; devel_success = valid_ids_devel_hog;
devel_ids = vid_ids_devel_string; devel_ids = vid_ids_devel_string;

View file

@ -7,12 +7,23 @@ function [geom_data, valid_ids] = Read_geom_files(users, model_param_data_dir)
for i=1:numel(users) for i=1:numel(users)
geom_file = [model_param_data_dir, '/' users{i} '.txt']; geom_file = [model_param_data_dir, '/' users{i} '.csv'];
if(i == 1)
tab = readtable(geom_file);
column_names = tab.Properties.VariableNames;
valid_ind = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'confidence'));
shape_inds = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'p_'));
end
res = dlmread(geom_file, ',', 1, 0); res = dlmread(geom_file, ',', 1, 0);
valid = res(:, 4); % Check the confidence of detection
res = res(:, 11:end); valid = res(:, valid_ind) > 0.7;
res = res(:, shape_inds);
% Do not consider global parameters
res = res(:, 7:end);
actual_locs = res * V'; actual_locs = res * V';
res = cat(2, actual_locs, res); res = cat(2, actual_locs, res);

View file

@ -9,16 +9,24 @@ function [geom_data, valid_ids] = Read_geom_files_dynamic(users, model_param_dat
for i=1:numel(users) for i=1:numel(users)
geom_file = [model_param_data_dir, '/' users{i} '.txt']; geom_file = [model_param_data_dir, '/' users{i} '.csv'];
user_files = cat(1, user_files, str2num(users{i}(3:5))); user_files = cat(1, user_files, str2num(users{i}(3:5)));
m_file = [model_param_data_dir, '/', users{i}, '.mat']; if(i == 1)
tab = readtable(geom_file);
column_names = tab.Properties.VariableNames;
valid_ind = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'confidence'));
shape_inds = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'p_'));
end
res = dlmread(geom_file, ',', 1, 0); res = dlmread(geom_file, ',', 1, 0);
valid = res(:, 4); valid = res(:, valid_ind) > 0.7;
res = res(:, 11:end); res = res(:, shape_inds);
% Do not consider global parameters
res = res(:, 7:end);
actual_locs = res * V'; actual_locs = res * V';
res = cat(2, actual_locs, res); res = cat(2, actual_locs, res);

View file

@ -51,9 +51,9 @@ for a=1:numel(aus)
svs = bsxfun(@times, PC, 1./scaling') * w; svs = bsxfun(@times, PC, 1./scaling') * w;
name = sprintf('models/AU_%d_dyn_intensity.dat', au); name = sprintf('models/AU_%d_static_intensity.dat', au);
write_lin_dyn_svr(name, means, svs, b); write_lin_dyn_svr(name, means, svs, b, 0);
name = sprintf('results_Bosphorus_devel/AU_%d_dyn_intensity.mat', au); name = sprintf('results_Bosphorus_devel/AU_%d_dyn_intensity.mat', au);

View file

@ -1,48 +1,93 @@
clear; clear;
face_processed_dir = 'E:\datasets\face_datasets_processed';
%% CK+, FERA2011 and UNBC datasets %% CK+
hog_dir = 'D:\Datasets/face_datasets/hog_aligned_rigid/'; hog_dir = [face_processed_dir, '/ck+/'];
hog_files = dir([hog_dir, '*.hog']); hog_files = dir([hog_dir '*.hog']);
[appearance_data, valid_inds, vid_ids_train] = Read_HOG_files_small(hog_files, hog_dir); [appearance_data, valid_inds, vid_ids_train] = Read_HOG_files_small(hog_files, hog_dir);
appearance_data = appearance_data(valid_inds,:); appearance_data = appearance_data(valid_inds,:);
vid_ids_train = vid_ids_train(valid_inds,:); vid_ids_train = vid_ids_train(valid_inds,:);
%% Bosphorus
hog_dir = [face_processed_dir, '/bosph/'];
hog_files = dir([hog_dir '*.hog']);
% Remove non-frontal
frontal = true(size(hog_files));
for i = 1:numel(frontal)
if(~isempty(strfind(hog_files(i).name, 'YR')) || ~isempty(strfind(hog_files(i).name, 'PR'))|| ~isempty(strfind(hog_files(i).name, 'CR')))
frontal(i) = false;
end
end
hog_files = hog_files(frontal);
[appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
%% FERA2011
hog_dir = [face_processed_dir, '/fera2011/'];
hog_files = dir([hog_dir '*.hog']);
[appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
%% UNBC
hog_dir = [face_processed_dir, '/unbc/'];
hog_files = dir([hog_dir '*.hog']);
[appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
%% DISFA %% DISFA
hog_dir = 'D:\Datasets\DISFA\hog_aligned_rigid/'; hog_dir = [face_processed_dir, '/disfa/'];
hog_files = dir([hog_dir, '*.hog']); hog_files = dir([hog_dir '*.hog']);
[appearance_data_disfa, valid_inds, vid_ids_train_disfa] = Read_HOG_files_small(hog_files, hog_dir, 100); [appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
appearance_data_disfa = appearance_data_disfa(valid_inds,:); appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_disfa = vid_ids_train_disfa(valid_inds,:); vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data = cat(1,appearance_data, appearance_data_disfa); appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_disfa); vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
%% BP4D %% BP4D train
hog_dir = 'D:\Datasets\FERA_2015\bp4d\processed_data/train/'; hog_dir = [face_processed_dir, '/bp4d/train/'];
hog_files = dir([hog_dir, '*.hog']); hog_files = dir([hog_dir '*.hog']);
[appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
[appearance_data_bp, valid_inds, vid_ids_train_bp] = Read_HOG_files_small(hog_files, hog_dir, 50); appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data_bp = appearance_data_bp(valid_inds,:); appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train_bp = vid_ids_train_bp(valid_inds,:); vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
appearance_data = cat(1,appearance_data, appearance_data_bp); %% SEMAINE train
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_bp); hog_dir = [face_processed_dir, '/semaine/train/'];
hog_files = dir([hog_dir '*.hog']);
%% SEMAINE [appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
hog_dir = 'D:\Datasets\FERA_2015\semaine\processed_data\train\';
hog_files = dir([hog_dir, '*.hog']);
[appearance_data_semaine, valid_inds, vid_ids_train_semaine] = Read_HOG_files_small(hog_files, hog_dir, 300); appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data_semaine = appearance_data_semaine(valid_inds,:); appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train_semaine = vid_ids_train_semaine(valid_inds,:); vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
appearance_data = cat(1,appearance_data, appearance_data_semaine);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_semaine);
%% %%
means_norm = mean(appearance_data); means_norm = mean(appearance_data);

View file

@ -1,60 +1,93 @@
clear; clear;
face_processed_dir = 'E:\datasets\face_datasets_processed';
%% CK+, FERA2011, and UNBC datasets %% CK+
hog_dir = 'D:\Datasets/face_datasets/hog_aligned_rigid/'; hog_dir = [face_processed_dir, '/ck+/'];
hog_files = dir([hog_dir, '*.hog']); hog_files = dir([hog_dir '*.hog']);
[appearance_data, valid_inds, vid_ids_train] = Read_HOG_files_small(hog_files, hog_dir); [appearance_data, valid_inds, vid_ids_train] = Read_HOG_files_small(hog_files, hog_dir);
appearance_data = appearance_data(valid_inds,:); appearance_data = appearance_data(valid_inds,:);
vid_ids_train = vid_ids_train(valid_inds,:); vid_ids_train = vid_ids_train(valid_inds,:);
%% Bosphorus dataset %% Bosphorus
hog_dir = 'D:\Datasets/face_datasets/hog_aligned_rigid_b/'; hog_dir = [face_processed_dir, '/bosph/'];
hog_files = dir([hog_dir, '*.hog']); hog_files = dir([hog_dir '*.hog']);
[appearance_data_bosph, valid_inds, vid_ids_train_bosph] = Read_HOG_files_small(hog_files, hog_dir); % Remove non-frontal
frontal = true(size(hog_files));
for i = 1:numel(frontal)
if(~isempty(strfind(hog_files(i).name, 'YR')) || ~isempty(strfind(hog_files(i).name, 'PR'))|| ~isempty(strfind(hog_files(i).name, 'CR')))
frontal(i) = false;
end
end
hog_files = hog_files(frontal);
[appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
%% FERA2011
hog_dir = [face_processed_dir, '/fera2011/'];
hog_files = dir([hog_dir '*.hog']);
[appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
%% UNBC
hog_dir = [face_processed_dir, '/unbc/'];
hog_files = dir([hog_dir '*.hog']);
[appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
appearance_data_bosph = appearance_data_bosph(valid_inds,:);
vid_ids_train_bosph = vid_ids_train_bosph(valid_inds,:);
appearance_data = cat(1,appearance_data, appearance_data_bosph);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_bosph);
%% DISFA %% DISFA
hog_dir = 'D:\Datasets\DISFA\hog_aligned_rigid/'; hog_dir = [face_processed_dir, '/disfa/'];
hog_files = dir([hog_dir, '*.hog']); hog_files = dir([hog_dir '*.hog']);
[appearance_data_disfa, valid_inds, vid_ids_train_disfa] = Read_HOG_files_small(hog_files, hog_dir, 100); [appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
appearance_data_disfa = appearance_data_disfa(valid_inds,:); appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_disfa = vid_ids_train_disfa(valid_inds,:); vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data = cat(1,appearance_data, appearance_data_disfa); appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_disfa); vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
%% BP4D %% BP4D train
hog_dir = 'D:\Datasets\FERA_2015\bp4d\processed_data/train/'; hog_dir = [face_processed_dir, '/bp4d/train/'];
hog_files = dir([hog_dir, '*.hog']); hog_files = dir([hog_dir '*.hog']);
[appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
[appearance_data_bp, valid_inds, vid_ids_train_bp] = Read_HOG_files_small(hog_files, hog_dir, 50); appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data_bp = appearance_data_bp(valid_inds,:); appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train_bp = vid_ids_train_bp(valid_inds,:); vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
appearance_data = cat(1,appearance_data, appearance_data_bp); %% SEMAINE train
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_bp); hog_dir = [face_processed_dir, '/semaine/train/'];
hog_files = dir([hog_dir '*.hog']);
%% SEMAINE [appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
hog_dir = 'D:\Datasets\FERA_2015\semaine\processed_data\train\';
hog_files = dir([hog_dir, '*.hog']);
[appearance_data_semaine, valid_inds, vid_ids_train_semaine] = Read_HOG_files_small(hog_files, hog_dir, 300); appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
appearance_data_semaine = appearance_data_semaine(valid_inds,:); appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train_semaine = vid_ids_train_semaine(valid_inds,:); vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
appearance_data = cat(1,appearance_data, appearance_data_semaine);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_semaine);
%% %%
means_norm = mean(appearance_data); means_norm = mean(appearance_data);