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,106 @@
function [data_train, labels_train, data_devel, labels_devel, raw_devel, PC, means_norm, stds_norm, vid_ids_devel_string, valid_ids_devel] = ...
Prepare_HOG_AU_data_generic(train_users, devel_users, au_train, rest_aus, fera_dir, features_dir)
%%
addpath(genpath('../../data extraction/'));
% First extracting the labels
[ labels_train, valid_ids_train, filenames ] = extract_FERA2011_labels(fera_dir, train_users, au_train);
[ labels_other, ~, ~ ] = extract_FERA2011_labels(fera_dir, train_users, rest_aus);
labels_other = cat(1, labels_other{:});
% 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, features_dir);
[train_geom_data] = Read_geom_files(train_users, features_dir);
% Subsample the data to make training quicker
labels_train = cat(1, labels_train{:});
valid_ids_train = logical(cat(1, valid_ids_train{:}));
reduced_inds = false(size(labels_train,1),1);
reduced_inds(labels_train == 1) = true;
% make sure the same number of positive and negative samples is taken
pos_count = sum(labels_train == 1);
neg_count = sum(labels_train == 0);
num_other = floor(pos_count / (size(labels_other, 2)));
inds_all = 1:size(labels_train,1);
for i=1:size(labels_other, 2)+1
if(i > size(labels_other, 2))
% fill the rest with a proportion of neutral
inds_other = inds_all(sum(labels_other,2)==0 & ~labels_train );
num_other_i = min(numel(inds_other), pos_count - sum(labels_train(reduced_inds,:)==0));
else
% take a proportion of each other AU
inds_other = inds_all(labels_other(:, i) & ~labels_train );
num_other_i = min(numel(inds_other), num_other);
end
inds_other_to_keep = inds_other(round(linspace(1, numel(inds_other), num_other_i)));
reduced_inds(inds_other_to_keep) = true;
end
% Remove invalid ids based on CLM failing or AU not being labelled
reduced_inds(~valid_ids_train) = false;
reduced_inds(~valid_ids_train_hog) = false;
labels_other = labels_other(reduced_inds, :);
labels_train = labels_train(reduced_inds,:);
train_appearance_data = train_appearance_data(reduced_inds,:);
train_geom_data = train_geom_data(reduced_inds,:);
vid_ids_train_string = vid_ids_train_string(reduced_inds,:);
%% Extract devel data
% First extracting the labels
[ labels_devel, valid_ids_devel, filenames_devel ] = extract_FERA2011_labels(fera_dir, devel_users, au_train);
% 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, features_dir);
[devel_geom_data] = Read_geom_files(devel_users, features_dir);
labels_devel = cat(1, labels_devel{:});
% Peforming zone specific masking
if(au_train < 8 || au_train == 43 || au_train == 45) % upper face AUs ignore bottom face
% normalise the data
pca_file = '../../pca_generation/generic_face_upper.mat';
load(pca_file);
elseif(au_train > 9) % lower face AUs ignore upper face and the sides
% normalise the data
pca_file = '../../pca_generation/generic_face_lower.mat';
load(pca_file);
elseif(au_train == 9) % Central face model
% normalise the data
pca_file = '../../pca_generation/generic_face_rigid.mat';
load(pca_file);
end
% Grab all data for validation as want good params for all the data
raw_devel = cat(2, devel_appearance_data, devel_geom_data);
devel_appearance_data = bsxfun(@times, bsxfun(@plus, devel_appearance_data, -means_norm), 1./stds_norm);
train_appearance_data = bsxfun(@times, bsxfun(@plus, train_appearance_data, -means_norm), 1./stds_norm);
data_train = train_appearance_data * PC;
data_devel = devel_appearance_data * PC;
data_train = cat(2, data_train, train_geom_data);
data_devel = cat(2, data_devel, devel_geom_data);
PC_n = zeros(size(PC)+size(train_geom_data, 2));
PC_n(1:size(PC,1), 1:size(PC,2)) = PC;
PC_n(size(PC,1)+1:end, size(PC,2)+1:end) = eye(size(train_geom_data, 2));
PC = PC_n;
means_norm = cat(2, means_norm, zeros(1, size(train_geom_data,2)));
stds_norm = cat(2, stds_norm, ones(1, size(train_geom_data,2)));
end

View File

