特征脸技术是近期发展起来的用于人脸或者一般性刚体识别以及其它涉及到人脸处理的一种方法。首先把一批人脸图像转换成一个特征向量集,称为“Eigenfaces”,即“特征脸”,它们是最初训练图像集的基本组件。识别的过程是把一副新的图像投影到特征脸子空间,并通过它的投影点在子空间的位置以及投影线的长度来进行判定和识别。
将图像变换到另一个空间后,同一个类别的图像会聚到一起,不同类别的图像会聚力比较远,在原像素空间中不同类别的图像在分布上很难用简单的线或者面切分,变换到另一个空间,就可以很好的把他们分开了。Eigenfaces选择的空间变换方法是PCA(主成分分析),利用PCA得到人脸分布的主要成分,具体实现是对训练集中所有人脸图像的协方差矩阵进行本征值分解,得到对应的本征向量,这些本征向量就是“特征脸”。每个特征向量或者特征脸相当于捕捉或者描述人脸之间的一种变化或者特性。这就意味着每个人脸都可以表示为这些特征脸的线性组合。
下面就直接给出基于特征脸的人脸识别实现过程:
原始图像投影到该特征空间中。特别说明,此时的原始图像x存成大小是n维的向量,即:
训练集为(这里p为样本图像数量),形成矩阵X[n][p],其中行代表像元,列代表每幅人脸图像。
将训练样本集中的人脸图像减去平均人脸图像,计算离散差值,将训练图像中心化。
将中心化之后图像组成一个大小为n×p的矩阵X:
将中心化后的图像组成的矩阵X乘以它的转置矩阵得到协方差矩阵Ω:
求解协方差矩阵Ω的k个非零特征值,以及所对应的特征向量,一般来说,训练图像数量p远远小于一幅图像的像素值n,所以协方差矩阵Ω最多有对应于非零特征值的p个特征向量,所以k≤p.按照特征值的从大到小的顺序排列特征向量,对应于最大特征值的特征向量反应了训练图像间的最大差异,而对应的特征值越小的特征向量,反应的图像间的差异越小。所有的非零特征值对应的特征向量,组成特征空间,也就是所谓的“特征脸”空间。
      计算特征值和特征向量,其中U为对应于特征值的特征向集。排列特征向量:按照非零特征值,从大到小的顺序,将对应的特征向量排列。所组成的特征向量矩阵即为特征空间U,U的每一列为一个特征向量:
          
    这样每一幅人脸图像都可以投影到由张成的子空间中。因此每一幅人脸图像对应于子空间中的一个点,同样,子空间中的每个点对应于一幅图像,下图显示的是所对应的图像,由于这些图像很像人脸,所以它们被称为“特征脸”。
 
 特征脸
    训练图像投影得到特征脸子空间
    有了这样一个由“特征脸”组成的降维特征子空间,任何一幅中心化后的人脸图像都可以通过下面的式子投影到特征脸子空间并获得一组坐标系数:

本文采用的数据集为“Labeled Faces in the Wild”, aka LFW: http://vis-www.cs.umass.edu/lfw/lfw-funneled.tgz (233MB)

下面结合Eigenfaces和SVM进行人脸识别:

Python源码:

