当前位置:网站首页>基于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
边栏推荐
- Primekg: building a knowledge map to achieve precision medicine
- Chongqing's first sci tech Innovation Board IPO is coming
- 品牌难立,IPO难行,中国茶企困于“传统”?
- SOA架构/测试阶段接口描述语言转换方案
- 2022年G2电站锅炉司炉考试模拟100题及模拟考试
- Detailed derivation of perspective projection transformation and related applications
- Richard Behrman, the founder of dynamic planning
- CAP 6.1 版本发布通告
- Nat. Rev. Drug Discov. | Application of AI in small molecule drug discovery: an upcoming wave?
- flex布局语法
猜你喜欢

仅需三步学会使用低代码ThingJS与森数据DIX数据对接

2022年茶艺师(中级)操作证考试题库及模拟考试

Comply with medical reform and actively layout -- insight into the development of high-value medical consumables under the background of centralized purchase 2022

Carry forward the past and forge ahead into the future, multiple residuals | densenet (I)

2022G1工业锅炉司炉考题及在线模拟考试

新思科技在《 2022 年 Gartner 应用安全测试关键能力报告》中表现优异 在五个常见用例中荣获最高分
Redis operation set, Zset, hash data types and use of visualization tools

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

vscode常用快捷键

Live broadcast preview | a new era of social interaction, exploring new social experiences in the universe
随机推荐
“禁塑令”下,中宝新材深挖可降解塑料,港交所买单吗?
Facebook AI | learning reverse folding from millions of prediction structures
2022年茶艺师(中级)操作证考试题库及模拟考试
几个对程序员的误解,害人不浅!
Cap version 6.1 Release Notice
NumPy 学习笔记
C#_串口通信项目
Pytorch Foundation (I) -- anaconda and pytorch installation
Create and install the visual studio offline installation package
Attributes of script tag
AIChE | ab initio drug design framework integrating mathematical programming method and deep learning model
Redis operation set, Zset, hash data types and use of visualization tools
Fabric.js 元素被选中时保持原有层级
It has become a unicorn since its establishment one year ago. Tencent didi is the "backer". This year's new unicorn is not simple
MFC basic knowledge and course design ideas
VBA judge whether the file exists and ask for the idea of file backup
新思科技在《 2022 年 Gartner 应用安全测试关键能力报告》中表现优异 在五个常见用例中荣获最高分
Thread interview related questions
Fabric.js 缩放画布
Set up proxy for chocolate