当前位置:网站首页>基于DeepFace模型设计的人脸识别软件
基于DeepFace模型设计的人脸识别软件
2022-06-10 16:31:00 【biyezuopinvip】
资源下载地址:https://download.csdn.net/download/sheziqiong/85601096
人脸识别软件(无外部API)
V2.0 基于DeepFace模型设计的人脸识别软件
V1.0 基于PCA模型设计的人脸识别软件
V2.0
- 在观看了吴恩达老师的“深度学习课程”,了解了深度卷积神经网络在人脸识别中的应用。其中提到的DeepFace模型在作业中有实现过程,故借此机会,将该模型应用到自己的人脸识别软件上。
- 引入 DeepFaceNet 模型,提高了识别准确率。同时解决了One-Shot问题。
新增文件
- dir ‘deepface’:包含了模型文件、识别函数、编码函数等
- ‘deepface.h5’ :DeepFace模型文件,采用Keras(Tensorflow backend)加载模型。
- ‘fr_utils.py’ :深度人脸识别接口,包含:模型编码人脸函数、人脸识别函数。
- ‘inception_blocks.py’:DeepFace模型接口文件,包含:加载模型函数、模型损失函数。
更新细节
- 'face_recognition.py’中新建了’DeepFaceRecognition’类,用于人脸识别。
- 增加识别细节的处理,未注册用户将会显示“Unknown”。
- 在图像预处理部分加入直方图均衡化,增加了在较暗处的识别准确率。
V1.0
- 起初,在数据库课程设计部分,我用C#设计了一个基于人脸识别的签到记录系统。这个系统中的人脸识别部分使用的是商汤科技 Face++ API。由于识别速度比较慢,还需要连网,我总想将其改为离线式识别。所以,就有了这一篇博客。
- 基于之前写过的一篇博客 《图像处理之人脸识别》 中介绍的基于PCA的训练模型方法得到了人脸模型。
- 基于人脸模型、Python设计了这个小软件。这样摆脱了使用第三方API的缺点,识别速度更快。不过,经过测试,该方法受到光照影响较大。
开发工具
环境
- windows 10
- Anaconda(Spyder)
语言
- 软件设计:Python
- 模型训练使用:Matlab
框架
- python-opencv
- 实现人脸检测功能,得到人脸区域
- numpy
- 矩阵运算
- scipy
- 科学计算,加载模型文件
- tkinter
- GUI开发
功能简介
人脸识别
在本软件设计中,我们使用的模型文件为 Matlab 导出的 .mat 文件。文件里面保存了两个矩阵 mean_face 与 V,前者为 平均脸向量,后者为人脸空间矩阵。
该软件保存的用户人脸图像大小为 112 x 92。每次开启软件时,加载所有用户图像进入内存,并将二维图像拉伸为一维向量。
v u s e r ( i ) v_{user}^{(i)} vuser(i)代表用户 i i i的人脸图像向量然后,我们将所有用户图像向量组合为用户图像矩阵,该矩阵的每一列为用户图像向量:
U = [ ( v u s e r ( 0 ) ) T ( v u s e r ( 1 ) ) T ⋯ ( v u s e r ( n ) ) T ] U = \begin{bmatrix} (v_{user}^{(0)})^T \ (v_{user}^{(1)})^T \ \cdots \ (v_{user}^{(n)})^T \end{bmatrix} U=[(vuser(0))T (vuser(1))T ⋯ (vuser(n))T]
- 将用户图像矩阵 U U U中的每一列减去平均脸向量 v m e a n _ f a c e v_{mean \_ face} vmean_face,再将运算后的矩阵投影至模型空间更新矩阵 U U U:
U = V T ⋅ ( U . − v m e a n _ f a c e ) U = V^T \cdot (U .- \ v_{mean \_ face}) U=VT⋅(U.− vmean_face)
- 如此一来,我们得到了降维后的用户人脸矩阵。
识别过程
采集人脸图像,提取人脸部分,并将图像转换为向量形式: v i n p u t v_{input} vinput
将上一步得到的人脸向量按如下公式投影至模型空间:
v p c a = V T ⋅ ( v i n p u t − v m e a n _ f a c e ) v_{pca}=V^T \cdot (v_{input} - v_{mean \_ face}) vpca=VT⋅(vinput−vmean_face)将上一步得到的 v p c a v_{pca} vpca向量与 U U U矩阵中的每一列计算 欧式距离,找到最近的一列即为识别目标。
识别函数代码
def __recognize(self, image, face):
""" the system approves the user's identity according to his face """
name = ''
try:
(x, y, w, h) = face
image = Image.fromarray(image).crop((x, y, x+w, y+h)).resize(self.img_size)
img_vec = self.V.T.dot(np.array(image).reshape([-1, 1]) - self.mean_face)
distances = [la.norm(img_vec - self.user_matrix[:, j].reshape([-1, 1])) \
for j in range(self.user_matrix.shape[1])]
min_dis = np.min(distances)
index = np.where(distances == min_dis)[0][0]
# print(min_dis, index)
name = self.user_names[index]
except:
pass
return name
人像导入
主要是为了方便导入用户人像,故加入该功能。
在界面中选择导入文件夹路径后,循环处理文件夹中的所有图像。提取人像部分并转换为灰度图片,保存至软件存储人像的相对路径下。
拍照录入
- 为了录入用户人像信息,用户可以在开启摄像头、输入姓名后,点击界面上的拍照按钮,即可保存人像信息至软件文件夹下。
软件缺陷
- 光照问题
- 比如:在光线比较亮的地方录入人像后,用户在光线暗的地方就容易被识别错误。
- 尝试解决问题的办法是:图像预处理部分使用了直方图均衡化,不过只起到了一部分作用。
- 因此使用时,应尽可能地保持录入环境与检测环境一致。
资源下载地址:https://download.csdn.net/download/sheziqiong/85601096
边栏推荐
- 新思科技助力以色列Visuality Systems推进安全“左移”
- Chongqing's first sci tech Innovation Board IPO is coming
- VBA判断一个长字符串中是否包含另一个短字符串
- 为 Chocolatey 设置代理
- Nat. Commun. | Knowledge integration and decision support for accelerating the discovery of antibiotic resistance genes
- [play with Huawei cloud] Kunpeng devkit migration practice
- “挽弓当挽强,用箭当用长”,曼孚科技为数据服务行业开启新赛道
- 使用KuboardSpray安装kubernetes(v1.23.1)
- Fabric. JS zoom canvas
- 2022年茶艺师(中级)操作证考试题库及模拟考试
猜你喜欢

