在jupyter notebook中运行,Mac电脑,python语言,源代码如下:
from sklearn.datasets import fetch_lfw_people
people = fetch_lfw_people(min_faces_per_person=20, resize=0.7)
image_shape = people.images[0].shape
fig, axes = plt.subplots(2, 5, figsize=(15, 8),
subplot_kw={'xticks': (), 'yticks': ()})
for target, image, ax in zip(people.target, people.images, axes.ravel()):
ax.imshow(image)
ax.set_title(people.target_names[target])
下一段代码
print("people.images.shape: {}".format(people.images.shape))
print("Number of classes: {}".format(len(people.target_names)))
运行结果为
people.images.shape: (67, 87, 65)
Number of classes: 2
最后一段代码
# count how often each target appears
counts = np.bincount(people.target)
# print counts next to target names:
for i, (count, name) in enumerate(zip(counts, people.target_names)):
print("{0:25} {1:3}".format(name, count), end=' ')
if (i + 1) % 3 == 0:
print()
结果为
Gloria Macapagal Arroyo 44 Tiger Woods 23
可见程序所访问的人脸库只有67张照片,只有两个人。
书上给出的运行结果如以下两张图所示:
访问人脸库所在文件夹,可以看到有200多M,有很多人的照片,如下:
新手一枚,对照着书按部就班地做,对这种意外情况百思不得其解,在此求助各位大大出手相救!感谢!