人脸识别之light_cnn_watersink的博客-程序员秘密_lightcnn

技术标签: 人脸识别  

light_cnn出自2016 cvpr吴翔A Light CNN for Deep Face Representation with Noisy Labels

优势在于一个很小的模型和一个非常不错的识别率。主要原因在于,

(1)作者使用maxout作为激活函数,实现了对噪声的过滤和对有用信号的保留,从而产生更好的特征图MFM(Max-Feature-Map)。这个思想非常不错,本人将此思想用在center_loss中,实现了大概0.5%的性能提升,同时,这个maxout也就是所谓的slice+eltwise,这2个层的好处就是,一,不会产生训练的参数,二,基本很少耗时,给人的感觉就是不做白不做,性能还有提升。

(2)作者使用了NIN(Network inNetwork)来减少参数,并提升效果,作者提供的A模型是没有NIN操作的,B模型是有NIN操作的,2个模型的训练数据集都是CASIA,但是性能有0.5%的提升,当然代价是会有额外参数的产生。但是相比其他网络结构,使用NIN还是会使模型小不少,作者论文中的网络结构和B,C模型相对应。

 

模型比较如下:

 

作者论文中的识别率是98.80%和实际测试结果非常接近,本人测试使用的对齐方式是使用作者提供的对齐方式。

         这里的S模型,是大神分享的基于light_cnn稍作修改的模型,其实就是通过卷基层替换全连接层来减少参数,当然为了保证输出为256维特征,作者在第一个卷基层的stride*2,这样使得卷积后特征图缩小为原来1半。这种方法减少了模型参数,同时,stride*2使得卷积过程少了1半以上,也许GPU并行后未必会有明显的反应,但是cpu模式下,就会看出运行时间减少不少。

 

修改的作者的对齐程序:

基本思想还是反射变换warpaffine的思想,根据眼睛做旋转,根据眼睛中点和嘴巴中点做缩放,然后crop而出)。

 

function [res, eyec2, cropped, resize_scale] = align(img, f5pt, ec_mc_y, ec_y,crop_size)
f5pt = double(f5pt);
ang_tan = (f5pt(1,2)-f5pt(2,2))/(f5pt(1,1)-f5pt(2,1));
ang = atan(ang_tan) / pi * 180;
img_rot = imrotate(img, ang, 'bicubic');
imgh = size(img,1);
imgw = size(img,2);

% eye center
x = (f5pt(1,1)+f5pt(2,1))/2;
y = (f5pt(1,2)+f5pt(2,2))/2;
% x = ffp(1);
% y = ffp(2);

ang = -ang/180*pi;
%{
x0 = x - imgw/2;
y0 = y - imgh/2;
xx = x0*cos(ang) - y0*sin(ang) + size(img_rot,2)/2;
yy = x0*sin(ang) + y0*cos(ang) + size(img_rot,1)/2;
%}
[xx, yy] = transform(x, y, ang, size(img), size(img_rot));
eyec = round([xx yy]);
x = (f5pt(4,1)+f5pt(5,1))/2;
y = (f5pt(4,2)+f5pt(5,2))/2;
[xx, yy] = transform(x, y, ang, size(img), size(img_rot));
mouthc = round([xx yy]);

resize_scale = ec_mc_y/abs(mouthc(2)-eyec(2));

img_resize = imresize(img_rot, resize_scale);

res = img_resize;
eyec2 = (eyec - [size(img_rot,2)/2 size(img_rot,1)/2]) * resize_scale + [size(img_resize,2)/2 size(img_resize,1)/2];
eyec2 = round(eyec2);
img_crop = zeros(crop_size, crop_size, size(img_rot,3));
% crop_y = eyec2(2) -floor(crop_size*1/3);
crop_y = eyec2(2) - ec_y;
crop_y_end = crop_y + crop_size - 1;
crop_x = eyec2(1)-floor(crop_size/2);
crop_x_end = crop_x + crop_size - 1;

box = guard([crop_x crop_x_end crop_y crop_y_end], size(img_resize,1));
if (box(2)>size(img_resize,2)||box(4)>size(img_resize,1))
    img_crop(box(3)-crop_y+1:box(4)-crop_y+1, box(1)-crop_x+1:box(2)-crop_x+1,:) =imresize(img_resize,[box(4)-box(3)+1,box(2)-box(1)+1]);
