我尝试执行以下链接中的附加代码: https://github.com/biometricsecurity/Preimage-attack-on-BTP-template 该代码旨在衡量 CB 系统的相似性攻击。我尝试运行 Biohahin 的示例,它运行时没有错误。我通过IoM功能改变了Biohash的功能,但重建功能不起作用。我需要你的帮助来解决问题。代码已附上。
提前致谢
function [randum] = random_IoM_edit(orig_length,Ndimension,Nprojection)
randum = randn(orig_length,Ndimension,Nprojection);
end
function [transformed_templates] = IoM_edit(opts)
persons=opts.nopersons;
for i=1:persons
training_vector=opts.data(i,:);
maxout_code_training_ind = [];
for counter = 1:opts.Nprojection
tmp_training= training_vector* opts.model(:,:,counter);
[m_trainig ind_training] = max(tmp_training);
maxout_code_training_ind = [maxout_code_training_ind, ind_training];
end
transformed_templates(i,:)=maxout_code_training_ind;
end
function [distance] = fitness_iom_edit(x, hashcode,opts)
[transformed_data] = IoM_edit(opts);
distcc=[];
for a=1:size(hashcode,1)
distcc=[distcc 1-matching_IoM(hashcode(a,:),transformed_data)];
end
distance=mean(distcc);
end
主要的mat文件是:
%clear all;
close all;
load('data\lfw\LFW_10Samples_insightface.mat')
load('data\lfw\LFW_label_10Samples_insightface.mat')
labels=ceil(0.1:0.1:158);
addpath('matlab_tools');
addpath_recurse("btp")
opts.data= LFW_10Samples_insightface
opts.Ndimension= 50;
opts.Nprojection = 300;
opts.nopersons=size(LFW_10Samples_insightface,1);
opts.dX=size(LFW_10Samples_insightface,2);
opts.model = random_IoM_edit(opts.dX,opts.Ndimension,opts.Nprojection);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% facenet iom generate dataset
[transformed_data] = IoM_edit(opts);
%scores = 1- pdist2(transformed_data,transformed_data,'Hamming');
%hamming_gen_score = scores(labels'==labels);
%hamming_gen_score = hamming_gen_score(find(hamming_gen_score~=1));
%hamming_imp_score = scores(labels'~=labels);
%[EER_HASH, mTSR, mFAR, mFRR, mGAR] =computeperformance(hamming_gen_score, hamming_imp_score, 0.001); % isnightface 3.43 % 4.40 %
reconstruct_x=zeros(158,512);
%% reconstruct the first one
for i=1:158
disp(['reconstructing ',num2str(i)])
to_retrieve_hash=transformed_data((i-1)*10+1,:); % first of the template are used to reconstruct
%rng default % For reproducibility
f_fitness = @(x)fitness_iom_edit(x,to_retrieve_hash,opts); % fitness function
f_constr = [];
reconstruct_x(i,:) = reconstruct(f_fitness,f_constr,opts);
end
save(['data/iomhashing_reconstructnoconstraint_',num2str(dimensions),'.mat'],'reconstruct_x');
save(['data/iomhashing_eer_',num2str(dimensions),'.mat'],'EER_HASH');
我有机会通过花药IoM函数进行Biohashing,重建函数不构造所需的矩阵
我认为你面临的问题是用 IoM 替换 Biohashing 后 IoM 算法中的重建函数。由于重建函数不起作用,它可能与如何定义和使用适应度函数
fitness_iom_edit
(或者可能与如何重建或处理数据)有关。
我建议您检查您的输入尺寸并确保
reconstruct
功能符合要求。
其次,调试健身功能。
fitness_iom_edit
函数通过matching_IoM
计算原始哈希码和新数据之间的距离。
第三,验证
reconstruct
函数,因为它可能需要修改才能与 IoM 配合使用。
您还应该确认
opts
结构的初始化对于 IoM 是正确的(包括 opts.model
)。
这里是一些调试代码:
function [distance] = fitness_iom_edit(x, hashcode, opts)
[transformed_data] = IoM_edit(opts);
distcc = [];
for a = 1:size(hashcode, 1)
dist = 1 - matching_IoM(hashcode(a, :), transformed_data);
distcc = [distcc, dist];
end
distance = mean(distcc);
% Debugging output
disp('Fitness function results:');
disp(['Distance: ', num2str(distance)]);
end
这是您编辑的脚本:
% Load data and labels
load('data\lfw\LFW_10Samples_insightface.mat')
load('data\lfw\LFW_label_10Samples_insightface.mat')
labels = ceil(0.1:0.1:158);
% Add necessary paths
addpath('matlab_tools');
addpath_recurse("btp");
% Set up options
opts.data = LFW_10Samples_insightface;
opts.Ndimension = 50;
opts.Nprojection = 300;
opts.nopersons = size(LFW_10Samples_insightface, 1);
opts.dX = size(LFW_10Samples_insightface, 2);
opts.model = random_IoM_edit(opts.dX, opts.Ndimension, opts.Nprojection);
% Generate transformed data
[transformed_data] = IoM_edit(opts);
% Initialize reconstructed data array
reconstruct_x = zeros(158, opts.dX);
% Reconstruct each template
for i = 1:158
disp(['Reconstructing ', num2str(i)]);
to_retrieve_hash = transformed_data((i-1)*10+1, :); % Get the hash to reconstruct
% Fitness function for reconstruction
f_fitness = @(x) fitness_iom_edit(x, to_retrieve_hash, opts);
f_constr = [];
% Attempt reconstruction
reconstruct_x(i,:) = reconstruct(f_fitness, f_constr, opts);
end
% Save results
save(['data/iomhashing_reconstructnoconstraint_', num2str(opts.Ndimension), '.mat'], 'reconstruct_x');
这应该正确初始化您的数组。我目前不在测试这个的位置。如果有任何问题我会编辑帖子。