L1-069 tire pressure monitoring (15 points)

C#_ Serial port communication project

Swing visualization plug-in jformdesigner of idea

Intelligent scenic spot video monitoring 5g intelligent light pole gateway networking integrated pole

Brands are difficult to establish, IPO is difficult, and Chinese tea enterprises are trapped in "tradition"?

Thread interview related questions

Photoshop如何打开、编辑和导出Webp格式图片的方法

adb不是内部或外部命令,也不是可运行的程序或批处理文件

全链路追踪 & 性能监控工具 SkyWalking 实战

MFC basic knowledge and course design ideas
随机推荐
智慧景区视频监控 5G智慧灯杆网关组网综合杆
Can bus protocol Foundation
vscode常用插件与配置
Richard Behrman, the founder of dynamic planning
Docker安装Redis镜像详细步骤(简单易懂,适合新手快速上手)
Photoshop如何打开、编辑和导出Webp格式图片的方法
Brands are difficult to establish, IPO is difficult, and Chinese tea enterprises are trapped in "tradition"?
Attributes of script tag
Swing visualization plug-in jformdesigner of idea
Example code of PHP for uploading multiple pictures
CAP 6.1 版本发布通告
Xinsi technology performed well in the Gartner application security test key capability report 2022 and won the highest score among the five common use cases
Pytorch Foundation (I) -- anaconda and pytorch installation
Institute of automation, Chinese Academy of Sciences: a review of the latest visual language pre training
成立1年便成独角兽,腾讯滴滴做「靠山」,今年新晋的独角兽不简单
MFC basic knowledge and course design ideas
ADB is not an internal or external command, nor is it a runnable program or batch file
This article introduces you to j.u.c's futuretask, fork/join framework and BlockingQueue
Eliminate if Five ways of else
Nat. Rev. Drug Discov. | Application of AI in small molecule drug discovery: an upcoming wave?