AIArticlesOpen Source Software

Deep Live Cam live-swaps your face with another

AI software is on the rise, and with GPUs from Nvidia and AMD performing better every year, it's no wonder that AI is also available on the consumer Desktop.

One of the latest additions is the open source project Deep Live Cam, which has become the number one trending repository on GitHub.

Deep Live Cam is the number one trending repository, as of writing this article
Deep Live Cam is the number one trending repository, as of writing this article

The Deep Live Cam software is written in Python and can live-replace your own face with another face, uploaded from an image, such as a photo. The demo video, shown in the repository's README, shows what is possible.

Deep Live Cam switched face with Elon Musk picture.

Installing Deep Live Cam

As of now there is no classical installer available, however you can install Deep Live Cam from the GitHub repository. You need the git command on your command line. In Windows you can do this using a PowerShell window, on macOS and Linux open a Terminal window.

Besides git, you also need to have Python (with pip module) and ffmpeg installed. On Windows you additionally need the Visual Studio 2022 runtime.

First clone the repository using the git command:

ck@mint ~/Git $ git clone https://github.com/hacksider/Deep-Live-Cam.git
Cloning into 'Deep-Live-Cam'...
remote: Enumerating objects: 211, done.
remote: Counting objects: 100% (79/79), done.
remote: Compressing objects: 100% (44/44), done.
remote: Total 211 (delta 53), reused 49 (delta 35), pack-reused 132
Receiving objects: 100% (211/211), 48.37 MiB | 14.15 MiB/s, done.
Resolving deltas: 100% (101/101), done.

This copies the contents of the repository onto your own machine. You should see the following files and structure:

ck@mint ~/Git $ cd Deep-Live-Cam/
ck@mint ~/Git/Deep-Live-Cam $ ls -la
total 34916
drwxrwxr-x  6 ck ck     4096 Aug 10 20:15 ./
drwxrwxr-x 80 ck ck     4096 Aug 10 20:15 ../
-rw-rw-r--  1 ck ck 11366009 Aug 10 20:15 demo.gif
-rw-rw-r--  1 ck ck 24202127 Aug 10 20:15 demo.mp4
drwxrwxr-x  2 ck ck     4096 Aug 10 20:15 docs/
drwxrwxr-x  8 ck ck     4096 Aug 10 20:15 .git/
-rw-rw-r--  1 ck ck       66 Aug 10 20:15 .gitattributes
-rw-rw-r--  1 ck ck      201 Aug 10 20:15 .gitignore
-rw-rw-r--  1 ck ck    74341 Aug 10 20:15 instruction.png
-rw-rw-r--  1 ck ck    34523 Aug 10 20:15 LICENSE
drwxrwxr-x  2 ck ck     4096 Aug 10 20:15 models/
drwxrwxr-x  3 ck ck     4096 Aug 10 20:15 modules/
-rw-rw-r--  1 ck ck      175 Aug 10 20:15 mypi.ini
-rw-rw-r--  1 ck ck     7667 Aug 10 20:15 README.md
-rw-rw-r--  1 ck ck      738 Aug 10 20:15 requirements.txt
-rw-rw-r--  1 ck ck       78 Aug 10 20:15 run-cuda.bat
-rw-rw-r--  1 ck ck       38 Aug 10 20:15 run-laptop-gpu.bat
-rw-rw-r--  1 ck ck       92 Aug 10 20:15 run.py
-rw-rw-r--  1 ck ck      546 Aug 10 20:15 run_with_chocolatey.bat
-rw-rw-r--  1 ck ck     3526 Aug 10 20:15 setup_deep_live_cam.bat

You also need to download two additional files and save them into the modules directory:

Now we can install additional Python modules defined in the requirements.txt file. This will download and install a lot of large modules. Be prepared that this can take quite a long time!

ck@mint ~/Git/Deep-Live-Cam $ pip3 install -r requirements.txt 
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu118
Ignoring torch: markers 'sys_platform == "darwin"' don't match your environment
Ignoring torchvision: markers 'sys_platform == "darwin"' don't match your environment
Ignoring onnxruntime: markers 'sys_platform == "darwin" and platform_machine != "arm64"' don't match your environment
Ignoring onnxruntime-silicon: markers 'sys_platform == "darwin" and platform_machine == "arm64"' don't match your environment
Ignoring tensorflow: markers 'sys_platform == "darwin"' don't match your environment
Collecting numpy==1.23.5
  Downloading numpy-1.23.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.1/17.1 MB 13.3 MB/s eta 0:00:00