@@ -0,0 +1,106 @@
function [data_train, labels_train, data_devel, labels_devel, raw_devel, PC, means_norm, stds_norm, vid_ids_devel_string] = ...
Prepare_HOG_AU_data_generic_dynamic(train_users, devel_users, au_train, rest_aus, semaine_dir, features_dir)
%%
addpath(genpath('../../data extraction/'));
% First extracting the labels
[ labels_train, filenames, vid_ids_train ] = extract_FERA2011_labels(semaine_dir, train_users, au_train);
[ labels_other, ~, ~ ] = extract_FERA2011_labels(semaine_dir, train_users, rest_aus);
labels_other = cat(1, labels_other{:});
% Reading in the HOG data (of only relevant frames)
[train_appearance_data, valid_ids_train_hog, vid_ids_train_string] = Read_HOG_files_dynamic(train_users, features_dir);
[train_geom_data] = Read_geom_files_dynamic(train_users, features_dir);
% Subsample the data to make training quicker
labels_train = cat(1, labels_train{:});
filenames = logical(cat(1, filenames{:}));
reduced_inds = false(size(labels_train,1),1);
reduced_inds(labels_train == 1) = true;
% make sure the same number of positive and negative samples is taken
pos_count = sum(labels_train == 1);
neg_count = sum(labels_train == 0);
num_other = floor(pos_count / (size(labels_other, 2)));
inds_all = 1:size(labels_train,1);
for i=1:size(labels_other, 2)+1
if(i > size(labels_other, 2))
% fill the rest with a proportion of neutral
inds_other = inds_all(sum(labels_other,2)==0 & ~labels_train );
num_other_i = min(numel(inds_other), pos_count - sum(labels_train(reduced_inds,:)==0));
else
% take a proportion of each other AU
inds_other = inds_all(labels_other(:, i) & ~labels_train );
num_other_i = min(numel(inds_other), num_other);
end
inds_other_to_keep = inds_other(round(linspace(1, numel(inds_other), num_other_i)));
reduced_inds(inds_other_to_keep) = true;
end
% Remove invalid ids based on CLM failing or AU not being labelled
reduced_inds(~filenames) = false;
reduced_inds(~valid_ids_train_hog) = false;
labels_other = labels_other(reduced_inds, :);
labels_train = labels_train(reduced_inds,:);
train_appearance_data = train_appearance_data(reduced_inds,:);
train_geom_data = train_geom_data(reduced_inds,:);
vid_ids_train_string = vid_ids_train_string(reduced_inds,:);
%% Extract devel data
% First extracting the labels
[ labels_devel, valid_ids_devel, vid_ids_devel ] = extract_FERA2011_labels(semaine_dir, devel_users, au_train);
% 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_users, features_dir);
[devel_geom_data] = Read_geom_files_dynamic(devel_users, features_dir);
labels_devel = cat(1, labels_devel{:});
% Peforming zone specific masking
if(au_train < 8 || au_train == 43 || au_train == 45) % upper face AUs ignore bottom face
% normalise the data
pca_file = '../../pca_generation/generic_face_upper.mat';
load(pca_file);
elseif(au_train > 9) % lower face AUs ignore upper face and the sides
% normalise the data
pca_file = '../../pca_generation/generic_face_lower.mat';
load(pca_file);
elseif(au_train == 9) % Central face model
% normalise the data
pca_file = '../../pca_generation/generic_face_rigid.mat';
load(pca_file);
end
% Grab all data for validation as want good params for all the data
raw_devel = cat(2, devel_appearance_data, devel_geom_data);
devel_appearance_data = bsxfun(@times, bsxfun(@plus, devel_appearance_data, -means_norm), 1./stds_norm);
train_appearance_data = bsxfun(@times, bsxfun(@plus, train_appearance_data, -means_norm), 1./stds_norm);
data_train = train_appearance_data * PC;
data_devel = devel_appearance_data * PC;
data_train = cat(2, data_train, train_geom_data);
data_devel = cat(2, data_devel, devel_geom_data);
PC_n = zeros(size(PC)+size(train_geom_data, 2));
PC_n(1:size(PC,1), 1:size(PC,2)) = PC;
PC_n(size(PC,1)+1:end, size(PC,2)+1:end) = eye(size(train_geom_data, 2));
PC = PC_n;
means_norm = cat(2, means_norm, zeros(1, size(train_geom_data,2)));
stds_norm = cat(2, stds_norm, ones(1, size(train_geom_data,2)));
end

View File

