Spaces:
Runtime error
Runtime error
sandrocalzada
commited on
Commit
·
fedaa13
1
Parent(s):
1a697a4
Create generate.py
Browse files- generate.py +29 -0
generate.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import face_recognition
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
|
6 |
+
PATH_BACKGROUND = 'images_background'
|
7 |
+
PATH_MODEL = 'bin'
|
8 |
+
DATA_IMAGE_PICKLE = 'data_images.pkl'
|
9 |
+
|
10 |
+
print('Loading data from brackground images ...')
|
11 |
+
filename = os.path.join(os.getcwd(), PATH_MODEL, DATA_IMAGE_PICKLE)
|
12 |
+
images_background_encoding = []
|
13 |
+
images_background_names = []
|
14 |
+
images_background_contents = []
|
15 |
+
for filename_image in os.listdir(PATH_BACKGROUND):
|
16 |
+
if filename_image.endswith('.gitkeep'):
|
17 |
+
continue
|
18 |
+
image_path = os.path.join(PATH_BACKGROUND, filename_image)
|
19 |
+
image_loaded = face_recognition.load_image_file(image_path)
|
20 |
+
face_encoding = face_recognition.face_encodings(image_loaded)[0]
|
21 |
+
images_background_encoding.append(face_encoding)
|
22 |
+
images_background_names.append(filename_image)
|
23 |
+
images_background_contents.append(image_loaded)
|
24 |
+
|
25 |
+
data_images = {"names": images_background_names, "encodings": images_background_encoding, 'content':images_background_contents}
|
26 |
+
with open(filename, 'wb') as file:
|
27 |
+
pickle.dump(data_images, file)
|
28 |
+
|
29 |
+
print(f'Generated data from background images on {filename}')
|