sustaining_gazes/matlab_version/AU_training/pca_generation/createSubFaceModels.m

153 lines
4.7 KiB
Mathematica
Raw Normal View History

2016-06-14 23:55:16 +02:00
clear;
face_processed_dir = 'E:\datasets\face_datasets_processed';
2016-06-14 23:55:16 +02:00
%% CK+
hog_dir = [face_processed_dir, '/ck+/'];
hog_files = dir([hog_dir '*.hog']);
2016-06-14 23:55:16 +02:00
[appearance_data, valid_inds, vid_ids_train] = Read_HOG_files_small(hog_files, hog_dir);
appearance_data = appearance_data(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);
2016-06-14 23:55:16 +02:00
%% 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
hog_dir = [face_processed_dir, '/disfa/'];
hog_files = dir([hog_dir '*.hog']);
2016-06-14 23:55:16 +02:00
[appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
2016-06-14 23:55:16 +02:00
appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
2016-06-14 23:55:16 +02:00
appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
2016-06-14 23:55:16 +02:00
%% BP4D train
hog_dir = [face_processed_dir, '/bp4d/train/'];
hog_files = dir([hog_dir '*.hog']);
[appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
2016-06-14 23:55:16 +02:00
appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
2016-06-14 23:55:16 +02:00
appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
2016-06-14 23:55:16 +02:00
%% SEMAINE train
hog_dir = [face_processed_dir, '/semaine/train/'];
hog_files = dir([hog_dir '*.hog']);
2016-06-14 23:55:16 +02:00
[appearance_data_tmp, valid_inds_tmp, vid_ids_train_tmp] = Read_HOG_files_small(hog_files, hog_dir);
2016-06-14 23:55:16 +02:00
appearance_data_tmp = appearance_data_tmp(valid_inds_tmp,:);
vid_ids_train_tmp = vid_ids_train_tmp(valid_inds_tmp,:);
2016-06-14 23:55:16 +02:00
appearance_data = cat(1,appearance_data, appearance_data_tmp);
vid_ids_train = cat(1,vid_ids_train, vid_ids_train_tmp);
2016-06-14 23:55:16 +02:00
%%
means_norm = mean(appearance_data);
stds_norm = std(appearance_data);
normed_data = bsxfun(@times, bsxfun(@plus, appearance_data, -means_norm), 1./stds_norm);
%% Creating a generic model
[PC, score, eigen_vals] = princomp(normed_data, 'econ');
% Keep 95 percent of variability
total_sum = sum(eigen_vals);
count = numel(eigen_vals);
for i=1:numel(eigen_vals)
if ((sum(eigen_vals(1:i)) / total_sum) >= 0.95)
count = i;
break;
end
end
PC = PC(:,1:count);
save('generic_face_rigid.mat', 'PC', 'means_norm', 'stds_norm');
%% Creating a lower face model
normed_data_lower_face = normed_data;
normed_data_lower_face(:, 1:5*12*31) = 0;
[PC, score, eigen_vals] = princomp(normed_data_lower_face, 'econ');
% Keep 98 percent of variability
total_sum = sum(eigen_vals);
count = numel(eigen_vals);
for i=1:numel(eigen_vals)
if ((sum(eigen_vals(1:i)) / total_sum) >= 0.98)
count = i;
break;
end
end
PC = PC(:,1:count);
save('generic_face_lower.mat', 'PC', 'means_norm', 'stds_norm');
%% Creating an upper face model
normed_data_upper_face = normed_data;
normed_data_upper_face(:, end-5*12*31+1:end) = 0;
[PC, score, eigen_vals] = princomp(normed_data_upper_face, 'econ');
% Keep 98 percent of variability
total_sum = sum(eigen_vals);
count = numel(eigen_vals);
for i=1:numel(eigen_vals)
if ((sum(eigen_vals(1:i)) / total_sum) >= 0.98)
count = i;
break;
end
end
PC = PC(:,1:count);
save('generic_face_upper.mat', 'PC', 'means_norm', 'stds_norm');