今天讲解如何运用统计学主成分分析方法来建立人脸识别模型。模型运行如下图,可准确识别大部分人脸。

人脸数据是图像,但图像可以转换为数字,课程里,我们把每个人脸图形转换为1850个维度数据。

Eigenface特征面
人脸识别应用中,Eigenface特征面是一个核心概念,必须了解。Eigenface是在人脸识别的计算机视觉问题中使用的一组特征向量的名称。
利用特征面进行识别的方法是Sirovich和Kirby(1987)开发的,并被Matthew Turk和Alex Pentland在人脸分类中使用。
特征向量来源于人脸图像高维向量空间上概率分布的协方差矩阵。特征面本身构成了所有用于构造协方差矩阵的图像的基集。

我们通过PCA生成特征脸,把1850个维度数据降低到100个维度左右。

 

PCA主成分降维在人脸识别应用-附代码_python

下图是课程python脚本,已经调试好,可以直接运行。 

如下图,模型输出结果非常棒,混淆矩阵的值都非常高,说明模型性能很好。

Total dataset size:
n_samples: 1288
n_features: 1850
n_classes: 7
Extracting the top 150 eigenfaces from 966 faces
done in 0.215s
Projecting the input data on the eigenfaces orthonormal basis
done in 0.023s
Fitting the classifier to the training set
done in 23.334s
Best estimator found by grid search:
SVC(C=1000.0, cache_size=200, class_weight='balanced', coef0=0.0,
decision_function_shape='ovr', degree=3, gamma=0.001, kernel='rbf',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False)
Predicting people's names on the test set
done in 0.049s
precision recall f1-score support

Ariel Sharon 0.50 0.69 0.58 13
Colin Powell 0.80 0.85 0.82 60
Donald Rumsfeld 0.69 0.74 0.71 27
George W Bush 0.91 0.89 0.90 146
Gerhard Schroeder 0.82 0.72 0.77 25
Hugo Chavez 0.83 0.67 0.74 15
Tony Blair 0.88 0.83 0.86 36

avg / total 0.84 0.83 0.83 322

[[ 9 0 3 1 0 0 0]
[ 2 51 2 4 0 1 0]
[ 5 0 20 2 0 0 0]
[ 2 8 2 130 3 0 1]
[ 0 1 0 3 18 1 2]
[ 0 2 0 1 1 10 1]
[ 0 2 2 2 0 0 30]]

 

欢迎学习完整知识《python实战因子分析和主成分分析》

​https://edu.51cto.com/course/28044.html​

PCA主成分降维在人脸识别应用-附代码_python_02