SVM:根据大量图片来精确实现人脸识别—Jason niu
from __future__ import print_function
from time import time
import logging
import matplotlib.pyplot as plt from sklearn.cross_validation import train_test_split
from sklearn.datasets import fetch_lfw_people
from sklearn.grid_search import GridSearchCV
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.decomposition import RandomizedPCA
from sklearn.svm import SVC print(__doc__) logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s') ############################################################################### lfw_people = fetch_lfw_people(min_faces_per_person=99, resize=0.4) n_samples, h, w = lfw_people.images.shape X = lfw_people.data
n_features = X.shape[1] 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) ############################################################################### X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25) ###############################################################################
n_components = 150 print("Extracting the top %d eigenfaces from %d faces"
% (n_components, X_train.shape[0]))
t0 = time()
pca = RandomizedPCA(n_components=n_components, 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)) ###############################################################################
print("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) #auto改为balanced 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_) ###############################################################################
print("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))) def 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(()) def 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) eigenface_titles = ["eigenface %d" % i for i in range(eigenfaces.shape[0])]
plot_gallery(eigenfaces, eigenface_titles, h, w)
plt.show()
SVM:根据大量图片来精确实现人脸识别—Jason niu的更多相关文章
- 机器学习 - 算法 - SVM 支持向量机 Py 实现 / 人脸识别案例
SVM 代码实现展示 相关模块引入 %matplotlib inline import numpy as np import matplotlib.pyplot as plt from scipy i ...
- 机器学习实战:用nodejs实现人脸识别
机器学习实战:用nodejs实现人脸识别 在本文中,我将向你展示如何使用face-recognition.js执行可靠的人脸检测和识别 . 我曾经试图找一个能够精确识别人脸的Node.js库,但是 ...
- 【《zw版·Halcon与delphi系列原创教程》 zw_halcon人脸识别
[<zw版·Halcon与delphi系列原创教程>zw_halcon人脸识别 经常有用户问,halcon人脸识别方面的问题. 可能是cv在人脸识别.车牌识别方面的投入太多了. 其实,人脸 ...
- PCA人脸识别
人脸数据来自http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html 实现代码和效果如下.由于图片数量有限(40*10),将原 ...
- 人脸识别必读的N篇文章
一,人脸检测/跟踪 人脸检测/跟踪的目的是在图像/视频中找到各个人脸所在的位置和大小:对于跟踪而言,还需要确定帧间不同人脸间的对应关系. 1, Robust Real-time Object Dete ...
- DeepID人脸识别算法之三代(转)
DeepID人脸识别算法之三代 转载请注明:http://blog.csdn.net/stdcoutzyx/article/details/42091205 DeepID,目前最强人脸识别算法,已经三 ...
- DeepFace--Facebook的人脸识别(转)
DeepFace基本框架 人脸识别的基本流程是: detect -> aligh -> represent -> classify 人脸对齐流程 分为如下几步: a. 人脸检测,使用 ...
- openFace 人脸识别框架测试
openface 人脸识别框架 但个人感觉精度还是很一般 openface的githup文档地址:http://cmusatyalab.github.io/openface/ openface的安 ...
- OpenCV+python 人脸识别
首先给大家推荐一本书:机器学习算法原理与编程实践 本文内容全部转载于书中,相当于一个读书笔记了吧 绪论 1992年麻省理工学院通过实验对比了基于结构特征的方法与基于模版匹配的方法,发现模版匹配的方法要 ...
随机推荐
- 如何为 Jupyter Notebook 安装代码提示功能
按照上一篇博客安装完 Python 和 Jupyter Notebook 后,我们已经可以使用 Notebook 愉快的编写 Python 代码了,但是发现它不像其他编辑器那样会弹出代码提示,这稍微有 ...
- JGUI源码:实现简单进度条(19)
程序效果如下 实现进度条动画主要有两种方法:(1)使用缓动,(2)使用Jquery Animate,本文使用第二种方法,先实现代码,后续进行控件封装 <style> .jgui-proce ...
- 《11招玩转网络安全》之第三招:Web暴力破解-Low级别
Docker中启动LocalDVWA容器,准备DVWA环境.在浏览器地址栏输入http://127.0.0.1,中打开DVWA靶机.自动跳转到了http://127.0.0.1/login.php登录 ...
- Window7 定制 Explore中的右键菜单
win+R 命令 运行 regedit ,打开注册表 在 HKEY_CLASSES_ROOT\*\shell\VisualCode下创建针对文件的新增命令 command 在HKEY_CLASSE ...
- JavaScript之深入理解【函数】
一 参考文献 <JavaScript忍者秘籍> 二 函数特征总结 1. 函数是[第一型对象(first-class object)]:可以像这门语言的其它对象一样使用 函数可以共处,可 ...
- 开启Apache的server status监测
从httpd.conf 打开 status_module#LoadModule status_module modules/mod_status.so修改成LoadModule status_modu ...
- hihocoder 1175
拓扑排序 hihocoder 1175 拓扑只适用于 有向无环图中,这个指的是 1.有向的,不是那种双向可走的 2.无环,并不是不存在环,而是一定要有一个没有其他点指向这个点的点, 题目大意:一个有向 ...
- 项目Alpha冲剂(3/10)
1.项目燃尽图 2.今日进度描述 项目进展 完成数据库和服务器的连接部分,完成了一些应用的基本功能. 问题困难 完成了服务器的成功配置,同时实现了客户端与服务器的连接 心得体会 进度有明显的变化,成员 ...
- hibernate核心类及常用方法
Configuration configure = new Configuration().configure(); SessionFactory factory = configure.buildS ...
- kafka 重新分配partition
登陆kafka manager 进入相关topic 点击generate partition assignments 点击reassign partirons