-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask0.py
47 lines (40 loc) · 1.26 KB
/
task0.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import matplotlib.pyplot as plt
import sklearn
import sklearn.datasets
import pickle
import elbp
import hog
import moments_of_color
def dump_dataset():
olivetti_faces_dataset = sklearn.datasets.fetch_olivetti_faces(
data_home=None,
shuffle=False,
random_state=0,
download_if_missing=True
)
images, targets = olivetti_faces_dataset['images'], olivetti_faces_dataset['target']
counter = 0
images_dir = os.path.join(os.getcwd(), 'images')
if not os.path.isdir(images_dir):
os.mkdir(images_dir)
image_map = {}
for image, target in zip(images, targets):
image_id = 'image_%s_%s' % (target, counter % 10)
plt.imsave(
'%s/%s.png' % (images_dir, image_id),
image,
cmap='gray'
)
image_map[image_id] = {
'image': image,
'color_moment': moments_of_color.get_cm_vector(image),
'elbp': elbp.get_elbp_vector(image),
'hog': hog.get_hog_vector(image)
}
counter += 1
pickle_path = '%s/dataset_meta.pickle' % images_dir
with open(pickle_path, 'wb') as handle:
pickle.dump(image_map, handle, protocol=pickle.HIGHEST_PROTOCOL)
if __name__=='__main__':
dump_dataset()