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,115 @@
clear;
%%
mirrorInds = [1,17;2,16;3,15;4,14;5,13;6,12;7,11;8,10;18,27;19,26;20,25;21,24;22,23;...
32,36;33,35;37,46;38,45;39,44;40,43;41,48;42,47;49,55;50,54;51,53;60,56;59,57;...
61,65;62,64;68,66];
mirror_inds = [1:68];
mirror_inds(mirrorInds(:,1)) = mirrorInds(:,2);
mirror_inds(mirrorInds(:,2)) = mirrorInds(:,1);
scales = {'0.50', '1.00'};
for s=scales
gen_experts = load(sprintf('cen_patches_%s_general.mat', s{1}));
load(sprintf('cen_patches_%s_menpo.mat', s{1}));
for c=1:size(visiIndex,1)
for i=1:size(visiIndex,2)
% If present in general and not menpo replace
if(gen_experts.visiIndex(c,i) && ~visiIndex(c,i))
visiIndex(c,i) = 1;
patch_experts.correlations(c,i) = gen_experts.patch_experts.correlations(c,i);
patch_experts.rms_errors(c,i) = gen_experts.patch_experts.rms_errors(c,i);
patch_experts.patch_experts(c,i) = gen_experts.patch_experts.patch_experts(c,i);
elseif(~visiIndex(c,i))
patch_experts.correlations(c,i) = 0;
patch_experts.rms_errors(c,i) = 0;
patch_experts.patch_experts(c,i) = {[]};
end
end
end
trainingScale = str2num(s{1});
save(['cen_patches_', s{1} '_of.mat'], 'trainingScale', 'centers', 'visiIndex', 'patch_experts', 'normalisationOptions');
% Work out the frontal view and remove mirror indices for it
[~, frontal] = min(mean(abs(bsxfun(@plus, centers, [0,0,0])')));
% First clean up the frontal view
patch_experts.patch_experts(frontal, mirrorInds(:,2)) = {[]};
% Work out which views have mirrors of each other, and keep only one set
% of them
n_views = size(visiIndex,1);
mirror_view = 1:n_views;
for i = 1:n_views
[~, mirror_view(i)] = min(mean(abs(bsxfun(@plus, centers, centers(i,:))')));
end
% Remove a set of mirror indices
to_rem = mirror_view < 1:n_views;
patch_experts.patch_experts(to_rem, :) = {[]};
trainingScale = str2num(s{1});
write_patch_expert_bin_simple(['cen_patches_', s{1} '_of.dat'], trainingScale, centers, visiIndex, patch_experts, mirror_inds - 1, mirror_view - 1);
end
scales = {'0.25', '0.35'};
for s=scales
gen_experts = load(sprintf('cen_patches_%s_general_model_half.mat', s{1}));
load(sprintf('cen_patches_%s_menpo_model_half.mat', s{1}));
for c=1:size(visiIndex,1)
for i=1:size(visiIndex,2)
% If present in general and not menpo replace
if(gen_experts.visiIndex(c,i) && ~visiIndex(c,i))
visiIndex(c,i) = 1;
patch_experts.correlations(c,i) = gen_experts.patch_experts.correlations(c,i);
patch_experts.rms_errors(c,i) = gen_experts.patch_experts.rms_errors(c,i);
patch_experts.patch_experts(c,i) = gen_experts.patch_experts.patch_experts(c,i);
elseif(~visiIndex(c,i))
patch_experts.correlations(c,i) = 0;
patch_experts.rms_errors(c,i) = 0;
patch_experts.patch_experts(c,i) = {[]};
end
end
end
trainingScale = str2num(s{1});
save(['cen_patches_', s{1} '_of.mat'], 'trainingScale', 'centers', 'visiIndex', 'patch_experts', 'normalisationOptions');
% Work out the frontal view and remove mirror indices for it
[~, frontal] = min(mean(abs(bsxfun(@plus, centers, [0,0,0])')));
% First clean up the frontal view
patch_experts.patch_experts(frontal, mirrorInds(:,2)) = {[]};
% Work out which views have mirrors of each other, and keep only one set
% of them
n_views = size(visiIndex,1);
mirror_view = 1:n_views;
for i = 1:n_views
[~, mirror_view(i)] = min(mean(abs(bsxfun(@plus, centers, centers(i,:))')));
end
% Remove a set of mirror indices
to_rem = mirror_view < 1:n_views;
patch_experts.patch_experts(to_rem, :) = {[]};
trainingScale = str2num(s{1});
write_patch_expert_bin_simple(['cen_patches_', s{1} '_of.dat'], trainingScale, centers, visiIndex, patch_experts, mirror_inds - 1, mirror_view - 1);
end

View File

@@ -0,0 +1,113 @@
clear;
load('../general/ccnf_patches_0.25_general.mat', 'centers', 'visiIndex', 'normalisationOptions');
mirrorInds = [1,17;2,16;3,15;4,14;5,13;6,12;7,11;8,10;18,27;19,26;20,25;21,24;22,23;...
32,36;33,35;37,46;38,45;39,44;40,43;41,48;42,47;49,55;50,54;51,53;60,56;59,57;...
61,65;62,64;68,66];
% For mirroring
frontalView = 1;
profileViewInds = [2,3,4];
% Grab all related experts and mirror them appropriatelly, just need to
% mirror the first layer
non_mirrored = mirrorInds(:,1);
normalisationOptions = rmfield(normalisationOptions, 'ccnf_ratio');
normalisationOptions.dccnf = true;
n_landmarks = size(visiIndex, 2);
n_views = size(visiIndex, 1);
patch_experts.correlations = zeros(n_views, n_landmarks);
patch_experts.rms_errors = zeros(n_views, n_landmarks);
patch_experts.types = {'reg'};
patch_experts.patch_experts = cell(n_views, n_landmarks);
scales = {'0.25', '0.35', '0.50', '1.00'};
root = 'D:/deep_experts/2017-02-02/rmses/';
for s=scales
for c=1:n_views
if(c == frontalView || sum(profileViewInds==c)> 0)
for i=1:n_landmarks
if(visiIndex(c,i))
mirror = false;
% Find the relevant file
if(c == frontalView)
rel_file = sprintf([root, 'MultiGeneral_arch4general_%s_frontal_%d_512.mat'], s{1}, i);
else
rel_file = sprintf([root, 'MultiGeneral_arch4general_%s_profile%d_%d_512.mat'], s{1}, c-1, i);
end
if(exist(rel_file, 'file'))
load(rel_file);
else
rel_id = mirrorInds(mirrorInds(:,2)==i,1);
if(isempty(rel_id))
rel_id = mirrorInds(mirrorInds(:,1)==i,2);
end
if(~visiIndex(c, rel_id))
continue;
end
if(c == frontalView)
rel_file = sprintf([root, 'MultiGeneral_arch4general_%s_frontal_%d_512.mat'], s{1}, rel_id);
mirror = true;
load(rel_file);
end
end
patch_experts.correlations(c, i) = correlation_2;
patch_experts.rms_errors(c, i) = rmse;
if(~mirror)
patch_experts.patch_experts{c, i} = weights;
else
flips = fliplr(reshape([1:121]', 11, 11));
weights_flipped = weights;
weights_flipped{1}(2:end,:) = weights{1}(flips+1,:);
patch_experts.patch_experts{c,i} = weights_flipped;
end
end
end
else
swap_id = find(centers(:,2) == -centers(c,2));
corr_T = patch_experts.correlations(swap_id,:);
% Appending a mirror view instead, based on the profile view
corr_T = swap(corr_T, mirrorInds(:,1), mirrorInds(:,2));
patch_experts.correlations(c,:) = corr_T;
rmsT = patch_experts.rms_errors(swap_id,:);
rmsT = swap(rmsT, mirrorInds(:,1), mirrorInds(:,2));
patch_experts.rms_errors(c,:) = rmsT;
patchExpertMirror = patch_experts.patch_experts(swap_id,:);
patchExpertMirrorT1 = patchExpertMirror(1,mirrorInds(:,1),:);
patchExpertMirrorT2 = patchExpertMirror(1,mirrorInds(:,2),:);
patchExpertMirror(1,mirrorInds(:,2),:) = patchExpertMirrorT1;
patchExpertMirror(1,mirrorInds(:,1),:) = patchExpertMirrorT2;
% To flip a patch expert it
for p=1:size(patchExpertMirror,2)
if(visiIndex(c, p))
weights = patchExpertMirror{p};
flips = fliplr(reshape([1:121]', 11, 11));
weights_flipped = weights;
weights_flipped{1}(2:end,:) = weights{1}(flips+1,:);
patch_experts.patch_experts{c,p} = weights_flipped;
end
end
end
end
trainingScale = str2num(s{1});
save(['cen_patches_', s{1} '_general.mat'], 'trainingScale', 'centers', 'visiIndex', 'patch_experts', 'normalisationOptions');
end

View File

@@ -0,0 +1,115 @@
clear;
load('../general/ccnf_patches_0.25_general.mat', 'centers', 'visiIndex', 'normalisationOptions');
mirrorInds = [1,17;2,16;3,15;4,14;5,13;6,12;7,11;8,10;18,27;19,26;20,25;21,24;22,23;...
32,36;33,35;37,46;38,45;39,44;40,43;41,48;42,47;49,55;50,54;51,53;60,56;59,57;...
61,65;62,64;68,66];
% For mirroring
frontalView = 1;
profileViewInds = [2,3,4];
% Grab all related experts and mirror them appropriatelly, just need to
% mirror the first layer
non_mirrored = mirrorInds(:,1);
normalisationOptions = rmfield(normalisationOptions, 'ccnf_ratio');
normalisationOptions.dccnf = true;
n_landmarks = size(visiIndex, 2);
n_views = size(visiIndex, 1);
patch_experts.correlations = zeros(n_views, n_landmarks);
patch_experts.rms_errors = zeros(n_views, n_landmarks);
patch_experts.types = {'reg'};
patch_experts.patch_experts = cell(n_views, n_landmarks);
scales = {'0.25', '0.35', '0.50', '1.00'};
visiIndex = zeros(7, 68);
root = 'D:/deep_experts/menpo/rmses/';
for s=scales
for c=1:n_views
if(c == frontalView || sum(profileViewInds==c)> 0)
for i=1:n_landmarks
mirror = false;
% Find the relevant file
if(c == frontalView)
rel_file = sprintf([root, '/%s_frontal_%d_512.mat'], s{1}, i);
else
rel_file = sprintf([root, '/%s_profile%d_%d_512.mat'], s{1}, c-1, i);
end
if(exist(rel_file, 'file'))
visiIndex(c,i) = 1;
load(rel_file);
else
rel_id = mirrorInds(mirrorInds(:,2)==i,1);
if(isempty(rel_id))
rel_id = mirrorInds(mirrorInds(:,1)==i,2);
end
if(c == frontalView)
rel_file = sprintf([root, '/%s_frontal_%d_512.mat'], s{1}, rel_id);
mirror = true;
visiIndex(c,i) = 1;
load(rel_file);
end
end
patch_experts.correlations(c, i) = correlation_2;
patch_experts.rms_errors(c, i) = rmse;
if(~mirror)
patch_experts.patch_experts{c, i} = weights;
else
flips = fliplr(reshape([1:121]', 11, 11));
weights_flipped = weights;
weights_flipped{1}(2:end,:) = weights{1}(flips+1,:);
patch_experts.patch_experts{c,i} = weights_flipped;
end
end
else
swap_id = find(centers(:,2) == -centers(c,2));
corr_T = patch_experts.correlations(swap_id,:);
% Appending a mirror view instead, based on the profile view
corr_T = swap(corr_T, mirrorInds(:,1), mirrorInds(:,2));
patch_experts.correlations(c,:) = corr_T;
vis_T = visiIndex(swap_id,:);
% Appending a mirror view instead, based on the profile view
vis_T = swap(vis_T, mirrorInds(:,1), mirrorInds(:,2));
visiIndex(c,:) = vis_T;
rmsT = patch_experts.rms_errors(swap_id,:);
rmsT = swap(rmsT, mirrorInds(:,1), mirrorInds(:,2));
patch_experts.rms_errors(c,:) = rmsT;
patchExpertMirror = patch_experts.patch_experts(swap_id,:);
patchExpertMirrorT1 = patchExpertMirror(1,mirrorInds(:,1),:);
patchExpertMirrorT2 = patchExpertMirror(1,mirrorInds(:,2),:);
patchExpertMirror(1,mirrorInds(:,2),:) = patchExpertMirrorT1;
patchExpertMirror(1,mirrorInds(:,1),:) = patchExpertMirrorT2;
% To flip a patch expert it
for p=1:size(patchExpertMirror,2)
if(visiIndex(c, p))
weights = patchExpertMirror{p};
flips = fliplr(reshape([1:121]', 11, 11));
weights_flipped = weights;
weights_flipped{1}(2:end,:) = weights{1}(flips+1,:);
patch_experts.patch_experts{c,p} = weights_flipped;
end
end
end
end
trainingScale = str2num(s{1});
save(['cen_patches_', s{1} '_menpo.mat'], 'trainingScale', 'centers', 'visiIndex', 'patch_experts', 'normalisationOptions');
write_patch_expert_bin(['cen_patches_', s{1} '_menpo.dat'], trainingScale, centers, visiIndex, patch_experts);
end

View File

@@ -0,0 +1,140 @@
clear;
load('../general/ccnf_patches_0.25_general.mat', 'centers', 'visiIndex', 'normalisationOptions');
mirrorInds = [1,17;2,16;3,15;4,14;5,13;6,12;7,11;8,10;18,27;19,26;20,25;21,24;22,23;...
32,36;33,35;37,46;38,45;39,44;40,43;41,48;42,47;49,55;50,54;51,53;60,56;59,57;...
61,65;62,64;68,66];
% For mirroring
frontalView = 1;
profileViewInds = [2,3,4];
% Grab all related experts and mirror them appropriatelly, just need to
% mirror the first layer
non_mirrored = mirrorInds(:,1);
normalisationOptions = rmfield(normalisationOptions, 'ccnf_ratio');
normalisationOptions.dccnf = true;
n_landmarks = size(visiIndex, 2);
n_views = size(visiIndex, 1);
patch_experts.correlations = zeros(n_views, n_landmarks);
patch_experts.rms_errors = zeros(n_views, n_landmarks);
patch_experts.types = {'reg'};
patch_experts.patch_experts = cell(n_views, n_landmarks);
scales = {'0.25', '0.35', '0.50', '1.00'};
visiIndex_full = visiIndex;
to_rem_from = [1,2,3,6,7];
to_rem_1 = [4;68;58;62;51;6;59;20;63;53;25;56;14;64;9;67;2;33;11;37;17;52;26;60;28;34;44;38;29;8;21;15;12;18];
to_rem_2 = [6;62;50;25;59;20;17;66;64;57;39;14;12;68;41;45;34;43;30;60;4;29;1;61;47;9;65;52;37;22;15;35;54;58];
to_rem_3 = [66;62;54;60;38;5;30;13;28;59;44;67;41;57;25];
for s=scales
visiIndex = visiIndex_full;
for c=1:n_views
if(c == frontalView || sum(profileViewInds==c)> 0)
for i=1:n_landmarks
if(visiIndex(c,i))
mirror = false;
% Find the relevant file
if(c == frontalView)
rel_file = sprintf('D:/deep_experts/rmses/MultiGeneral_arch4general_%s_frontal_%d_512.mat', s{1}, i);
else
rel_file = sprintf('D:/deep_experts/rmses/MultiGeneral_arch4general_%s_profile%d_%d_512.mat', s{1}, c-1, i);
end
if(exist(rel_file, 'file'))
load(rel_file);
else
rel_id = mirrorInds(mirrorInds(:,2)==i,1);
if(isempty(rel_id))
rel_id = mirrorInds(mirrorInds(:,1)==i,2);
end
if(~visiIndex(c, rel_id))
break;
end
if(c == frontalView)
rel_file = sprintf('D:/deep_experts/rmses/MultiGeneral_arch4general_%s_frontal_%d_512.mat', s{1}, rel_id);
else
rel_file = sprintf('D:/deep_experts/rmses/MultiGeneral_arch4general_%s_profile%d_%d_512.mat', s{1}, c-1, rel_id);
end
mirror = true;
load(rel_file);
end
patch_experts.correlations(c, i) = correlation_2;
patch_experts.rms_errors(c, i) = rmse;
if(~mirror)
patch_experts.patch_experts{c, i} = weights;
else
flips = fliplr(reshape([1:121]', 11, 11));
weights_flipped = weights;
weights_flipped{1}(2:end,:) = weights{1}(flips+1,:);
patch_experts.patch_experts{c,i} = weights_flipped;
end
end
end
else
swap_id = find(centers(:,2) == -centers(c,2));
corr_T = patch_experts.correlations(swap_id,:);
% Appending a mirror view instead, based on the profile view
corr_T = swap(corr_T, mirrorInds(:,1), mirrorInds(:,2));
patch_experts.correlations(c,:) = corr_T;
rmsT = patch_experts.rms_errors(swap_id,:);
rmsT = swap(rmsT, mirrorInds(:,1), mirrorInds(:,2));
patch_experts.rms_errors(c,:) = rmsT;
patchExpertMirror = patch_experts.patch_experts(swap_id,:);
patchExpertMirrorT1 = patchExpertMirror(1,mirrorInds(:,1),:);
patchExpertMirrorT2 = patchExpertMirror(1,mirrorInds(:,2),:);
patchExpertMirror(1,mirrorInds(:,2),:) = patchExpertMirrorT1;
patchExpertMirror(1,mirrorInds(:,1),:) = patchExpertMirrorT2;
% To flip a patch expert it
for p=1:size(patchExpertMirror,2)
if(visiIndex(c, p))
weights = patchExpertMirror{p};
flips = fliplr(reshape([1:121]', 11, 11));
weights_flipped = weights;
weights_flipped{1}(2:end,:) = weights{1}(flips+1,:);
patch_experts.patch_experts{c,p} = weights_flipped;
end
end
end
end
if(strcmp('0.25', s))
visiIndex(to_rem_from, to_rem_1) = 0;
patch_experts.correlations(to_rem_from, to_rem_1) = 0;
patch_experts.rms_errors(to_rem_from, to_rem_1) = 0;
patch_experts.patch_experts(to_rem_from, to_rem_1) = {[]};
end
if(strcmp('0.35', s))
visiIndex(to_rem_from, to_rem_2) = 0;
patch_experts.correlations(to_rem_from, to_rem_2) = 0;
patch_experts.rms_errors(to_rem_from, to_rem_2) = 0;
patch_experts.patch_experts(to_rem_from, to_rem_2) = {[]};
end
if(strcmp('0.50', s))
visiIndex(to_rem_from, to_rem_3) = 0;
patch_experts.correlations(to_rem_from, to_rem_3) = 0;
patch_experts.rms_errors(to_rem_from, to_rem_3) = 0;
patch_experts.patch_experts(to_rem_from, to_rem_3) = {[]};
end
trainingScale = str2num(s{1});
save(['cen_patches_', s{1} '_general_sparse.mat'], 'trainingScale', 'centers', 'visiIndex', 'patch_experts', 'normalisationOptions');
write_patch_expert_bin(['cen_patches_', s{1} '_general_sparse.dat'], trainingScale, centers, visiIndex, patch_experts);
end

View File

@@ -0,0 +1,12 @@
Scripts for creating CEN patch experts from already trained models.
1. To create one from 300W + MultiPIE - create_cen_experts_gen.m
2. To create one from 300W + MultiPIE + Menpo - create_cen_experts_menpo.m
Please note that items 1 and 2 use the output of the code from "OpenFace/model_training/ce-clm_training/cen_training/train_cen.py. The output of this code is fed as "MultiGeneral_arch4general_%s_[frontal,profilex]_%d_512.mat'" in file 1 which can be decoded as follows: we call the training procedure MultiGeneral. It uses arch4 and is trained on 300W + MultiPIE (called general). Hence the architecture and data are represented as arch4general. The first %s is the scale. When generating the data from "OpenFace/model_training/ce-clm_training/patch_generation/" you will have 4 scales of {'0.25', '0.35', '0.50', '1.00'}. The frontal means trained for frontal faces (patches from frontal images) and profilex means from profilex; x can be 1,2,3 or depending on how many different profiles you defined when generating the data. The %d means which landmark number the training has been done for. 512 denotes the minibatch size. If you decide to go with different names please replace the "MultiGeneral_arch4general_%s_[frontal,profilex]_%d_512.mat'" with your desired name. We didn't change it to demonstrate which architecture and configurations we used. This name should match the output of the script "OpenFace/model_training/ce-clm_training/patch_generation/" denoted with parameter <results_dir> where all the results are svaed. All the training epochs will be stored when training ce-clm model, you can simply pick the best one and use it for the scripts in this folder.
To create one used in OpenFace for C++ code:
create_cen_experts_OF.m (this uses both the general and menpo experts to create a joint one, with general ones used when menpo unavailable for that view)
To dowload pretrained models, go to:
https://www.dropbox.com/sh/o8g1530jle17spa/AADRntSHl_jLInmrmSwsX-Qsa?dl=0

View File

@@ -0,0 +1,6 @@
function arr = swap(arr, ind1, ind2)
val1 = arr(ind1);
val2 = arr(ind2);
arr(ind1) = val2;
arr(ind2) = val1;
end

View File

@@ -0,0 +1,37 @@
% for easier readibility write them row by row
function writeMatrixBin(fileID, M, type)
% 4 bytes each for the description
fwrite(fileID, size(M,1), 'uint');
fwrite(fileID, size(M,2), 'uint');
fwrite(fileID, type, 'uint');
% Convert the matrix to OpenCV format (row minor as opposed to column
% minor)
M = M';
% type 0 - uint8, 1 - int8, 2 - uint16, 3 - int16, 4 - int, 5 -
% float32, 6 - float64
% Write out the matrix itself
switch type
case 0
type = 'uint8';
case 1
type = 'int8';
case 2
type = 'uint16';
case 3
type = 'int16';
case 4
type = 'int';
case 5
type = 'float32';
case 6
type = 'float64';
otherwise
type = 'float32';
end
fwrite(fileID, M, type);
end

View File

@@ -0,0 +1,73 @@
function write_patch_expert_bin(location, trainingScale, centers, visiIndex, patch_experts)
patches_file = fopen(location, 'w');
[n_views, n_landmarks, ~] = size(patch_experts.correlations);
% write out the scaling factor as this is what will be used when
% fitting on the window
fwrite(patches_file, trainingScale, 'float64');
fwrite(patches_file, n_views, 'int');
% Write out the information about the view's and centers here
for i=1:n_views
% this indicates that we're writing a 3x1 double matrix
writeMatrixBin(patches_file, centers(i,:)', 6);
end
% Write out the visibilities
for i=1:n_views
% this indicates that we're writing a 3x1 double matrix
writeMatrixBin(patches_file, visiIndex(i,:)', 4);
end
for i=1:n_views
for j=1:n_landmarks
% Write out that we're writing a CEN patch expert of 11x11 support region
fwrite(patches_file, 6, 'int');
fwrite(patches_file, 11, 'int');
fwrite(patches_file, 11, 'int');
if(~visiIndex(i,j))
% Write out that there won't be any neurons for this
% landmark
fwrite(patches_file, 0, 'int');
fwrite(patches_file, 0, 'int');
else
num_layers = numel(patch_experts.patch_experts{i,j})/2;
fwrite(patches_file, num_layers, 'int');
for n=1:num_layers
% output the actual layer
% Layer type, bias, weights
% Type of layer, first two are relu, the final one is a
% sigmoid (0 - sigmoid, 1 - tanh_opt, 2 - ReLU)
if(n < 3)
fwrite(patches_file, 2, 'int');
else
fwrite(patches_file, 0, 'int');
end
bias = patch_experts.patch_experts{i,j}{n*2};
weights = patch_experts.patch_experts{i,j}{n*2-1};
% the actual bias/weight matrix
writeMatrixBin(patches_file, bias, 5);
writeMatrixBin(patches_file, weights, 5);
end
% finally write out the confidence
fwrite(patches_file, patch_experts.correlations(i,j), 'float64');
end
end
end
fclose(patches_file);

View File

@@ -0,0 +1,79 @@
function write_patch_expert_bin_simple(location, trainingScale, centers, visiIndex, patch_experts, mirror_inds, mirror_view)
patches_file = fopen(location, 'w');
[n_views, n_landmarks, ~] = size(patch_experts.correlations);
% write out the scaling factor as this is what will be used when
% fitting on the window
fwrite(patches_file, trainingScale, 'float64');
fwrite(patches_file, n_views, 'int');
% Write out the information about the view's and centers here
for i=1:n_views
% this indicates that we're writing a 3x1 double matrix
writeMatrixBin(patches_file, centers(i,:)', 6);
end
% Write out the visibilities
for i=1:n_views
% this indicates that we're writing a 3x1 double matrix
writeMatrixBin(patches_file, visiIndex(i,:)', 4);
end
% Write out the mirror indices
writeMatrixBin(patches_file, mirror_inds, 4);
% Write out the mirror views
writeMatrixBin(patches_file, mirror_view, 4);
for i=1:n_views
for j=1:n_landmarks
% Write out that we're writing a CEN patch expert of 11x11 support region
fwrite(patches_file, 6, 'int');
fwrite(patches_file, 11, 'int');
fwrite(patches_file, 11, 'int');
if(~visiIndex(i,j))
% Write out that there won't be any neurons for this
% landmark
fwrite(patches_file, 0, 'int');
fwrite(patches_file, patch_experts.correlations(i,j), 'float64'); % also writing out a fake correlation
else
num_layers = numel(patch_experts.patch_experts{i,j})/2;
fwrite(patches_file, num_layers, 'int');
for n=1:num_layers
% output the actual layer
% Layer type, bias, weights
% Type of layer, first two are relu, the final one is a
% sigmoid (0 - sigmoid, 1 - tanh_opt, 2 - ReLU)
if(n < 3)
fwrite(patches_file, 2, 'int');
else
fwrite(patches_file, 0, 'int');
end
bias = patch_experts.patch_experts{i,j}{n*2};
weights = patch_experts.patch_experts{i,j}{n*2-1};
% the actual bias/weight matrix
writeMatrixBin(patches_file, bias, 5);
writeMatrixBin(patches_file, weights', 5);
end
% finally write out the confidence
fwrite(patches_file, patch_experts.correlations(i,j), 'float64');
end
end
end
fclose(patches_file);