人脸验证算法Joint Bayesian详解及实现(Matlab)
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)的更多相关文章
- 人脸验证算法Joint Bayesian详解及实现(Python版)
人脸验证算法Joint Bayesian详解及实现(Python版) Tags: JointBayesian DeepLearning Python 本博客仅为作者记录笔记之用,不免有很多细节不对之处 ...
- 一阶RC高通滤波器详解(仿真+matlab+C语言实现)
文章目录 预备知识 关于电容 HPF的推导 simulink 仿真 simulink 运行结果 matlab 实现 matlab 运行结果 C语言实现 如果本文帮到了你,帮忙点个赞: 如果本文帮到了你 ...
- 一阶RC低通滤波器详解(仿真+matlab+C语言实现)
文章目录 1 预备知识 2 simulink 仿真 3 simulink 运行结果 4 matlab实现 5 matlab运行结果 6 C语言实现 7 C语言运行结果 如果本文帮到了你,帮忙点个赞: ...
- 手 Q 人脸识别动画实现详解
欢迎大家前往腾讯云社区,获取更多腾讯海量技术实践干货哦~ 前言 开门见山,先来看下效果吧. 看到这么酷炫的效果图,不得不赞叹一下我们的设计师.然而,站在程序员的角度上看,除了酷炫之外更多的是复杂.但是 ...
- Java版人脸检测详解下篇:编码
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- samtools常用命令详解(转)
转自:samtools常用命令详解 samtools的说明文档:http://samtools.sourceforge.net/samtools.shtml samtools是一个用于操作sam和ba ...
- 前端技术之_CSS详解第三天
前端技术之_CSS详解第三天 二.权重问题深入 2.1 同一个标签,携带了多个类名,有冲突: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...
- 深度学习之卷积神经网络(CNN)详解与代码实现(一)
卷积神经网络(CNN)详解与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/10430073.html 目 ...
- spring事务详解(三)源码详解
系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...
随机推荐
- eclipse因为js validator无法通过导致build workspace失败
eclipse编译工程时时会validator js的errors和warnings,对于一些小型的项目,这当然没任何问题. 但是对于那些拥有大量js文件的web工程,js warnings通常会达到 ...
- UITextView 添加 pleaceholder
UITextView 默认没有 pleaceholder属性: 我们可以通过多种方式添加 在UITextView的代理方法中写 - (void)textViewDidBeginEditing:(UIT ...
- CSV 读写
using System; using System.IO; using System.Runtime.InteropServices; using UnityEngine; public class ...
- vnc/route/ifconfig 配置
重启网卡的方法: 1 network 利用root帐户 # service network restart ############################################## ...
- xftp Initialize Flexnet Service failed / Error code: 50003
xftp Initialize Flexnet Service failed / Error code: 50003 CreateTime--2018年5月3日15:47:05 Author:Ma ...
- jedis使用线程池封装redis基本操作
redisclient jedis 经常使用的 操作 key value hash list set zset 的基本操作 package cn.zto.util; import java.util. ...
- jQuery获取select中全部option值
<select id="language"> <option value="">请选择</option> <optio ...
- Flume入门:安装、部署
一.什么是Flume? flume 作为 cloudera 开发的实时日志收集系统,受到了业界的认可与广泛应用.Flume 初始的发行版本目前被统称为 Flume OG(original genera ...
- kernel4.1 ioctl调用
在4.1内核中开发时遇到个奇怪的问题: 用户空间的ioctl无法调用到内核空间的unlock_ioctl 排查源码发现 546 int do_vfs_ioctl(struct file *filp, ...
- LeetCode 155 Min Stack(最小栈)
翻译 设计支持push.pop.top和在常量时间内检索最小元素的栈. push(x) -- 推送元素X进栈 pop() -- 移除栈顶元素 top() -- 得到栈顶元素 getMin() -- 检 ...