DEV Community

Sattyam Jain
Sattyam Jain

Posted on

Introducing a Face Replacement Software: Swap Faces in Videos with Ease

With our innovative software, you can effortlessly replace faces in videos using just a single image of your desired face. No need for extensive datasets or training. The process is simple and effective. Check out some demos to see it in action.

Source: ROOP

Installation:

To get started, ensure that you have the following prerequisites installed on your system:

  • Python (and pip, if needed)
  • Git
  • FFmpeg

If you have GPU support, follow the instructions below based on your GPU manufacturer:

AMD (Linux):

Note: AMD GPUs can only be used with Linux.

  1. Install the required dependencies: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.4.2
  2. Uninstall any existing onnxruntime: pip uninstall onnxruntime
  3. Clone the onnxruntime repository: git clone https://github.com/microsoft/onnxruntime && cd onnxruntime
  4. Build and install onnxruntime: ./build.sh --config Release --build_wheel --update --build --parallel --cmake_extra_defines CMAKE_PREFIX_PATH=/opt/rocm/lib/cmake ONNXRUNTIME_VERSION=$ONNXRUNTIME_VERSION onnxruntime_BUILD_UNIT_TESTS=off --use_rocm --rocm_home=/opt/rocm
  5. Install the built package: pip install build/Linux/Release/dist/*.whl

NVIDIA (Windows):

Note: The following instructions are specifically for Windows.

Recommended versions: ONNX Runtime 1.9.0 CUDA EP - CUDA 11.4.3+cuDNN 8.2.4.15

  1. Install the CUDA toolkit from [here].
  2. Install cuDNN from [here].
  3. Uninstall any existing onnxruntime and onnxruntime-gpu: pip uninstall onnxruntime onnxruntime-gpu
  4. Install the required dependencies: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu114
  5. Install onnxruntime-gpu: pip install onnxruntime-gpu

For other GPU manufacturers or platforms, please refer to the specific instructions provided.

Usage:

Upon running the program for the first time, it will download a set of models (~300MB in size). To use the software, execute the python run.py command, which will open a graphical user interface (GUI). Select a face image and the target image or video where you want to replace the face. Click "Start" to initiate the process. You can then navigate to the chosen output directory to observe the real-time swapping of frames within a directory named after the video title. Once the processing is complete, the output file will be generated. Avoid altering the FPS checkbox unless you understand its implications. Additional command line arguments are also available for more customization.

Disclaimer:

While deepfake software already exists, our project serves as an experiment to improve existing techniques. It is intended for educational purposes, allowing users to explore the field of AI. We strongly discourage any illicit or unethical use of this software. Users must obtain consent from individuals involved and must transparently disclose when content online includes deepfake elements. We do not assume responsibility for any misuse, as our project is aimed solely at advancing AI understanding.

Credits:

We extend our appreciation to the developers behind the FFmpeg tool for simplifying video-related operations, as well as to the deepinsight team for their insightface project, which provided a well-made library and models.

Top comments (0)