Collecting opencv-python==4.8.1.78
  Downloading opencv_python-4.8.1.78-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (61.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.7/61.7 MB 10.2 MB/s eta 0:00:00
Collecting onnx==1.16.0
  Downloading onnx-1.16.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.9/15.9 MB 17.6 MB/s eta 0:00:00
Collecting insightface==0.7.3
  Downloading insightface-0.7.3.tar.gz (439 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 439.5/439.5 KB 19.1 MB/s eta 0:00:00
[...]
Successfully built insightface basicsr filterpy
Installing collected packages: wcwidth, tk, lmdb, lit, libclang, flatbuffers, easydict, addict, wrapt, typing-extensions, tqdm, tomli, threadpoolctl, termcolor, tensorflow-io-gcs-filesystem, tensorflow-estimator, tensorboard-data-server, requests-oauthlib, psutil, protobuf, prettytable, platformdirs, pillow, numpy, networkx, MarkupSafe, llvmlite, lazy-loader, keras, joblib, importlib-metadata, humanfriendly, grpcio, google-pasta, gast, darkdetect, cython, cmake, astunparse, absl-py, yapf, werkzeug, tifffile, scipy, opt-einsum, opencv-python-headless, opencv-python, onnx, numba, ml-dtypes, jinja2, imageio, h5py, google-auth, gdown, customtkinter, coloredlogs, tb-nightly, scikit-learn, scikit-image, onnxruntime-gpu, jaxlib, google-auth-oauthlib, filterpy, tensorboard, qudida, jax, tensorflow, albumentations, opennsfw2, insightface, triton, torch, torchvision, facexlib, basicsr, gfpgan
Successfully installed MarkupSafe-2.1.5 absl-py-2.1.0 addict-2.4.0 albumentations-1.3.1 astunparse-1.6.3 basicsr-1.4.2 cmake-3.30.2 coloredlogs-15.0.1 customtkinter-5.2.2 cython-3.0.11 darkdetect-0.8.0 easydict-1.13 facexlib-0.3.0 filterpy-1.4.5 flatbuffers-24.3.25 gast-0.4.0 gdown-5.2.0 gfpgan-1.3.8 google-auth-2.33.0 google-auth-oauthlib-1.0.0 google-pasta-0.2.0 grpcio-1.65.4 h5py-3.11.0 humanfriendly-10.0 imageio-2.34.2 importlib-metadata-8.2.0 insightface-0.7.3 jax-0.4.30 jaxlib-0.4.30 jinja2-3.1.4 joblib-1.4.2 keras-2.12.0 lazy-loader-0.4 libclang-18.1.1 lit-18.1.8 llvmlite-0.43.0 lmdb-1.5.1 ml-dtypes-0.4.0 networkx-3.3 numba-0.60.0 numpy-1.23.5 onnx-1.16.0 onnxruntime-gpu-1.18.0 opencv-python-4.8.1.78 opencv-python-headless-4.10.0.84 opennsfw2-0.10.2 opt-einsum-3.3.0 pillow-9.5.0 platformdirs-4.2.2 prettytable-3.10.2 protobuf-4.23.2 psutil-5.9.8 qudida-0.0.4 requests-oauthlib-2.0.0 scikit-image-0.24.0 scikit-learn-1.5.1 scipy-1.14.0 tb-nightly-2.18.0a20240810 tensorboard-2.12.3 tensorboard-data-server-0.7.2 tensorflow-2.12.1 tensorflow-estimator-2.12.0 tensorflow-io-gcs-filesystem-0.37.1 termcolor-2.4.0 threadpoolctl-3.5.0 tifffile-2024.7.24 tk-0.1.0 tomli-2.0.1 torch-2.0.1+cu118 torchvision-0.15.2+cu118 tqdm-4.66.4 triton-2.0.0 typing-extensions-4.5.0 wcwidth-0.2.13 werkzeug-3.0.3 wrapt-1.14.1 yapf-0.40.2

To enable GPU support, read the additional steps in the README.md file. Unfortunately AMD does not seem to be supported yet.

Launching Deep Live Cam

If the pip installation didn't run into an error, you can now launch the Deep Live Cam application:

ck@mint ~/Git/Deep-Live-Cam $ python3 run.py

A new application window is launched, allowing you to upload a picture. Here I used a photo of Arnold Schwarzenegger (from ~20 years ago):

Select a face in Deep live cam
Select a face in Deep live cam

Then click on the "Live" button at the bottom to start your own webcam and see your face is live-swapped with the picture you've just selected.

Deep Live Cam live-swapped my face with Arnold Schwarzenegger's face.
Deep Live Cam live-swapped my face with Arnold Schwarzenegger's face.

On my machine, running an AMD Radeon RX 580X from 2021, the live picture was not fluid at all and could not be used for a video recording. I guess with the proper GPU support (currently Nvidia GPUs) and a more recent and powerful GPU this should work correctly without massive lagging. Nevertheless, the result is impressive!

Claudio Kuenzler
Claudio has been writing way over 1000 articles on his own blog since 2008 already. He is fascinated by technology, especially Open Source Software. As a Senior Systems Engineer he has seen and solved a lot of problems - and writes about them.

You may also like

Leave a reply

Your email address will not be published. Required fields are marked *