@@ -0,0 +1,86 @@
function [hog_data, valid_data, vid_id] = Read_HOG_files(users, hog_data_dir)
hog_data = [];
vid_id = {};
valid_data = [];
feats_filled = 0;
for i=1:numel(users)
hog_file = [hog_data_dir, '/au_training_' users{i} '.hog'];
f = fopen(hog_file, 'r');
curr_data = [];
curr_ind = 0;
while(~feof(f))
if(curr_ind == 0)
num_cols = fread(f, 1, 'int32');
if(isempty(num_cols))
break;
end
num_rows = fread(f, 1, 'int32');
num_chan = fread(f, 1, 'int32');
curr_ind = curr_ind + 1;
% preallocate some space
if(curr_ind == 1)
curr_data = zeros(5000, 1 + num_rows * num_cols * num_chan);
num_feats = 1 + num_rows * num_cols * num_chan;
end
if(curr_ind > size(curr_data,1))
curr_data = cat(1, curr_data, zeros(6000, 1 + num_rows * num_cols * num_chan));
end
feature_vec = fread(f, [1, 1 + num_rows * num_cols * num_chan], 'float32');
curr_data(curr_ind, :) = feature_vec;
else
% Reading in batches of 5000
feature_vec = fread(f, [4 + num_rows * num_cols * num_chan, 5000], 'float32');
feature_vec = feature_vec(4:end,:)';
num_rows_read = size(feature_vec,1);
curr_data(curr_ind+1:curr_ind+num_rows_read,:) = feature_vec;
curr_ind = curr_ind + size(feature_vec,1);
end
end
fclose(f);
curr_data = curr_data(1:curr_ind,:);
vid_id_curr = cell(curr_ind,1);
vid_id_curr(:) = users(i);
vid_id = cat(1, vid_id, vid_id_curr);
% Assume same number of frames per video
if(i==1)
hog_data = zeros(curr_ind*numel(users), num_feats);
end
if(size(hog_data,1) < feats_filled+curr_ind)
hog_data = cat(1, hog_data, zeros(size(hog_data,1), num_feats));
end
hog_data(feats_filled+1:feats_filled+curr_ind,:) = curr_data;
feats_filled = feats_filled + curr_ind;
end
if(numel(users) > 0)
valid_data = hog_data(1:feats_filled,1) > 0;
hog_data = hog_data(1:feats_filled,2:end);
end
end

View File

