summaryrefslogtreecommitdiff
path: root/site/content/pages/datasets/lfw/assets/fetch_lfw_people.py
blob: 639883a69990a79ef9e5edb078cb9ab42335425f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python

# ------------------------------------------------------------
#
# Script to generate montage of LFW faces used in scikit-learn
#
# ------------------------------------------------------------

import numpy as np
from sklearn.datasets import fetch_lfw_people
import imageio
import imutils

# download LFW dataset (first run takes a while)
lfw_people = fetch_lfw_people(min_faces_per_person=1, resize=1, color=True, funneled=False)

# introspect dataset
n_samples, h, w, c = lfw_people.images.shape
print(f'{n_samples:,} images at {w}x{h} pixels')
cols, rows = (176, 76)
n_ims = cols * rows

# build montages
im_scale = 0.5
ims = lfw_people.images[:n_ims]
montages = imutils.build_montages(ims, (int(w * im_scale,   int(h * im_scale)), (cols, rows))
montage = montages[0]

# save full montage image
imageio.imwrite('lfw_montage_full.png', montage)

# make a smaller version
montage = imutils.resize(montage, width=960)
imageio.imwrite('lfw_montage_960.jpg', montage)