在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,有很多人的照片,如下:

新手一枚,對照著書按部就班地做,對這種意外情況百思不得其解,在此求助各位大大出手相救!感謝!
uj5u.com熱心網友回復:
樓主,你好,我把people = fetch_lfw_people(min_faces_per_person=20, resize=0.7) 這行代碼改為
people = fetch_lfw_people()輸出結果為:(2719, 62, 47),參考一下
uj5u.com熱心網友回復:
你下的人的圖片不全,程式中min_faces_per_person=20,每人需要最少20張,因此不足的人被忽略了。uj5u.com熱心網友回復:
下載完整資料包,然后復制到:C:\Users\xxxx\scikit_learn_data\lfw_home\lfw_funneled,再把C:\Users\xxxi\scikit_learn_data\lfw_home\joblib\sklearn\datasets\_lfw\_fetch_lfw_people目錄的臨時目錄洗掉。重新運行即可。轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/51152.html
標籤:機器視覺
上一篇:dota2 原始碼或者架構