@@ -0,0 +1,133 @@
function [hog_data, valid_data, vid_id] = Read_HOG_files_dynamic(users, hog_data_dir)
hog_data = [];
vid_id = {};
valid_data = [];
feats_filled = 0;
user1 = {'train_001', 'train_002', 'train_003', 'train_004', 'train_005',...
'train_006', 'train_007', 'train_008', 'train_009', 'train_010',...
'train_011', 'train_012', 'train_013', 'train_014', 'train_015',...
'train_016', 'train_017', 'train_018'};
user2 = {'train_019', 'train_020', 'train_021', 'train_022', 'train_023',...
'train_024', 'train_025', 'train_026', 'train_027', 'train_028',...
'train_029', 'train_030', 'train_031', 'train_032'};
user3 = {'train_033', 'train_034', 'train_035', 'train_036', 'train_037',...
'train_038', 'train_039', 'train_040', 'train_041'};
user4 = {'train_042', 'train_043', 'train_044', 'train_045', 'train_046',...
'train_047', 'train_048', 'train_049', 'train_050', 'train_051',...
'train_052', 'train_053', 'train_054', 'train_055', 'train_056'};
user5 = {'train_057', 'train_058', 'train_059', 'train_060', 'train_061',...
'train_062', 'train_063'};
user6 = {'train_064', 'train_065', 'train_066', 'train_067', 'train_068',...
'train_069', 'train_070', 'train_071', 'train_072', 'train_073',...
'train_074', 'train_075', 'train_076', 'train_077', 'train_078', 'train_079'};
user7 = {'train_080', 'train_081', 'train_082', 'train_083', 'train_084',...
'train_085', 'train_086', 'train_087'};
users_group = cat(1, {user1}, {user2}, {user3}, {user4}, {user5}, {user6}, {user7});
user_inds = [];
for i=1:numel(users)
hog_file = [hog_data_dir, '/au_training_' users{i} '.hog'];
f = fopen(hog_file, 'r');
curr_data = [];
curr_ind = 0;
while(~feof(f))
if(curr_ind == 0)
num_cols = fread(f, 1, 'int32');
if(isempty(num_cols))
break;
end
num_rows = fread(f, 1, 'int32');
num_chan = fread(f, 1, 'int32');
curr_ind = curr_ind + 1;
% preallocate some space
if(curr_ind == 1)
curr_data = zeros(5000, 1 + num_rows * num_cols * num_chan);
num_feats = 1 + num_rows * num_cols * num_chan;
end
if(curr_ind > size(curr_data,1))
curr_data = cat(1, curr_data, zeros(6000, 1 + num_rows * num_cols * num_chan));
end
feature_vec = fread(f, [1, 1 + num_rows * num_cols * num_chan], 'float32');
curr_data(curr_ind, :) = feature_vec;
else
% Reading in batches of 5000
feature_vec = fread(f, [4 + num_rows * num_cols * num_chan, 5000], 'float32');
feature_vec = feature_vec(4:end,:)';
num_rows_read = size(feature_vec,1);
curr_data(curr_ind+1:curr_ind+num_rows_read,:) = feature_vec;
curr_ind = curr_ind + size(feature_vec,1);
end
end
fclose(f);
curr_data = curr_data(1:curr_ind,:);
for k=1:numel(users_group)
if(~isempty(strmatch(users{i}, users_group{k})))
user_inds = cat(1, user_inds, k * ones(curr_ind,1));
end
end
valid = logical(curr_data(:, 1));
vid_id_curr = cell(curr_ind,1);
vid_id_curr(:) = users(i);
vid_id = cat(1, vid_id, vid_id_curr);
% Assume same number of frames per video
if(i==1)
hog_data = zeros(curr_ind*numel(users), num_feats);
end
if(size(hog_data,1) < feats_filled+curr_ind)
hog_data = cat(1, hog_data, zeros(size(hog_data,1), num_feats));
end
hog_data(feats_filled+1:feats_filled+curr_ind,:) = curr_data;
feats_filled = feats_filled + curr_ind;
end
if(numel(users) > 0)
% Perform normalization here
u_id = unique(user_inds)';
valid_data = hog_data(1:feats_filled,1) > 0;
for u=u_id
hog_data(user_inds==u, 2:end) = bsxfun(@plus, hog_data(user_inds==u, 2:end), -median(hog_data(user_inds==u & valid_data, 2:end)));
end
hog_data = hog_data(1:feats_filled,2:end);
end
end

View File

@@ -0,0 +1,36 @@
function [geom_data, valid_ids] = Read_geom_files(users, params_data_dir)
geom_data = [];
valid_ids = [];
load('../../pca_generation/pdm_68_aligned_wild.mat');
for i=1:numel(users)
geom_file = [params_data_dir, '/au_training_' 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, 'success'));
shape_inds = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'p_'));
end
res = dlmread(geom_file, ',', 1, 0);
% Check the confidence of detection
valid = logical(res(:, valid_ind));
res = res(:, shape_inds);
% Do not consider global parameters
res = res(:, 7:end);
actual_locs = res * V';
res = cat(2, actual_locs, res);
valid_ids = cat(1, valid_ids, valid);
geom_data = cat(1, geom_data, res);
end
end

View File

@@ -0,0 +1,82 @@
function [geom_data, valid_ids] = Read_geom_files_dynamic(users, params_data_dir)
geom_data = [];
valid_ids = [];
load('../../pca_generation/pdm_68_aligned_wild.mat');
user1 = {'train_001', 'train_002', 'train_003', 'train_004', 'train_005',...
'train_006', 'train_007', 'train_008', 'train_009', 'train_010',...
'train_011', 'train_012', 'train_013', 'train_014', 'train_015',...
'train_016', 'train_017', 'train_018'};
user2 = {'train_019', 'train_020', 'train_021', 'train_022', 'train_023',...
'train_024', 'train_025', 'train_026', 'train_027', 'train_028',...
'train_029', 'train_030', 'train_031', 'train_032'};
user3 = {'train_033', 'train_034', 'train_035', 'train_036', 'train_037',...
'train_038', 'train_039', 'train_040', 'train_041'};
user4 = {'train_042', 'train_043', 'train_044', 'train_045', 'train_046',...
'train_047', 'train_048', 'train_049', 'train_050', 'train_051',...
'train_052', 'train_053', 'train_054', 'train_055', 'train_056'};
user5 = {'train_057', 'train_058', 'train_059', 'train_060', 'train_061',...
'train_062', 'train_063'};
user6 = {'train_064', 'train_065', 'train_066', 'train_067', 'train_068',...
'train_069', 'train_070', 'train_071', 'train_072', 'train_073',...
'train_074', 'train_075', 'train_076', 'train_077', 'train_078', 'train_079'};
user7 = {'train_080', 'train_081', 'train_082', 'train_083', 'train_084',...
'train_085', 'train_086', 'train_087'};
users_group = cat(1, {user1}, {user2}, {user3}, {user4}, {user5}, {user6}, {user7});
user_inds = [];
for i=1:numel(users)
geom_file = [params_data_dir, '/au_training_' 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, 'success'));
shape_inds = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'p_'));
end
res = dlmread(geom_file, ',', 1, 0);
% Check the confidence of detection
valid = logical(res(:, valid_ind));
res = res(:, shape_inds);
% Do not consider global parameters
res = res(:, 7:end);
for k=1:numel(users_group)
if(~isempty(strmatch(users{i}, users_group{k})))
user_inds = cat(1, user_inds, k * ones(size(valid,1),1));
end
end
actual_locs = res * V';
res = cat(2, actual_locs, res);
valid_ids = cat(1, valid_ids, valid);
geom_data = cat(1, geom_data, res);
end
if(numel(users) > 0)
% Perform normalization here
u_id = unique(user_inds)';
for u=u_id
geom_data(user_inds==u, :) = bsxfun(@plus, geom_data(user_inds==u, :), -median(geom_data(user_inds==u & valid_ids, :)));
end
end
end