else
    img_crop(box(3)-crop_y+1:box(4)-crop_y+1, box(1)-crop_x+1:box(2)-crop_x+1,:) = img_resize(box(3):box(4),box(1):box(2),:);
end
% img_crop = img_rot(crop_y:crop_y+img_size-1,crop_x:crop_x+img_size-1);
cropped = img_crop/255;
end

function r = guard(x, N)
x(x<1)=1;
x(x>N)=N;
r = x;
end

function [xx, yy] = transform(x, y, ang, s0, s1)
% x,y position
% ang angle
% s0 size of original image
% s1 size of target image

x0 = x - s0(2)/2;
y0 = y - s0(1)/2;
xx = x0*cos(ang) - y0*sin(ang) + s1(2)/2;
yy = x0*sin(ang) + y0*cos(ang) + s1(1)/2;
end

 

 

 

测试程序:

其中,list.txt数据格式如下:

路径/图片类别eye_x  eye_y  eye_x  eye_y  nose_x nose_y  mouse_x  mouse _y

 

 

 

clear;
clc;
imagelist=importdata('list.txt');

addpath('/home/caffe/matlab');
caffe.reset_all();

% load face model and creat network
caffe.set_device(0);
caffe.set_mode_gpu();
%-------1
model = 'LightenedCNN_A_deploy.prototxt';
weights = 'LightenedCNN_A.caffemodel';
%-------2
% model = 'LightenedCNN_B_deploy.prototxt';
% weights = 'LightenedCNN_B.caffemodel';
%-------3
% model = 'LightenedCNN_C_deploy.prototxt';
% weights = 'LightenedCNN_C.caffemodel';

net = caffe.Net(model, weights, 'test');

features=[];

