python http://blog.csdn.net/cyh_24/article/details/49059475

github https://github.com/johnnyconstantine/Joint_Bayesian

实验所用的数据下载 http://www.down20.com/f-1036718061807849

下面为matlab代码,与论文的公式保持一致,运行需要比较大的内存。

addpath('../WDFdata')
%---------------------Load the training data------------------------
load('lbp_WDRef.mat')%there are pictures,each contains (*)
load('id_WDRef.mat')%persion id ,same id means same person
labels = id_WDRef;
clear id_WDRef;
X = double(lbp_WDRef);%trans int into double
clear lbp_WDRef;
train_mean = mean(X,);
X = bsxfun(@minus,X,train_mean);%substract the mean
% [COEFF,SCORE] = princomp(X,'econ');%PCA
[COEFF,SCORE] = pca(X,'econ');%PCA
train_x = SCORE(:,:);%
%----------------------------------------------------------
clear X;
clear SCORE;
%----------------------------------------------------------
%----------------------------------------------------------
%------------------------------load testing data-------------------------------------
load('lbp_lfw.mat')%it's 13233*5900
load('pairlist_lfw.mat')
%pairlist_lfw is an struct,it contains two * matrix,they are IntraPersonPair、ExtraPersonPair
normX = double(lbp_lfw);
train_mean = mean(normX,);
normX = bsxfun(@minus,normX,train_mean);
normX = normX * COEFF(:,:);%PCA
test_Intra = pairlist_lfw.IntraPersonPair;
test_Extra = pairlist_lfw.ExtraPersonPair;
%----------------------------------------------------------------------------------------------------------
clear lbp_lfw;
clear pairlist_lfw;
clear train_mean;
clear COEFF;
%-------------------------creat training pairs(intraPair和extraPair)---------------------------------------------------
[classes, bar, labels] = unique(labels);%labels
nc = length(classes);%there are person
clear bar and classes;
train_Intra = zeros(nc*,);%*
for i=:nc%randperm(n,)
train_Intra(*i-,:) = randperm(sum(labels == i),) + find(labels == i,,'first') - ;
train_Intra(*i,:) = randperm(sum(labels == i),) + find(labels == i,,'first') - ;
end%choose two pictures from one person as intraPairs
train_Extra = reshape(randperm(length(labels),),,);%reshape *
train_Extra(labels(train_Extra(:,))==labels(train_Extra(:,)),:)=[];
train_Extra(size(train_Intra,)+:end,:)=[];
Dis_train_Intra = zeros(size(train_Intra,),);
Dis_train_Extra = zeros(size(train_Intra,),);
%------------------------------initialize before training---------------------------------------------------------
m = length(labels); %
n = size(train_x,);%
[classes, bar, labels] = unique(labels);
nc = length(classes);%为2995
clear classes;
clear bar;
Sw = eye(size(train_x, ), size(train_x, ));
Su = eye(size(train_x, ), size(train_x, ));%initialize sw su as identity matrix
cur = {};%cell,*
withinCount = ;
numberBuff = zeros(,);% make sure that the largest number of a person is less than
for i=:nc%
cur{i} = train_x(labels == i,:);%make cell
if size(cur{i},)>
withinCount = withinCount + size(cur{i},);
end
if numberBuff(size(cur{i},)) ==
numberBuff(size(cur{i},)) = ;
end
end%
clear labels;
u = zeros(n,nc);%*
clear withinCount;
oldSw = Sw;
SuFG = cell(,);
SwG = cell(,);%* cell
%-------------------------------------EM-Like begin training-------------------------------------------------
for k=: %set the cycle times
F = inv(Sw);%formula()in supplementary material
ep =zeros(n,m);
nowp = ;
for g = :
if numberBuff(g)==
G = - .* (g .* Su + Sw) \ Su / Sw;%formula()in supplementary material
SuFG{g} = Su * (F + g.*G);%
SwG{g} = Sw*G;
end
end%
for i=:nc%
nnc = size(cur{i}, );%number of each person
u(:,i) = sum(SuFG{nnc} * cur{i}',2);%
ep(:,nowp:nowp+ size(cur{i}, )-) = bsxfun(@plus,cur{i}',sum(SwG{nnc}*cur{i}',));%formula()in supplementary material
nowp = nowp+ nnc;
end
Su = cov(u');%su,
Sw = cov(ep');%sw,。
fprintf('%d %f\n',k,norm(Sw - oldSw)/norm(Sw));
if norm(Sw - oldSw)/norm(Sw)<1e-%
break;
end
oldSw = Sw;
F = inv(Sw);
mapping.G = - .* ( * Su + Sw) \ Su / Sw;%formula()in supplementary material
mapping.A = inv(Su + Sw) - (F + mapping.G);%formula()
mapping.Sw = Sw;
mapping.Su = Su;
%---------------------------------begin testing------------------------------------------------------------------- for i=:size(train_Intra,)%formula()
Dis_train_Intra(i) = train_x(train_Intra(i,),:) * mapping.A * train_x(train_Intra(i,),:)' + train_x(train_Intra(i,2),:) * mapping.A * train_x(train_Intra(i,2),:)' - * train_x(train_Intra(i,),:) * mapping.G * train_x(train_Intra(i,),:)';
Dis_train_Extra(i) = train_x(train_Extra(i,),:) * mapping.A * train_x(train_Extra(i,),:)' + train_x(train_Extra(i,2),:) * mapping.A * train_x(train_Extra(i,2),:)' - * train_x(train_Extra(i,),:) * mapping.G * train_x(train_Extra(i,),:)';
end
group_train = [ones(size(Dis_train_Intra,),);zeros(size(Dis_train_Extra,),)];%
training = [Dis_train_Intra;Dis_train_Extra];%*
%-------------------------------------------------------------------------------------------------------------
result_Intra = zeros(,);
result_Extra = zeros(,);
for i=:
result_Intra(i) = normX(test_Intra(i,),:) * mapping.A * normX(test_Intra(i,),:)' + normX(test_Intra(i,2),:) * mapping.A * normX(test_Intra(i,2),:)' - * normX(test_Intra(i,),:) * mapping.G * normX(test_Intra(i,),:)';
result_Extra(i) = normX(test_Extra(i,),:) * mapping.A * normX(test_Extra(i,),:)' + normX(test_Extra(i,2),:) * mapping.A * normX(test_Extra(i,2),:)' - * normX(test_Extra(i,),:) * mapping.G * normX(test_Extra(i,),:)';
end%formula()
group_sample = [ones(,);zeros(,)];%
sample = [result_Intra;result_Extra];%
%---------------------------------------
% clear normX;%
%---------------------------------------
% classification
[p,q]=size(group_train);%*
starderd=;
eg1=;
num1=;
eg2=;
num2=;
for i=:p
if group_train(i,)==
eg2=eg2+training(i,);%training
num2=num2+;
else
eg1=eg1+training(i,);
num1=num1+;
end
end
starderd=(eg1+eg2)/(num1+num2);
[p,q]=size(sample);%sample
label=zeros(p,);%
accuracy=;
for i=:p
if sample(i,)>starderd%same person
label(i,)=;
else
label(i,)=;%not same person
end
if label(i,)==group_sample(i,)%
accuracy=accuracy+;
end
end
result = accuracy/p %
if(result>=0.90)%if you can't reach this high accuracy you may end this by ctl + c or just set a lower number
clear Sw and Su and F and G and numberBuff;%this should be done by the end of the for cycle
break;
end
end%new added by cx match the big for cycle
display('program done');

人脸验证算法Joint Bayesian详解及实现(Matlab)的更多相关文章

  1. 人脸验证算法Joint Bayesian详解及实现(Python版)

    人脸验证算法Joint Bayesian详解及实现(Python版) Tags: JointBayesian DeepLearning Python 本博客仅为作者记录笔记之用,不免有很多细节不对之处 ...

  2. 一阶RC高通滤波器详解(仿真+matlab+C语言实现)

    文章目录 预备知识 关于电容 HPF的推导 simulink 仿真 simulink 运行结果 matlab 实现 matlab 运行结果 C语言实现 如果本文帮到了你,帮忙点个赞: 如果本文帮到了你 ...

  3. 一阶RC低通滤波器详解(仿真+matlab+C语言实现)

    文章目录 1 预备知识 2 simulink 仿真 3 simulink 运行结果 4 matlab实现 5 matlab运行结果 6 C语言实现 7 C语言运行结果 如果本文帮到了你,帮忙点个赞: ...

  4. 手 Q 人脸识别动画实现详解

    欢迎大家前往腾讯云社区,获取更多腾讯海量技术实践干货哦~ 前言 开门见山,先来看下效果吧. 看到这么酷炫的效果图,不得不赞叹一下我们的设计师.然而,站在程序员的角度上看,除了酷炫之外更多的是复杂.但是 ...

  5. Java版人脸检测详解下篇:编码

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  6. samtools常用命令详解(转)

    转自:samtools常用命令详解 samtools的说明文档:http://samtools.sourceforge.net/samtools.shtml samtools是一个用于操作sam和ba ...

  7. 前端技术之_CSS详解第三天

    前端技术之_CSS详解第三天 二.权重问题深入 2.1 同一个标签,携带了多个类名,有冲突: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...

  8. 深度学习之卷积神经网络(CNN)详解与代码实现(一)

    卷积神经网络(CNN)详解与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/10430073.html 目 ...

  9. spring事务详解(三)源码详解

    系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...

随机推荐

  1. ffmpeg & mplayer & vlc 手册(转)

    如何基于FFMPEG和SDL写一个少于1000行代码的视频播放器 http://blog.sina.com.cn/s/blog_51396f890100nd91.html http://lanhy20 ...

  2. UNIX网络编程读书笔记:基本SCTP套接口编程

    概述 SCTP是一个较新的传输协议,于2000年在IETF得到标准化(TCP是在1981年标准化的).它最初是为满足不断增长的IP电话市场设计的:具体地说,就是穿越因特网传输电话信令. SCTP是一个 ...

  3. spring相关记录

    1 国际化org.springframework.web.servlet.i18n.SessionLocaleResolver    http://blog.csdn.net/kcai678/arti ...

  4. Python 正则表达式学习摘要及资料

    来源:Michael_翔_ 摘要 在正则表达式中,如果直接给出字符,就是精确匹配. {m,n}? 对于前一个字符重复 m 到 n 次,并且取尽可能少的情况 在字符串'aaaaaa'中,a{2,4} 会 ...

  5. iOS 3DTouch

    概述 iOS10系统登录中国,在系统中对3D Touch的使用需求更频繁,所以对iOS9中便引入的3D Touch功能做一些了解是很有必要的 详细 代码下载:http://www.demodashi. ...

  6. Android开发之帐户管理

    android.accounts主要包括了集中式的帐户管理API, AccountManagerCallback, AccountManagerFuture, OnAccountsUpdateList ...

  7. Docker配置本地镜像与容器的存储位置

    默认情况下Docker的存放位置为:/var/lib/docker 可以通过下面命令查看具体位置: sudo docker info | grep "Docker Root Dir" ...

  8. JSP页面输出的几种方式:

    1. 内置九大对象之out         下载图片 2. <%= %> JSP输出表达式      JSP中出现大量脚本 3. response.getWriter()        n ...

  9. mybatis中sql语句传入多个参数方法

    1 使用map <select id="selectRole" parameterType="map" resultType="RoleMap& ...

  10. Redis的5个常见应用场景

    前言 Redis 是一个强大的内存型存储,具有丰富的数据结构,使其可以应用于很多方面,包括作为数据库.缓存.消息队列等等. 如果你的印象中Redis只是一个 key-value 存储,那就错过了Red ...