Face Swap implementation by PiktID, also available online at swap.piktid.com
This implementation relies on the EraseID infrastructure and APIs. Check more on EraseID web-application.
The following instructions suppose you have already installed a recent version of Python. For a general overview, please visit the API documentation. To use any PiktID API, an access token is required. Moreover, PiktID is currently manually granting access to users.
Step 0 - Register here. 10 credits are given for free to all new users.
Step 1 - Clone the SwapID library
# Installation commands
$ git clone https://github.com/piktid/swapid.git
$ cd swapid
Step 2 - Export the email and password as environmental variables
$ export SWAPID_EMAIL={Your email here}
$ export SWAPID_PASSWORD={Your password here}
Step 3 - You can provide both the absolute path of the target and face image (containing a person). Add the arguments
...
--target_path 'mydir/mytarget.jpg'
or
--face_path 'mydir/mysource.jpg'
...
Alternatively, you can provide the url of the target and face image, as in the default example with the Einstein face on the Monalisa image.
...
--target_url 'https://images.piktid.com/frontend/studio/swapid/target/monalisa.jpg'
or
--face_url 'https://images.piktid.com/frontend/studio/swapid/face/einstein.jpg'
...
Step 4 - Run the main function with the selected endpoint
$ python3 main_swap.py --target_path 'mydir/mytarget.jpg' --face_path 'mydir/mysource.jpg'
Without any additional argument, SwapID will upload both images into PiktID's servers and provide (read the logs) the codes for both images, which you can reuse for further re-generations, one for the target 'abc' and one for the face 'xyz'. The swap asynchronously elaborates your images. It reads the notifications, and once the swap process is over, it extracts the link of the swapped image.
Step 5 - Rerun the main function with PiktID's codes
$ python3 main_swap.py --target_name 'abc' --face_name 'xyz'
Step 6 - Play with the parameters
If the result is not satisfactory enough, we recommend either changing the seed or strength of the source image (lower strength results in low influence of the source on the output)
$ python3 main_swap.py --target_name 'abc' --face_name 'xyz' --seed 1234 --strength '0.55'
Step 7 - Multiple faces
If you have a target image with multiple subjects, you need to inform the system, via the idx_face integer argument, which face to swap. As an example:
$ python3 main_swap.py --target_path 'mydir/mytarget.jpg' --face_path 'mydir/mysource.jpg' --idx_face 0
It is also possible to include the hair in the swapping process. To do that, you need to run the command
$ python3 main_swap.py --target_path 'mydir/mytarget.jpg' --face_path 'mydir/mysource.jpg' --hair
Please contact us for more details.