for k=1:size(imagelist.textdata,1)
    
    f5pt = [imagelist.data(k,3),imagelist.data(k,5), imagelist.data(k,7),imagelist.data(k,9),imagelist.data(k,11);...
        imagelist.data(k,2),imagelist.data(k,4), imagelist.data(k,6),imagelist.data(k,8),imagelist.data(k,10)];
    f5pt=f5pt';
   
    crop_size=128;
    ec_mc_y=48;
    ec_y=40;
    [img2, eyec, img_cropped, resize_scale] = align(img, f5pt, ec_mc_y, ec_y, crop_size);
    
    img_final = imresize(img_cropped, [crop_size crop_size], 'Method', 'bicubic');

    img_final = permute(img_final, [2,1,3]);
    img_final = img_final(:,:,[3,2,1]);
    
    if size(img_final,3)>1
    img_final = rgb2gray(img_final);
    end
    
    tic
    res = net.forward({img_final});  
    toc
    features=[features;[res{1,1}]'];   
end
score=[];
for i=1:2:size(features,1)
    scoretmp=pdist2(features(i,:),features(i+1,:),'cosine');%chisq,emd,L1,cosine,euclidean
    score=[score;scoretmp];
end
figure,plot(score);
caffe.reset_all();

 

训练的proto文件:http://download.csdn.net/detail/qq_14845119/9790137

 

reference

https://github.com/AlfredXiangWu/face_verification_experiment

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_14845119/article/details/56677339

智能推荐

计算机病毒的历史:1986-1993(译文…_菩提树下写代码的博客-程序员秘密

这篇文章是译文,由于译者水平有限,仅供参考。具体见译文下的原文。。1986:这一年第一个计算机病毒面世,它感染引导区,由名叫Basit和Amjad两个人编写。他们给这个程序命名“病毒”是因为它可以感染别的计算机和磁盘!这个病毒并没有名字,它也不传染,且只能感染360KB的软盘!同时一个叫Ralf Burger的程序员制作了第一个文件感染病毒,他把他这个程序命名为VIRDEM!这个

javaweb开发-javabean+EL+JSTL_strive_then_choose的博客-程序员秘密

JavaBean规范:JavaBean 是一种JAVA语言写成的可重用组件(类)必须遵循一定的规范         (1):类必须用public修饰         (2):必须保证有公共无参数构造器         (3):包含属性的操作手段(给属性赋值,获取属性值)  分类:         (1)复杂:UI:如Button,Panel,Window类

Git Clone时报 "fatal: index-pack failed error: RPC failed; result=18, HTTP code = 200"_百分之百ok的博客-程序员秘密

Git Clone时报 “fatal: index-pack failed error: RPC failed; result=18, HTTP code = 200”环境说明:远程仓库为gitlab,centos系统 1.问题描述: 最近在使用git clone远程仓库代码到本地时,出现如下错误:git.exe clone --progress -v "http://192.168.13.21

李德成的个人简历_济南炼油厂李德成简历_lidecheng的博客-程序员秘密

李德成的个人简历================================姓名:李德成     性别:男          民族:汉籍贯:山东省济南市出生日期:1987年4月7日学历:大专(计算机应用专业)从事专业:软件开发语言能力:英语/计算机英语Email:[email protected]联系电话:13583110271================================教育

设置footer位置:让页面footer在正文内容不够是置于屏幕底部,当正文内容超过屏幕高度时置于正文底部_奔跑的Camille的博客-程序员秘密

让页面footer在正文内容不够是置于屏幕底部,当正文内容超过屏幕高度时置于正文底部//html布局&lt;template&gt; &lt;div class="page-container"&gt; &lt;header-nav&gt;&lt;/header-nav&gt; &lt;router-view class="main-layout"&gt;&...

随便推点

JVM性能调优监控工具——jps、jstack、jmap、jhat、jstat、hprof使用详解_jstat -gcutil 打印到文件_借我十年年华的博客-程序员秘密

摘要: JDK本身提供了很多方便的JVM性能调优监控工具,除了集成式的VisualVM和jConsole外,还有jps、jstack、jmap、jhat、jstat、hprof等小巧的工具,本博客希望能起抛砖引玉之用,让大家能开始对JVM性能调优的常用工具有所了解。    现实企业级Java开发中,有时候我们会碰到下面这些问题:OutOfMemoryError,内存不足

产生异常:HibernateOptimisticLockingFailureException_Jeenyyin的博客-程序员秘密

org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hib...

人工智能在围棋程序中的应用_距离计算黑棋影响值_cjianwyr的博客-程序员秘密

围棋程序的编制被称作人工智能的“试金石”,是人工智能技术的一大难题。   本文介绍了人工智能在围棋程序中的应用与发展,对比了围棋与国际象棋博弈算法的差别和复杂度,从而分析围棋算法的难点,讨论各种博弈算法(气位理论、模式匹配与博弈树)在围棋程序中的融合运用。【关键字】  围棋,搜索,模式匹配,博弈树一、概述   1、围棋简介  围棋相传为尧所创,纵

eas k5.4 (七):v4.17 - Util(ization) Est(imated)_liglei的博客-程序员秘密

519329 sched/fair: Update util_est only on util_avg updatesa07630b sched/cpufreq/schedutil: Use util_est for OPP selectionf9be3e5 sched/fair: Use util_est in LB and WU paths7f65ea4 sched/fair: Add ...

向mysql中插入数据时出现ERROR 1054 (42S22): Unknown column ‘password‘ in ‘field list‘_firstcode666的博客-程序员秘密

向mysql中插入数据时出现ERROR 1054 (42S22): Unknown column 'password' in 'field list'打印mysql语句出来发现错误,下次直接打印sql语句。新安装的MySQL5.7,登录时提示密码错误,安装的时候并没有更改密码,后来通过免密码登录的方式更改密码,输入update mysql.user set password=password('root') where user='root'时提示ERROR 1054 (42S22): Unknow.

记一次搭建Postfix邮件服务器(上篇)_星语惜馨_新浪博客_星语惜馨的博客-程序员秘密

搭建Postfix邮件服务器(文章copy,不过一些点没注意到,补充了一些,其他自己搭建就知道失误在哪,错误百度,最后步骤是操作,打字是看不懂的可以自己查,需要请看下个文章,其中mail的用户可以多个自行添加,文章为加3)1 将sendmail服务停止[[email protected]~]# service sendmail stop//停止sendmail...

推荐文章

热门文章

相关标签