![a25150517ca6439dedbc179229629513.png](https://img-blog.csdnimg.cn/img_convert/a25150517ca6439dedbc179229629513.png)
点击蓝字关注我哦
![bbce1b106342a471634eca98155d7161.png](https://img-blog.csdnimg.cn/img_convert/bbce1b106342a471634eca98155d7161.png)
![39a2a45e2c4c3fd9fff8be10f7a30c27.gif](https://img-blog.csdnimg.cn/img_convert/39a2a45e2c4c3fd9fff8be10f7a30c27.gif)
一、使用LFW数据库作为训练的数据集
![5c6bb4c93f79dbebeec156feac659c8c.gif](https://img-blog.csdnimg.cn/img_convert/5c6bb4c93f79dbebeec156feac659c8c.gif)
from sklearn.datasets import fetch_lfw_peoplefaces = fetch_lfw_people(min_faces_per_person=60)print(faces.target_names)print(faces.images.shape)
fetch_lfw_people: load the labeled faces in the Wild(LFW) people dataset(classification).
这篇短文中使用的人脸数据样本来自于”Labeled Faces in the Wild (LFW)”,这是一个用于学习人脸识别问题的人脸照片数据库。这个数据库由University of Massachusetts的研究员Amherst创立和维护,数据库中包含5749个人的13233张图片。
换句话说dataset里面含有的classes有5749个,一共有13233个samples, dimensionality:5828个,features:0-255(用来表示颜色的参数R G B三原色每个参数取值范围都是0-255)
min_faces_per_person:提取的数据集中每个人将保留具有至少有min_faces_per_person个不同图片。Returns: 返回的faces包含下面的四项内容:
data (13233,2914): 返回的data那个矩阵shape为13233x2914,每一行对应一个原始尺寸为62x47的人脸图像images(13233,62,47):每一行对应5749个人中某一个人的人脸图像数据。
target(13233,):每一个人脸图像对应的标签,从0到5478,一个数字对应一个人的ID。
Target_Names:target中的每个人的ID对应的个人的姓名,将个人ID和个人姓名一一对应起来。
DESCR:一段关于LFW数据库的描述性文字。
import matplotlib.pyplot as pltfig, ax = plt.subplots(3, 5) #产生三行五列个subplot.for i, axi in enumerate(ax.flat): axi.imshow(faces.images[i], cmap='bone') axi.set(xticks=[], yticks=[], xlabel=faces.target_names[faces.target[i]])plt.show()
举个小例子:
我们产生一个2行3列的array:
![4943afed6f974771e8d4077803b1bad4.png](https://img-blog.csdnimg.cn/img_convert/4943afed6f974771e8d4077803b1bad4.png)
然后我们用list() function分别列出这个array以及这个array.flat之后的结果:
很明显的差别,x.flat之后它变成了一个一维的iterator, iterator is an object which used to iterate over an iter