from __future__ import print_functionfrom time import time
import logging
import matplotlib.pyplot as pltfrom sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import fetch_lfw_people
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.decomposition import PCA
from sklearn.svm import SVCprint(__doc__)# Display progress logs on stdout
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')# #############################################################################
# Download the data, if not already on disk and load it as numpy arrayslfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4)# introspect the images arrays to find the shapes (for plotting)
n_samples, h, w = lfw_people.images.shape# for machine learning we use the 2 data directly (as relative pixel
# positions info is ignored by this model)
X = lfw_people.data
n_features = X.shape[1]# the label to predict is the id of the person
y = lfw_people.target
target_names = lfw_people.target_names
n_classes = target_names.shape[0]print("Total dataset size:")
print("n_samples: %d" % n_samples)
print("n_features: %d" % n_features)
print("n_classes: %d" % n_classes)# #############################################################################
# Split into a training set and a test set using a stratified k fold# split into a training and testing set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)# #############################################################################
# Compute a PCA (eigenfaces) on the face dataset (treated as unlabeled
# dataset): unsupervised feature extraction / dimensionality reduction
n_components = 150print("Extracting the top %d eigenfaces from %d faces"% (n_components, X_train.shape[0]))
t0 = time()
pca = PCA(n_components=n_components, svd_solver='randomized',whiten=True).fit(X_train)
print("done in %0.3fs" % (time() - t0))eigenfaces = pca.components_.reshape((n_components, h, w))print("Projecting the input data on the eigenfaces orthonormal basis")
t0 = time()
X_train_pca = pca.transform(X_train)
X_test_pca = pca.transform(X_test)
print("done in %0.3fs" % (time() - t0))# #############################################################################
# Train a SVM classification modelprint("Fitting the classifier to the training set")
t0 = time()
param_grid = {'C': [1e3, 5e3, 1e4, 5e4, 1e5],'gamma': [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.1], }
clf = GridSearchCV(SVC(kernel='rbf', class_weight='balanced'), param_grid)
clf = clf.fit(X_train_pca, y_train)
print("done in %0.3fs" % (time() - t0))
print("Best estimator found by grid search:")
print(clf.best_estimator_)# #############################################################################
# Quantitative evaluation of the model quality on the test setprint("Predicting people's names on the test set")
t0 = time()
y_pred = clf.predict(X_test_pca)
print("done in %0.3fs" % (time() - t0))print(classification_report(y_test, y_pred, target_names=target_names))
print(confusion_matrix(y_test, y_pred, labels=range(n_classes)))# #############################################################################
# Qualitative evaluation of the predictions using matplotlibdef plot_gallery(images, titles, h, w, n_row=3, n_col=4):"""Helper function to plot a gallery of portraits"""plt.figure(figsize=(1.8 * n_col, 2.4 * n_row))plt.subplots_adjust(bottom=0, left=.01, right=.99, top=.90, hspace=.35)for i in range(n_row * n_col):plt.subplot(n_row, n_col, i + 1)plt.imshow(images[i].reshape((h, w)), cmap=plt.cm.gray)plt.title(titles[i], size=12)plt.xticks(())plt.yticks(())# plot the result of the prediction on a portion of the test setdef title(y_pred, y_test, target_names, i):pred_name = target_names[y_pred[i]].rsplit(' ', 1)[-1]true_name = target_names[y_test[i]].rsplit(' ', 1)[-1]return 'predicted: %s\ntrue:      %s' % (pred_name, true_name)prediction_titles = [title(y_pred, y_test, target_names, i)for i in range(y_pred.shape[0])]plot_gallery(X_test, prediction_titles, h, w)# plot the gallery of the most significative eigenfaceseigenface_titles = ["eigenface %d" % i for i in range(eigenfaces.shape[0])]
plot_gallery(eigenfaces, eigenface_titles, h, w)plt.show()

Result:

