Skip to content

Commit

Permalink
Added an error message when landmark file is missing. (deepfakes#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yutsa authored and Ganonmaster committed Dec 23, 2017
1 parent c357559 commit f0c971e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/faces_process.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import cv2
import numpy
import os

from .aligner import Aligner
from .model import autoencoder_A
from .model import autoencoder_B
from .model import encoder, decoder_A, decoder_B


def convert_one_image(image, model_dir="models"):

encoder.load_weights(model_dir + "/encoder.h5")
decoder_A.load_weights(model_dir + "/decoder_A.h5")
decoder_B.load_weights(model_dir + "/decoder_B.h5")

autoencoder = autoencoder_B

# landmark file can be found in http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
# unzip it in the same folder as the main scripts
aligner = Aligner("contrib/shape_predictor_68_face_landmarks.dat", "contrib/mmod_human_face_detector.dat")

shapePredictor = "contrib/shape_predictor_68_face_landmarks.dat"
humanFaceDetector = "contrib/mmod_human_face_detector.dat"
if not os.path.exists(shapePredictor):
print("{} file not found.\n"
"Landmark file can be found in http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2"
"\nUnzip it in the contrib/ folder.".format(shapePredictor))
return
aligner = Aligner(shapePredictor, humanFaceDetector)

assert image.shape == (256, 256, 3)
crop = slice(48, 208)
Expand All @@ -34,6 +41,7 @@ def convert_one_image(image, model_dir="models"):
# else:
# return result


def superpose(image, new_face, crop):
new_image = image.copy()
new_image[crop, crop] = new_face
Expand Down

0 comments on commit f0c971e

Please sign in to comment.