Skip to content

Applications Guide

Yuval Nirkin edited this page Nov 7, 2018 · 2 revisions

face_swap_single2many

For running the face swap on a pair of images, it's best to first create a configuration file because of the large number of parameters. For this example create a configuration file "test.cfg" under "bin" in the installation directory with the following parameters:

landmarks = ../data/shape_predictor_68_face_landmarks.dat       # path to landmarks model file
model_3dmm_h5 = ../data/BaselFaceModel_mod_wForehead_noEars.h5  # path to 3DMM file (.h5)
model_3dmm_dat = ../data/BaselFace.dat                          # path to 3DMM file (.dat)
reg_model = ../data/3dmm_cnn_resnet_101.caffemodel              # path to 3DMM regression CNN model file (.caffemodel)
reg_deploy = ../data/3dmm_cnn_resnet_101_deploy.prototxt        # path to 3DMM regression CNN deploy file (.prototxt)
reg_mean = ../data/3dmm_cnn_resnet_101_mean.binaryproto         # path to 3DMM regression CNN mean file (.binaryproto)
seg_model = ../data/face_seg_fcn8s_300.caffemodel               # path to face segmentation CNN model file (.caffemodel)
seg_deploy = ../data/face_seg_fcn8s_300_deploy.prototxt         # path to face segmentation CNN deploy file (.prototxt)
generic = 0                                  # use generic mode (disable shape regression)
expressions = 1                              # use expression regression
gpu = 0                                      # toggle GPU / CPU
gpu_id = 0                                   # GPU's device id
reverse = 0                                  # reverse swap direction
cache = 1                                    # cache intermediate face data
source_seg = 1                               # toggle sources segmentation
target_seg = 1                               # toggle targets segmentation
source_max_res = 500                         # sources max resolution
target_max_res = 500                         # targets max resolution
verbose = 2                                  # 1 += overlay image, 2 += debug image
sources= ../data/images/brad_pitt_01.jpg     # list of source images or source directory
targets = ../data/images/bruce_willis_01.jpg # list of target images or target directory
output = .                                   # output directory

Now run the following commands:

cd path/to/face_swap/bin
face_swap_single2many --cfg test.cfg

Similarly set the parameters "sources" and "targets" to directories to swap all possible pairs between them.

face_swap_image

Prepare "test.cfg" under "bin" in the installation directory with the following parameters:

landmarks = ../data/shape_predictor_68_face_landmarks.dat       # path to landmarks model file
model_3dmm_h5 = ../data/BaselFaceModel_mod_wForehead_noEars.h5  # path to 3DMM file (.h5)
model_3dmm_dat = ../data/BaselFace.dat                          # path to 3DMM file (.dat)
reg_model = ../data/3dmm_cnn_resnet_101.caffemodel              # path to 3DMM regression CNN model file (.caffemodel)
reg_deploy = ../data/3dmm_cnn_resnet_101_deploy.prototxt        # path to 3DMM regression CNN deploy file (.prototxt)
reg_mean = ../data/3dmm_cnn_resnet_101_mean.binaryproto         # path to 3DMM regression CNN mean file (.binaryproto)
seg_model = ../data/face_seg_fcn8s.caffemodel                   # path to face segmentation CNN model file (.caffemodel)
seg_deploy = ../data/face_seg_fcn8s_deploy.prototxt             # path to face segmentation CNN deploy file (.prototxt)
generic = 0                                 # use generic mode (disable shape regression)
expressions = 1                             # use expression regression
gpu = 1                                     # toggle GPU / CPU
gpu_id = 0                                  # GPU's device id
verbose = 1                                 # 1 = before blend image, 2 += projected meshes, 3 += landmarks, 4 += meshes ply
input = ../data/images/brad_pitt_01.jpg     # source image
input = ../data/images/bruce_willis_01.jpg  # target image
output = out.jpg                            # output image or directory

Now run the following commands:

cd path/to/face_swap/bin
face_swap_image --cfg test.cfg

face_swap_batch

For running the face swap on a list of images, prepare a csv file in which each line contains the paths to a pair of images, separated by a comma. For this example create a file "img_list.csv" like the following:

../data/images/brad_pitt_01.jpg,../data/images/bruce_willis_01.jpg
../data/images/bruce_willis_01.jpg,../data/images/brad_pitt_01.jpg

Replace the input and output parameters from "test.cfg" from the previous section with the following:

log = test.log                              # path to log file
input = img_list.csv                        # list file or directory
output = .                                  # output directory

Now run the following commands:

cd path/to/face_swap/bin
face_swap_batch --cfg test.cfg

It's also possible to run on entire image directories. In that case all possible pairs will be processed. Just specify a directory in the input parameter for face_swap_batch.

Clone this wiki locally