DEV Community

Cover image for Deep Fake, Easily made

Deep Fake, Easily made

Refacer is an open source library that allows easy replacement of faces in a video. In this article, I will detail how to use it in order to do exactly that.

Prerequisites

  1. A laptop/desktop device (I suppose even a tablet could work)
  2. A Github Account

You will also need to prepare the files you will need in the refacing process -

  1. Source Video: the original video that you wish to clone; for this tutorial, we’ll use a scene from the “The Harder They Fall.” For the initial test run, I would suggest you use a short video that is a minute-long or even shorter.

  2. Target Face Images: Images of the faces you intend to manipulate. These could be screenshots from the video or other sources. For this tutorial, my target face was that of Cherokee Bill played by LaKeith Stanfield.

  3. Replacement Faces Images: Images of the faces that will replace the original faces in the target video. Please make sure you have the consent to use these pictures / faces from the person. For this tutorial I used my own face.

Refacing

To create the deep fake, we will use the refacer repository available on Github here. Before using the app make sure you have read the disclaimer at the end of this project or on the GitHub repository. You can access the Refacer using a Google colab notebook but since that did not work for me, this tutorial will guide you through the longer route - running the project locally.

Setup

I will assume that you are working on linux or any other unix-based system (as is the Godly thing to do as a developer).

  1. Navigate to the directory you want to store the project in (I recommend creating a new folder altogether)
  2. Download this file inswapper_128.onnx and place it inside the folder you just created.
  3. In the terminal, navigate to the folder you just created
  4. Clone the Rafacer repository from GitHub using the below command: git clone https://github.com/xaviviro/refacer.git
  5. Navigate to the refacer directory by using the command cd refacer if you are on linux/mac or chdir refacer if you are on windows
  6. Open the requirements.txt file and replace gradio==3.33.1 with gradio==3.36.1 and save & close
  7. Install packages: pip install -r requirements.txt
  8. Run the app: python app.py
  9. Finally, open your web browser and navigate to the following address: http://127.0.0.1:7680

The Refacer Interface

On the specified port, you should see an interface that looks like the one below:

Reface User Interface on the Web

The main sections are:

  1. Original Video Upload: Upload the source video to this section.
  2. Target Faces Placement: Place the faces in the video that you want to replace; up to five faces are supported.
  3. Replacement Faces Placement: Position the faces that will replace the corresponding faces uploaded to section (2).
  4. Output File Display: The resulting file will be displayed here.

Upload the required files

Upload the respective files to their designated sections and click “Reface” (The big orange button at the bottom of the page). This action initiates a process that will “reface” all frames in the video using the provided faces. Please note that this process may take some time.

Refacer Interface with uploaded media

You can check the terminal to see progress being made. I would also recommend that if you have a light-weight device, you could close all other running apps and leave the device for refacing.

Accessing your video

Your output/refaced video will be in the /out folder. For the full path, please check your terminal. You can also view the refaced video on the browser.

Sharing

Please be sure to share your refaced video like I did here and if you can, tag me!

Till next time comrades, may the force be with you!

Top comments (0)