open source pkg v1
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,119 @@
|
||||
function [data_train, labels_train, data_test, labels_test, raw_test, PC, means_norm, stds_norm, vid_ids_test, success_test] = ...
|
||||
Prepare_HOG_AU_data_generic(train_users, test_users, au_train, rest_aus, root, features_dir)
|
||||
|
||||
%% This should be a separate function?
|
||||
|
||||
input_train_label_files = cell(numel(train_users),1);
|
||||
input_test_label_files = cell(numel(test_users),1);
|
||||
|
||||
% This is for loading the labels
|
||||
for i=1:numel(train_users)
|
||||
input_train_label_files{i} = [root, '/ActionUnit_Labels/', train_users{i}, '/', train_users{i}];
|
||||
end
|
||||
|
||||
% This is for loading the labels
|
||||
for i=1:numel(test_users)
|
||||
input_test_label_files{i} = [root, '/ActionUnit_Labels/', test_users{i}, '/', test_users{i}];
|
||||
end
|
||||
|
||||
% First extracting the labels
|
||||
[train_geom_data] = Read_geom_files(train_users, features_dir);
|
||||
[test_geom_data] = Read_geom_files(test_users, features_dir);
|
||||
|
||||
% Reading in the HOG data
|
||||
[train_data, tracked_inds_hog, vid_ids_train] = Read_HOG_files(train_users, features_dir);
|
||||
[test_data, success_test, vid_ids_test] = Read_HOG_files(test_users, features_dir);
|
||||
|
||||
train_data = cat(2, train_data, train_geom_data);
|
||||
raw_test = cat(2, test_data, test_geom_data);
|
||||
|
||||
% Extracting the labels
|
||||
labels_train = extract_au_labels(input_train_label_files, au_train);
|
||||
labels_test = extract_au_labels(input_test_label_files, au_train);
|
||||
|
||||
labels_other = zeros(size(labels_train,1), numel(rest_aus));
|
||||
|
||||
% This is used to pick up activity of other AUs for a more 'interesting'
|
||||
% data split and not only neutral expressions for negative samples
|
||||
if(numel(input_train_label_files) > 0)
|
||||
for i=1:numel(rest_aus)
|
||||
labels_other(:,i) = extract_au_labels(input_train_label_files, rest_aus(i));
|
||||
end
|
||||
|
||||
% can now extract the needed training labels (do not rebalance validation
|
||||
% data)
|
||||
|
||||
% make sure the same number of positive and negative samples is taken
|
||||
reduced_inds = false(size(labels_train,1),1);
|
||||
reduced_inds(labels_train > 0) = true;
|
||||
|
||||
% make sure the same number of positive and negative samples is taken
|
||||
pos_count = sum(labels_train > 0);
|
||||
neg_count = sum(labels_train == 0);
|
||||
|
||||
% pos_count = pos_count * 8;
|
||||
|
||||
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(~tracked_inds_hog) = false;
|
||||
|
||||
labels_train = labels_train(reduced_inds);
|
||||
train_data = train_data(reduced_inds,:);
|
||||
|
||||
end
|
||||
|
||||
geom_size = max(size(train_geom_data,2), size(test_geom_data,2));
|
||||
|
||||
% 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
|
||||
|
||||
PC_n = zeros(size(PC)+geom_size);
|
||||
PC_n(1:size(PC,1), 1:size(PC,2)) = PC;
|
||||
PC_n(size(PC,1)+1:end, size(PC,2)+1:end) = eye(geom_size);
|
||||
PC = PC_n;
|
||||
|
||||
means_norm = cat(2, means_norm, zeros(1, geom_size));
|
||||
stds_norm = cat(2, stds_norm, ones(1, geom_size));
|
||||
|
||||
data_test = bsxfun(@times, bsxfun(@plus, raw_test, -means_norm), 1./stds_norm);
|
||||
data_test = data_test * PC;
|
||||
|
||||
if(numel(train_data > 0))
|
||||
data_train = bsxfun(@times, bsxfun(@plus, train_data, -means_norm), 1./stds_norm);
|
||||
data_train = data_train * PC;
|
||||
else
|
||||
data_train = [];
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,119 @@
|
||||
function [data_train, labels_train, data_test, labels_test, raw_test, PC, means_norm, stds_norm, vid_ids_test, success_test] = ...
|
||||
Prepare_HOG_AU_data_generic_dynamic(train_users, test_users, au_train, rest_aus, root, features_dir)
|
||||
|
||||
%% This should be a separate function?
|
||||
|
||||
input_train_label_files = cell(numel(train_users),1);
|
||||
input_test_label_files = cell(numel(test_users),1);
|
||||
|
||||
% This is for loading the labels
|
||||
for i=1:numel(train_users)
|
||||
input_train_label_files{i} = [root, '/ActionUnit_Labels/', train_users{i}, '/', train_users{i}];
|
||||
end
|
||||
|
||||
% This is for loading the labels
|
||||
for i=1:numel(test_users)
|
||||
input_test_label_files{i} = [root, '/ActionUnit_Labels/', test_users{i}, '/', test_users{i}];
|
||||
end
|
||||
|
||||
% First extracting the labels
|
||||
[train_geom_data] = Read_geom_files_dynamic(train_users, features_dir);
|
||||
[test_geom_data] = Read_geom_files_dynamic(test_users, features_dir);
|
||||
|
||||
% Reading in the HOG data
|
||||
[train_data, tracked_inds_hog, vid_ids_train] = Read_HOG_files_dynamic(train_users, features_dir);
|
||||
[test_data, success_test, vid_ids_test] = Read_HOG_files_dynamic(test_users, features_dir);
|
||||
|
||||
train_data = cat(2, train_data, train_geom_data);
|
||||
raw_test = cat(2, test_data, test_geom_data);
|
||||
|
||||
% Extracting the labels
|
||||
labels_train = extract_au_labels(input_train_label_files, au_train);
|
||||
labels_test = extract_au_labels(input_test_label_files, au_train);
|
||||
|
||||
labels_other = zeros(size(labels_train,1), numel(rest_aus));
|
||||
|
||||
% This is used to pick up activity of other AUs for a more 'interesting'
|
||||
% data split and not only neutral expressions for negative samples
|
||||
if(numel(input_train_label_files) > 0)
|
||||
for i=1:numel(rest_aus)
|
||||
labels_other(:,i) = extract_au_labels(input_train_label_files, rest_aus(i));
|
||||
end
|
||||
|
||||
% can now extract the needed training labels (do not rebalance validation
|
||||
% data)
|
||||
|
||||
% make sure the same number of positive and negative samples is taken
|
||||
reduced_inds = false(size(labels_train,1),1);
|
||||
reduced_inds(labels_train > 0) = true;
|
||||
|
||||
% make sure the same number of positive and negative samples is taken
|
||||
pos_count = sum(labels_train > 0);
|
||||
neg_count = sum(labels_train == 0);
|
||||
|
||||
% pos_count = pos_count * 8;
|
||||
|
||||
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(~tracked_inds_hog) = false;
|
||||
|
||||
labels_train = labels_train(reduced_inds);
|
||||
train_data = train_data(reduced_inds,:);
|
||||
|
||||
end
|
||||
|
||||
geom_size = max(size(train_geom_data,2), size(test_geom_data,2));
|
||||
|
||||
% 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
|
||||
|
||||
PC_n = zeros(size(PC)+geom_size);
|
||||
PC_n(1:size(PC,1), 1:size(PC,2)) = PC;
|
||||
PC_n(size(PC,1)+1:end, size(PC,2)+1:end) = eye(geom_size);
|
||||
PC = PC_n;
|
||||
|
||||
means_norm = cat(2, means_norm, zeros(1, geom_size));
|
||||
stds_norm = cat(2, stds_norm, ones(1, geom_size));
|
||||
|
||||
data_test = bsxfun(@times, bsxfun(@plus, raw_test, -means_norm), 1./stds_norm);
|
||||
data_test = data_test * PC;
|
||||
|
||||
if(numel(train_data > 0))
|
||||
data_train = bsxfun(@times, bsxfun(@plus, train_data, -means_norm), 1./stds_norm);
|
||||
data_train = data_train * PC;
|
||||
else
|
||||
data_train = [];
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,87 @@
|
||||
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, 'LeftVideo' users{i} '_comp.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
|
||||
@@ -0,0 +1,91 @@
|
||||
function [hog_data, valid_data, vid_id] = Read_HOG_files_dynamic(users, hog_data_dir)
|
||||
|
||||
hog_data = [];
|
||||
vid_id = {};
|
||||
valid_data = [];
|
||||
|
||||
feats_filled = 0;
|
||||
|
||||
for i=1:numel(users)
|
||||
|
||||
hog_file = [hog_data_dir, 'LeftVideo' users{i} '_comp.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,:);
|
||||
|
||||
valid = logical(curr_data(:, 1));
|
||||
|
||||
curr_data(:, 2:end) = bsxfun(@plus, curr_data(:, 2:end), -median(curr_data(valid, 2:end)));
|
||||
|
||||
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
|
||||
@@ -0,0 +1,33 @@
|
||||
function [geom_data] = Read_geom_files(users, hog_data_dir)
|
||||
|
||||
geom_data = [];
|
||||
|
||||
load('../../pca_generation/pdm_68_aligned_wild.mat');
|
||||
|
||||
for i=1:numel(users)
|
||||
|
||||
geom_file = [hog_data_dir, 'LeftVideo' users{i} '_comp.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);
|
||||
|
||||
geom_data = cat(1, geom_data, res);
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,35 @@
|
||||
function [geom_data] = Read_geom_files_dynamic(users, hog_data_dir)
|
||||
|
||||
geom_data = [];
|
||||
|
||||
load('../../pca_generation/pdm_68_aligned_wild.mat');
|
||||
|
||||
for i=1:numel(users)
|
||||
|
||||
geom_file = [hog_data_dir, 'LeftVideo' users{i} '_comp.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);
|
||||
|
||||
res = bsxfun(@plus, res, -median(res(valid,:)));
|
||||
|
||||
geom_data = cat(1, geom_data, res);
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,66 @@
|
||||
% Change to your downloaded location
|
||||
clear
|
||||
addpath('C:\liblinear\matlab')
|
||||
addpath('../training_code')
|
||||
addpath('../utilities')
|
||||
|
||||
%% load shared definitions and AU data
|
||||
shared_defs;
|
||||
|
||||
% Set up the hyperparameters to be validated
|
||||
hyperparams.c = 10.^(-7:1:1);
|
||||
hyperparams.e = 10.^(-3);
|
||||
|
||||
hyperparams.validate_params = {'c', 'e'};
|
||||
|
||||
% Set the training function
|
||||
svr_train = @svm_train_linear;
|
||||
|
||||
% Set the test function (the first output will be used for validation)
|
||||
svr_test = @svm_test_linear;
|
||||
|
||||
%%
|
||||
for a=1:numel(aus)
|
||||
|
||||
au = aus(a);
|
||||
|
||||
rest_aus = setdiff(all_aus, au);
|
||||
|
||||
% make sure validation data's labels are balanced
|
||||
[users_train, users_valid] = get_balanced_fold(DISFA_dir, users, au, 1/3, 1);
|
||||
|
||||
% need to split the rest
|
||||
[train_samples, train_labels, valid_samples, valid_labels, ~, PC, means, scaling, valid_ids, valid_success] = Prepare_HOG_AU_data_generic_dynamic(users_train, users_valid, au, rest_aus, DISFA_dir, hog_data_dir);
|
||||
|
||||
train_labels(train_labels > 1) = 1;
|
||||
valid_labels(valid_labels > 1) = 1;
|
||||
|
||||
train_samples = sparse(train_samples);
|
||||
valid_samples = sparse(valid_samples);
|
||||
|
||||
%% Validate here
|
||||
hyperparams.success = valid_success;
|
||||
|
||||
[ best_params, ~ ] = validate_grid_search_no_par(svr_train, svr_test, false, train_samples, train_labels, valid_samples, valid_labels, hyperparams);
|
||||
|
||||
model = svr_train(train_labels, train_samples, best_params);
|
||||
|
||||
[~, prediction] = svr_test(valid_labels, valid_samples, model);
|
||||
|
||||
name = sprintf('classifiers/AU_%d_dyn.mat', au);
|
||||
|
||||
[ accuracies, F1s, corrs, ccc, rms, classes ] = evaluate_regression_results( prediction, valid_labels );
|
||||
|
||||
save(name, 'model', 'accuracies', 'F1s', 'corrs', 'rms', 'ccc', 'prediction', 'valid_labels');
|
||||
|
||||
name = sprintf('classifiers/AU_%d_dyn.dat', au);
|
||||
|
||||
pos_lbl = model.Label(1);
|
||||
neg_lbl = model.Label(2);
|
||||
|
||||
w = model.w(1:end-1)';
|
||||
b = model.w(end);
|
||||
|
||||
svs = bsxfun(@times, PC, 1./scaling') * w;
|
||||
write_lin_svm(name, means, svs, b, pos_lbl, neg_lbl);
|
||||
end
|
||||
@@ -0,0 +1,67 @@
|
||||
% Change to your downloaded location
|
||||
clear
|
||||
addpath('C:\liblinear\matlab')
|
||||
addpath('../training_code')
|
||||
addpath('../utilities')
|
||||
|
||||
%% load shared definitions and AU data
|
||||
shared_defs;
|
||||
|
||||
% Set up the hyperparameters to be validated
|
||||
hyperparams.c = 10.^(-7:1:1);
|
||||
hyperparams.e = 10.^(-3);
|
||||
|
||||
hyperparams.validate_params = {'c', 'e'};
|
||||
|
||||
% Set the training function
|
||||
svr_train = @svm_train_linear;
|
||||
|
||||
% Set the test function (the first output will be used for validation)
|
||||
svr_test = @svm_test_linear;
|
||||
|
||||
%%
|
||||
for a=1:numel(aus)
|
||||
|
||||
au = aus(a);
|
||||
|
||||
rest_aus = setdiff(all_aus, au);
|
||||
|
||||
% make sure validation data's labels are balanced
|
||||
[users_train, users_valid] = get_balanced_fold(DISFA_dir, users, au, 1/3, 1);
|
||||
|
||||
% need to split the rest
|
||||
[train_samples, train_labels, valid_samples, valid_labels, ~, PC, means, scaling, valid_ids, valid_success] = Prepare_HOG_AU_data_generic(users_train, users_valid, au, rest_aus, DISFA_dir, hog_data_dir);
|
||||
|
||||
train_labels(train_labels > 1) = 1;
|
||||
valid_labels(valid_labels > 1) = 1;
|
||||
|
||||
train_samples = sparse(train_samples);
|
||||
valid_samples = sparse(valid_samples);
|
||||
|
||||
%% Validate here
|
||||
hyperparams.success = valid_success;
|
||||
|
||||
[ best_params, ~ ] = validate_grid_search_no_par(svr_train, svr_test, false, train_samples, train_labels, valid_samples, valid_labels, hyperparams);
|
||||
|
||||
model = svr_train(train_labels, train_samples, best_params);
|
||||
|
||||
[~, prediction] = svr_test(valid_labels, valid_samples, model);
|
||||
|
||||
name = sprintf('classifiers/AU_%d_stat.mat', au);
|
||||
|
||||
[ accuracies, F1s, corrs, ccc, rms, classes ] = evaluate_regression_results( prediction, valid_labels );
|
||||
|
||||
save(name, 'model', 'accuracies', 'F1s', 'corrs', 'rms', 'ccc', 'prediction', 'valid_labels');
|
||||
|
||||
name = sprintf('classifiers/AU_%d_stat.dat', au);
|
||||
|
||||
pos_lbl = model.Label(1);
|
||||
neg_lbl = model.Label(2);
|
||||
|
||||
w = model.w(1:end-1)';
|
||||
b = model.w(end);
|
||||
|
||||
svs = bsxfun(@times, PC, 1./scaling') * w;
|
||||
write_lin_svm(name, means, svs, b, pos_lbl, neg_lbl);
|
||||
|
||||
end
|
||||
@@ -0,0 +1,68 @@
|
||||
% Change to your downloaded location
|
||||
clear
|
||||
addpath('C:\liblinear\matlab')
|
||||
addpath('../training_code')
|
||||
addpath('../utilities')
|
||||
|
||||
%% load shared definitions and AU data
|
||||
shared_defs;
|
||||
|
||||
% Set up the hyperparameters to be validated
|
||||
hyperparams.c = 10.^(-7:1:3);
|
||||
hyperparams.p = 10.^(-2);
|
||||
|
||||
hyperparams.validate_params = {'c', 'p'};
|
||||
|
||||
% Set the training function
|
||||
svr_train = @svr_train_linear_shift;
|
||||
|
||||
% Set the test function (the first output will be used for validation)
|
||||
svr_test = @svr_test_linear_shift;
|
||||
|
||||
%%
|
||||
for a=1:numel(aus)
|
||||
|
||||
au = aus(a);
|
||||
|
||||
rest_aus = setdiff(all_aus, au);
|
||||
|
||||
% make sure validation data's labels are balanced
|
||||
[users_train, users_valid] = get_balanced_fold(DISFA_dir, users, au, 1/4, 1);
|
||||
|
||||
% need to split the rest
|
||||
[train_samples, train_labels, valid_samples, valid_labels, ~, PC, means, scaling, valid_ids, valid_success] = Prepare_HOG_AU_data_generic_dynamic(users_train, users_valid, au, rest_aus, DISFA_dir, hog_data_dir);
|
||||
|
||||
train_samples = sparse(train_samples);
|
||||
valid_samples = sparse(valid_samples);
|
||||
|
||||
%% Validate here
|
||||
hyperparams.success = valid_success;
|
||||
hyperparams.valid_samples = valid_samples;
|
||||
hyperparams.valid_labels = valid_labels;
|
||||
hyperparams.vid_ids = valid_ids;
|
||||
|
||||
[ best_params, ~ ] = validate_grid_search_no_par(svr_train, svr_test, false, train_samples, train_labels, valid_samples, valid_labels, hyperparams);
|
||||
|
||||
model = svr_train(train_labels, train_samples, best_params);
|
||||
model.success = valid_success;
|
||||
model.vid_ids = valid_ids;
|
||||
|
||||
[~, prediction] = svr_test(valid_labels, valid_samples, model);
|
||||
|
||||
name = sprintf('regressors/AU_%d_dyn_intensity.mat', au);
|
||||
|
||||
[ accuracies, F1s, corrs, ccc, rms, classes ] = evaluate_regression_results( prediction, valid_labels );
|
||||
|
||||
save(name, 'model', 'accuracies', 'F1s', 'corrs', 'rms', 'ccc', 'prediction', 'valid_labels');
|
||||
|
||||
% Write out the model
|
||||
name = sprintf('regressors/AU_%d_dynamic_intensity.dat', au);
|
||||
|
||||
w = model.w(1:end-1)';
|
||||
b = model.w(end);
|
||||
|
||||
svs = bsxfun(@times, PC, 1./scaling') * w;
|
||||
|
||||
write_lin_dyn_svr(name, means, svs, b, model.cutoff);
|
||||
|
||||
end
|
||||
@@ -0,0 +1,83 @@
|
||||
% Change to your downloaded location
|
||||
addpath('C:\liblinear\matlab')
|
||||
addpath('../training_code')
|
||||
addpath('../utilities')
|
||||
|
||||
num_test_folds = 5;
|
||||
|
||||
%% load shared definitions and AU data
|
||||
shared_defs;
|
||||
|
||||
% Set up the hyperparameters to be validated
|
||||
hyperparams.c = 10.^(-7:1:3);
|
||||
hyperparams.p = 10.^(-2);
|
||||
|
||||
hyperparams.validate_params = {'c', 'p'};
|
||||
|
||||
% Set the training function
|
||||
svr_train = @svr_train_linear_shift;
|
||||
|
||||
% Set the test function (the first output will be used for validation)
|
||||
svr_test = @svr_test_linear_shift;
|
||||
|
||||
test_folds = get_test_folds(num_test_folds, users);
|
||||
|
||||
%%
|
||||
for a=1:numel(aus)
|
||||
|
||||
au = aus(a);
|
||||
|
||||
prediction_all = [];
|
||||
test_all = [];
|
||||
fprintf('Training AU%d ', au);
|
||||
|
||||
for t=1:num_test_folds
|
||||
|
||||
rest_aus = setdiff(all_aus, au);
|
||||
|
||||
% load the training and testing data for the current fold
|
||||
[~, ~, test_samples, test_labels, ~, ~, ~, ~, test_ids, test_success] = Prepare_HOG_AU_data_generic_dynamic({}, test_folds{t}, au, rest_aus, DISFA_dir, hog_data_dir);
|
||||
|
||||
% create the training and validation data
|
||||
users_train = setdiff(users, unique(test_ids));
|
||||
% make sure validation data's labels are balanced
|
||||
[users_train, users_valid] = get_balanced_fold(DISFA_dir, users_train, au, 1/4, 1);
|
||||
|
||||
% need to split the rest
|
||||
[train_samples, train_labels, valid_samples, valid_labels, ~, PC, means, scaling, valid_ids, valid_success] = Prepare_HOG_AU_data_generic_dynamic(users_train, users_valid, au, rest_aus, DISFA_dir, hog_data_dir);
|
||||
|
||||
train_samples = sparse(train_samples);
|
||||
valid_samples = sparse(valid_samples);
|
||||
test_samples = sparse(test_samples);
|
||||
|
||||
%% Cross-validate here
|
||||
hyperparams.success = valid_success;
|
||||
hyperparams.valid_samples = valid_samples;
|
||||
hyperparams.valid_labels = valid_labels;
|
||||
hyperparams.vid_ids = valid_ids;
|
||||
|
||||
[ best_params, ~ ] = validate_grid_search_no_par(svr_train, svr_test, false, train_samples, train_labels, valid_samples, valid_labels, hyperparams);
|
||||
|
||||
model = svr_train(train_labels, train_samples, best_params);
|
||||
model.success = test_success;
|
||||
model.success = test_success;
|
||||
model.vid_ids = test_ids;
|
||||
|
||||
[~, prediction] = svr_test(test_labels, test_samples, model);
|
||||
|
||||
prediction_all = cat(1, prediction_all, prediction);
|
||||
test_all = cat(1, test_all, test_labels);
|
||||
fprintf('done fold %d ', t);
|
||||
end
|
||||
|
||||
fprintf('\n');
|
||||
|
||||
name = sprintf('5_fold_shift/AU_%d_dyn_shift.mat', au);
|
||||
|
||||
[ accuracies, F1s, corrs, ccc, rms, classes ] = evaluate_regression_results( prediction_all, test_all );
|
||||
|
||||
save(name, 'model', 'accuracies', 'F1s', 'corrs', 'rms', 'ccc', 'prediction_all', 'test_all');
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
% Change to your downloaded location
|
||||
clear
|
||||
addpath('C:\liblinear\matlab')
|
||||
addpath('../training_code')
|
||||
addpath('../utilities')
|
||||
|
||||
%% load shared definitions and AU data
|
||||
shared_defs;
|
||||
|
||||
% Set up the hyperparameters to be validated
|
||||
hyperparams.c = 10.^(-7:1:3);
|
||||
hyperparams.p = 10.^(-2);
|
||||
|
||||
hyperparams.validate_params = {'c', 'p'};
|
||||
|
||||
% Set the training function
|
||||
svr_train = @svr_train_linear;
|
||||
|
||||
% Set the test function (the first output will be used for validation)
|
||||
svr_test = @svr_test_linear;
|
||||
|
||||
%%
|
||||
for a=1:numel(aus)
|
||||
|
||||
au = aus(a);
|
||||
|
||||
rest_aus = setdiff(all_aus, au);
|
||||
|
||||
% make sure validation data's labels are balanced
|
||||
[users_train, users_valid] = get_balanced_fold(DISFA_dir, users, au, 1/4, 1);
|
||||
|
||||
% need to split the rest
|
||||
[train_samples, train_labels, valid_samples, valid_labels, ~, PC, means, scaling, valid_ids, valid_success] = Prepare_HOG_AU_data_generic(users_train, users_valid, au, rest_aus, DISFA_dir, hog_data_dir);
|
||||
|
||||
train_samples = sparse(train_samples);
|
||||
valid_samples = sparse(valid_samples);
|
||||
|
||||
%% Validate here
|
||||
hyperparams.success = valid_success;
|
||||
hyperparams.valid_samples = valid_samples;
|
||||
hyperparams.valid_labels = valid_labels;
|
||||
hyperparams.vid_ids = valid_ids;
|
||||
|
||||
[ best_params, ~ ] = validate_grid_search_no_par(svr_train, svr_test, false, train_samples, train_labels, valid_samples, valid_labels, hyperparams);
|
||||
|
||||
model = svr_train(train_labels, train_samples, best_params);
|
||||
model.success = valid_success;
|
||||
model.vid_ids = valid_ids;
|
||||
|
||||
[~, prediction] = svr_test(valid_labels, valid_samples, model);
|
||||
|
||||
name = sprintf('regressors/AU_%d_static_intensity.mat', au);
|
||||
|
||||
[ accuracies, F1s, corrs, ccc, rms, classes ] = evaluate_regression_results( prediction, valid_labels );
|
||||
|
||||
save(name, 'model', 'accuracies', 'F1s', 'corrs', 'rms', 'ccc', 'prediction', 'valid_labels');
|
||||
|
||||
% Write out the model
|
||||
name = sprintf('regressors/AU_%d_static_intensity.dat', au);
|
||||
|
||||
w = model.w(1:end-1)';
|
||||
b = model.w(end);
|
||||
|
||||
svs = bsxfun(@times, PC, 1./scaling') * w;
|
||||
|
||||
write_lin_svr(name, means, svs, b);
|
||||
|
||||
end
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
function [ labels ] = extract_au_labels( input_folders, au_id)
|
||||
%EXTRACT_AU_LABELS Summary of this function goes here
|
||||
% Detailed explanation goes here
|
||||
|
||||
labels = [];
|
||||
for i=1:numel(input_folders)
|
||||
|
||||
in_file = sprintf('%s_au%d.txt', input_folders{i}, au_id);
|
||||
|
||||
A = dlmread(in_file, ',');
|
||||
|
||||
labels = cat(1, labels, A(:,2));
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
function [train_users, dev_users] = get_balanced_fold(DISFA_dir, users, au, prop_test, offset)
|
||||
|
||||
% This is for loading the labels
|
||||
for i=1:numel(users)
|
||||
input_train_label_files{i} = [DISFA_dir, '/ActionUnit_Labels/', users{i}, '/', users{i}];
|
||||
end
|
||||
|
||||
% Extracting the labels
|
||||
labels_train = extract_au_labels(input_train_label_files, au);
|
||||
|
||||
counts = zeros(numel(users),1);
|
||||
for k=1:numel(users)
|
||||
counts(k) = sum(labels_train((k-1)*4844+1:k*4844));
|
||||
end
|
||||
|
||||
[sorted, inds] = sort(counts);
|
||||
|
||||
dev_users = users(inds(offset:round(1/prop_test):end));
|
||||
train_users = setdiff(users, dev_users);
|
||||
|
||||
count_dev = 0;
|
||||
count_train = 0;
|
||||
for k=1:numel(users)
|
||||
if(any(strcmp(dev_users, users{k})))
|
||||
count_dev = count_dev + counts(k);
|
||||
else
|
||||
count_train = count_train + counts(k);
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
function [ test_folds ] = get_test_folds( num_folds, users )
|
||||
%GET_TEST_FOLDS Summary of this function goes here
|
||||
% Detailed explanation goes here
|
||||
|
||||
test_folds = cell(num_folds,1);
|
||||
rng(0);
|
||||
randomise_users = randperm(27);
|
||||
spacing = round(linspace(0, 27, num_folds+1));
|
||||
for i=1:num_folds
|
||||
test_folds{i} = users(randomise_users((spacing(i)+1):spacing(i+1)));
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user