人脸识别之特征脸方法相关推荐

  1. 人脸识别之特征脸方法(Eigenface)

    人脸识别之特征脸方法(Eigenface) zouxy09@qq.com http://blog.csdn.net/zouxy09 因为需要,花了一点时间写了下经典的基于特征脸(EigenFace)的 ...

  2. Python机器学习:PCA与梯度上升:009人脸识别与特征脸(lfw_people数据集)

    将w的每一行想成一个样本,则第一行是最重要的样本..第二行次重要..(Wk特征engen face) CODE 我们使用lfw_people数据集 #人脸识别与特征脸 import numpy as ...

  3. 人脸识别—特征脸方法

    人脸识别之特征脸方法(Eigenface) zouxy09@qq.com http://blog.csdn.net/zouxy09 因为需要,花了一点时间写了下经典的基于特征脸(EigenFace)的 ...

  4. 人脸识别经典算法一:特征脸方法(Eigenface)

    这篇文章是撸主要介绍人脸识别经典方法的第一篇,后续会有其他方法更新.特征脸方法基本是将人脸识别推向真正可用的第一种方法,了解一下还是很有必要的.特征脸用到的理论基础PCA在另一篇博客里:特征脸(Eig ...

  5. OpenCV人脸识别之Eigenface算法(PCA特征脸方法)

    Eigenface Eigenfaces就是特征脸的意思,是一种从主成分分析(Principal Component Analysis,PCA)中导出的人脸识别和描述技术.特征脸方法的主要思路就是将输 ...

  6. 人脸识别算法之特征脸方法(Eigenface)

    一.人脸识别算法之特征脸方法(Eigenface) 1.原理介绍及数据收集 特征脸方法主要是基于PCA降维实现. 详细介绍和主要思想可以参考 https://www.cnblogs.com/littl ...

  7. python人脸识别特征脸法_人脸识别经典算法:特征脸方法(Eigenface)

    特征脸方法基本是将人脸识别推向真正可用的第一种方法,了解一下还是很有必要的.特征脸用到的理论基础PCA在之前的文章中已经讲过了.直接上特征脸方法的步骤: 步骤一:获取包含M张人脸图像的集合S.在我们的 ...

  8. python人脸识别特征脸法_人脸识别经典算法一 特征脸方法(Eigenface)

    这篇文章是撸主要介绍人脸识别经典方法的第一篇,后续会有其他方法更新.特征脸方法基本是将人脸识别推向真正可用的第一种方法,了解一下还是很有必要的.特征脸用到的理论基础PCA在另一篇博客里:特征脸(Eig ...

  9. matlab怎么显示特征脸,matlab表情识别 Matlab表情识别,特征脸[1 ]作为面部表情分类的方法 联合开发网 - pudn.com...

    matlab表情识别 所属分类:其他 开发工具:matlab 文件大小:4575KB 下载次数:23 上传日期:2019-03-11 20:20:45 上 传 者:bbqQq 说明:  Matlab表 ...

最新文章

  1. ps grep java_ps -ef | grep java 查看所有关于java的进程
  2. CentOS7内核升级
  3. API接口通讯参数规范
  4. Effective C++ --4 设计与声明
  5. 在PyPI上发布自己的python包
  6. bashrc, bash_profile etc;
  7. v-if 表单验证_避免许多if块进行验证检查
  8. RocketMQ 端云一体化设计与实践
  9. uv转化率多少正常_宣城UV光解设备价格多少-低价供应
  10. HTML的基本知识(五)——无序列表、有序列表、自定义列表
  11. 国外游戏开发商吐槽:开发VR游戏付账单的钱都赚不到
  12. linux之ssh-keygen命令
  13. Atitit SpringCloud 使用总结 目录 1.1. 启动一个服务注册中心EurekaServer 1 1.2. 三、创建一个服务提供者 (eureka client) 2 1.3. 创建
  14. java 代码走查_代码走查如何保证软件质量
  15. 工程实践线切割3B代码参考
  16. PIC单片机开发环境的搭建总结及新上手单片机平台如何实现快速开发的几点经验分享
  17. 【AI视野·今日NLP 自然语言处理论文速览 第三十三期】Thu, 21 Apr 2022
  18. 《随笔二十二》—— C++中的“ 函数模板 和 类模板 ”
  19. 女生学前端适合么?新人应该怎么学习?
  20. 作为程序员的硬实力是什么 ?

热门文章

  1. ICLR 2022 不求甚解阅读笔记--强化学习类(1)
  2. 如何走好知识变现第一步
  3. 【车载】功能安全中FSR TSR的区别
  4. ubuntu 设置中文环境
  5. Arduino I2C + 三轴加速度计ADXL345
  6. 孵化器行业拓客的10个经典方法
  7. 音频数字信号和模拟信号
  8. 智能肉温度计的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  9. IDEA 主题,四款牛x炫酷的主题,非常哇塞!
  10. P4编程理论与实践——理论篇(转载)