Skip to content

A set of tools and utils to operate face swapping and explore creative usage of derived artifacts.

License

Notifications You must be signed in to change notification settings

5agado/face-swap

Repository files navigation

Face Swap

A set of tools and utils to operate face swapping and explore creative usage of derived artifacts.

Setup

Install via (requires python > 3.4)

python setup.py [develop]

Notice that the project depends on another repository of mine for reusable utils and modules. This dependency should be installed via the previous command, but if you encounter any problem you can run

git clone https://github.com/5agado/data-science-learning.git
cd data-science-learning
pip install .

Configuration settings and models location should be specified in models.cfg.

Run

Scripts

scripts.sh provides a simplified interface to various operations and setup based on video conversion. Requires a workdir containing a video file (i.e. .gif, .webm, mp4) and requires ffmpeg to be installed on the machine.

Init dir (required step). Creates required folders

./scripts.sh -w ~/workdir/path -i

Extract faces (relies on params set in models.cfg)

./scripts.sh -w ~/workdir/path -e

Swap faces and create video (relies on params set in models.cfg)

./scripts.sh -w ~/workdir/path -s

Python Commands

As an alternative to the calling scripts you can rely directly on Python commands installed during initial setup.

Faces Extract

extract -i dir/to/video -o output/dir/faces

Faces Swap

deep_swap -i dir/to/video -o output/video/path -A -model_name base_gan -model_version v0

Train

You can train a new model by using train.py. See train.py -h for more info.

Otherwise I would suggest to rely on Google Colaboratory, which provides a free GPU environment accessible via Jupyter. See my related notebook which installs all the required dependencies and then provides basic interface to the training functions.

Resources

This code is colossally based on shaoanlu repo and work. I tried to give it a bit more structure, and add comments and pointers for new comers to better understand what exactly is going on.

Other useful references for code and techniques for pre and post-processing phases:

Docker

You can also build a Docker image (complete of all requirement code and utils) via

docker build -t faceswap .

Start image and exec bash

docker run -it faceswap bash

TODO

  • align face -> feed to generator -> detect face in generated image -> align back using landmarks
  • log some stats (frames w w/o faces, faces size, conversion size, execution time of operations)

License

Released under version 2.0 of the Apache License.

About

A set of tools and utils to operate face swapping and explore creative usage of derived artifacts.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published