emotions_faceswap / generate.py
sandrocalzada's picture
Create generate.py
fedaa13
raw
history blame contribute delete
No virus
1.08 kB
import os
import face_recognition
import pickle
PATH_BACKGROUND = 'images_background'
PATH_MODEL = 'bin'
DATA_IMAGE_PICKLE = 'data_images.pkl'
print('Loading data from brackground images ...')
filename = os.path.join(os.getcwd(), PATH_MODEL, DATA_IMAGE_PICKLE)
images_background_encoding = []
images_background_names = []
images_background_contents = []
for filename_image in os.listdir(PATH_BACKGROUND):
if filename_image.endswith('.gitkeep'):
continue
image_path = os.path.join(PATH_BACKGROUND, filename_image)
image_loaded = face_recognition.load_image_file(image_path)
face_encoding = face_recognition.face_encodings(image_loaded)[0]
images_background_encoding.append(face_encoding)
images_background_names.append(filename_image)
images_background_contents.append(image_loaded)
data_images = {"names": images_background_names, "encodings": images_background_encoding, 'content':images_background_contents}
with open(filename, 'wb') as file:
pickle.dump(data_images, file)
print(f'Generated data from background images on {filename}')