View File

@@ -0,0 +1,78 @@
function Script_HOG_SVM_train()
% Change to your downloaded location
addpath('C:\liblinear\matlab')
addpath('../training_code/');
addpath('../utilities/');
addpath('../../data extraction/');
%% load shared definitions and AU data
shared_defs;
% Set up the hyperparameters to be validated
hyperparams.c = 10.^(-9:0.5:1);
hyperparams.e = 10.^(-3);
hyperparams.validate_params = {'c', 'e'};
% Set the training function
svm_train = @svm_train_linear;
% Set the test function (the first output will be used for validation)
svm_test = @svm_test_linear;
all_recs = cat(2, train_recs, devel_recs);
%%
for a=1:numel(all_aus)
au = all_aus(a);
rest_aus = setdiff(all_aus, au);
[train_recs, devel_recs] = get_balanced_fold(FERA2011_dir, all_recs, au, 1/3, 1);
% 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, rest_aus, FERA2011_dir, features_dir);
train_samples = sparse(train_samples);
valid_samples = sparse(valid_samples);
%% Cross-validate here
[ best_params, ~ ] = validate_grid_search_no_par(svm_train, svm_test, false, train_samples, train_labels, valid_samples, valid_labels, hyperparams);
model = svm_train(train_labels, train_samples, best_params);
[~, prediction] = svm_test(valid_labels, valid_samples, model);
% Go from raw data to the prediction
w = model.w(1:end-1)';
b = model.w(end);
svs = bsxfun(@times, PC, 1./scaling') * w;
name = sprintf('models/AU_%d_static.dat', au);
pos_lbl = model.Label(1);
neg_lbl = model.Label(2);
write_lin_svm(name, means, svs, b, pos_lbl, neg_lbl);
name = sprintf('results_FERA2011_devel/AU_%d_static.mat', au);
tp = sum(valid_labels == 1 & prediction == 1);
fp = sum(valid_labels == 0 & prediction == 1);
fn = sum(valid_labels == 1 & prediction == 0);
tn = sum(valid_labels == 0 & prediction == 0);
precision = tp/(tp+fp);
recall = tp/(tp+fn);
f1 = 2 * precision * recall / (precision + recall);
save(name, 'model', 'f1', 'precision', 'recall', 'best_params', 'valid_labels', 'prediction');
end
end

View File

@@ -0,0 +1,79 @@
function Script_HOG_SVM_train_dyn()
% Change to your downloaded location
addpath('C:\liblinear\matlab')
addpath('../training_code/');
addpath('../utilities/');
addpath('../../data extraction/');
%% load shared definitions and AU data
shared_defs;
% Set up the hyperparameters to be validated
hyperparams.c = 10.^(-9:0.5:1);
hyperparams.e = 10.^(-3);
hyperparams.validate_params = {'c', 'e'};
% Set the training function
svm_train = @svm_train_linear;
% Set the test function (the first output will be used for validation)
svm_test = @svm_test_linear;
all_recs = cat(2, train_recs, devel_recs);
%%
for a=1:numel(all_aus)
au = all_aus(a);
rest_aus = setdiff(all_aus, au);
[train_recs, devel_recs] = get_balanced_fold(FERA2011_dir, all_recs, au, 1/3, 1);
% 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, rest_aus, FERA2011_dir, features_dir);
train_samples = sparse(train_samples);
valid_samples = sparse(valid_samples);
%% Cross-validate here
[ best_params, ~ ] = validate_grid_search_no_par(svm_train, svm_test, false, train_samples, train_labels, valid_samples, valid_labels, hyperparams);
model = svm_train(train_labels, train_samples, best_params);
[~, prediction] = svm_test(valid_labels, valid_samples, model);
% Go from raw data to the prediction
w = model.w(1:end-1)';
b = model.w(end);
svs = bsxfun(@times, PC, 1./scaling') * w;
name = sprintf('models/AU_%d_dyn.dat', au);
pos_lbl = model.Label(1);
neg_lbl = model.Label(2);
write_lin_dyn_svm(name, means, svs, b, pos_lbl, neg_lbl);
name = sprintf('results_FERA2011_devel/AU_%d_dyn.mat', au);
tp = sum(valid_labels == 1 & prediction == 1);
fp = sum(valid_labels == 0 & prediction == 1);
fn = sum(valid_labels == 1 & prediction == 0);
tn = sum(valid_labels == 0 & prediction == 0);
precision = tp/(tp+fp);
recall = tp/(tp+fn);
f1 = 2 * precision * recall / (precision + recall);
save(name, 'model', 'f1', 'precision', 'recall', 'best_params', 'valid_labels', 'prediction');
end
end

View File

@@ -0,0 +1,56 @@
function [train_users, dev_users] = get_balanced_fold(FERA_dir, users, au, prop_test, offset)
[ labels_train, valid_ids_train, filenames ] = extract_FERA2011_labels(FERA_dir, users, au);
% Make sure the folds are user independent
user1 = {'train_001', 'train_002', 'train_003', 'train_004', 'train_005',...
'train_006', 'train_007', 'train_008', 'train_009', 'train_010',...
'train_011', 'train_012', 'train_013', 'train_014', 'train_015',...
'train_016', 'train_017', 'train_018'};
user2 = {'train_019', 'train_020', 'train_021', 'train_022', 'train_023',...
'train_024', 'train_025', 'train_026', 'train_027', 'train_028',...
'train_029', 'train_030', 'train_031', 'train_032'};
user3 = {'train_033', 'train_034', 'train_035', 'train_036', 'train_037',...
'train_038', 'train_039', 'train_040', 'train_041'};
user4 = {'train_042', 'train_043', 'train_044', 'train_045', 'train_046',...
'train_047', 'train_048', 'train_049', 'train_050', 'train_051',...
'train_052', 'train_053', 'train_054', 'train_055', 'train_056'};
user5 = {'train_057', 'train_058', 'train_059', 'train_060', 'train_061',...
'train_062', 'train_063'};
user6 = {'train_064', 'train_065', 'train_066', 'train_067', 'train_068',...
'train_069', 'train_070', 'train_071', 'train_072', 'train_073',...
'train_074', 'train_075', 'train_076', 'train_077', 'train_078', 'train_079'};
user7 = {'train_080', 'train_081', 'train_082', 'train_083', 'train_084',...
'train_085', 'train_086', 'train_087'};
users_group = cat(1, {user1}, {user2}, {user3}, {user4}, {user5}, {user6}, {user7});
counts = zeros(numel(users_group),1);
for k=1:numel(users_group)
for f=1:numel(filenames)
if(~isempty(strmatch(filenames{f}(1:9), users_group{k})))
counts(k) = counts(k) + sum(labels_train{f});
end
end
end
% Now group them together by users
[sorted, inds] = sort(counts);
dev_inds = inds(offset:round(1/prop_test):end);
train_inds = setdiff(inds, dev_inds);
dev_users = users_group(dev_inds);
dev_users = cat(2, dev_users{:})';
train_users = users_group(train_inds);
train_users = cat(2, train_users{:})';
end

View File

@@ -0,0 +1,11 @@
% this is data defined across the experiments (to make sure all of them have same user conventions)
% Defining which AU's we are extracting
all_aus = [1, 2, 4, 6, 7, 10, 12, 15, 17, 18, 25, 26];
addpath('../../data extraction/');
find_FERA2011;
features_dir = 'E:\datasets\face_datasets_processed\fera2011';