Based on https://github.com/datitran/face2face-demo
This is a pix2pix demo that learns from facial landmarks and translates this into a face. A webcam-enabled application is also provided that translates your face to the trained face in real-time.
# Clone this repo
git clone https://github.com/Heonozis/ShrekNET
# Create the conda environment from file (Mac OSX)
pip install -r requirements.txt
python generate_train_data.py --file angela_merkel_speech.mp4 --num 400 --landmark-model shape_predictor_68_face_landmarks.dat
Input:
fileis the name of the video file from which you want to create the data set.numis the number of train data to be created.landmark-modelis the facial landmark model that is used to detect the landmarks. A pre-trained facial landmark model is provided here.
Output:
- Two folders
originalandlandmarkswill be created.
# Resize original images
python tools/process.py \
--input_dir photos/original \
--operation resize \
--output_dir photos/original_resized
# Resize landmark images
python tools/process.py \
--input_dir photos/landmarks \
--operation resize \
--output_dir photos/landmarks_resized
# Combine both resized original and landmark images
python tools/process.py \
--input_dir photos/landmarks_resized \
--b_dir photos/original_resized \
--operation combine \
--output_dir photos/combined
# Split into train/val set
python tools/split.py \
--dir photos/combined
# Train the model on the data
python pix2pix.py \
--mode train \
--output_dir face2face-model \
--max_epochs 200 \
--input_dir photos/combined/train \
--which_direction AtoB
For more information around training, have a look at Christopher Hesse's pix2pix-tensorflow implementation.
-
First, we need to reduce the trained model so that we can use an image tensor as input:
python reduce_model.py --model-input face2face-model --model-output face2face-reduced-modelInput:
model-inputis the model folder to be imported.model-outputis the model (reduced) folder to be exported.
Output:
- It returns a reduced model with less weights file size than the original model.
-
Second, we freeze the reduced model to a single file.
python freeze_model.py --model-folder face2face-reduced-modelInput:
model-folderis the model folder of the reduced model.
Output:
- It returns a frozen model file
frozen_model.pbin the model folder.
python run_webcam.py --source 0 --show 0 --landmark-model shape_predictor_68_face_landmarks.dat --tf-model face2face-reduced-model/frozen_model.pb
Input:
sourceis the device index of the camera (default=0).showis an option to either display the normal input (0) or the facial landmark (1) alongside the generated image (default=0).landmark-modelis the facial landmark model that is used to detect the landmarks.tf-modelis the frozen model file.