Deepfakes with an AMD graphics card tutorial (Updated)

How to use an AMD graphics card to make deepfakes with Linux

UPDATED. The standard deepfakes code requires CUDA-compatible NVIDIA graphics cards. That means ATI graphics card users were left unable to participate.

Here is a tutorial for running the python version of the deepfakes faceswap using an AMD card in a Linux environment on a fresh install of Ubuntu 16.04 LTS. Note that this is experimental, and some users report success while many others report difficulties. Please post in the forum thread with questions and comments.

Installing basic components

Operating system requirements

The following tutorial has been confirmed to work under Ubuntu 16.04, which is probably one of the most common Linux flavors and quite user friendly. If you need to install it, go here.

The tutorial has not been validated for Cygwin users who are running Linux directly on top of a Windows installation. You can learn how to dual boot your computer here.

Install OpenCL headers

sudo apt-get install ocl-icd-opencl-dev opencl-headers

Install AMDGPU-Pro drivers

Visit and install the the most recent driver for your graphics card. Extract the file and type the following in that directory:

./amdgpu-pro-install -y
sudo reboot

(or reboot manually)

If you are using a pre-Vega GPU only, you need to use the command:

./amdgpu-pro-install -y –opencl=legacy

Return to the install directory and type:

./amdgpu-pro-install -compute -y

Install other dependencies

sudo apt-get install zlib1g-dev
sudo apt-get install cmake
sudo apt-get install git

Install Radeontop (Optional)

Radeontop (Github link) monitors your GPU usage to make sure your script is making use of it. Go to your home directory or choice of install directory. Grab this package first.

cd ~/
sudo apt-get install libncurses5-dev libncursesw5-dev
git clone
sudo make
sudo make install

Install Python 3.6.4

Download the Python 3.6.4 source code here.

Extract the files. Uncomment line 209 to 212 in ./Modules/setup after ./configure (see here for why). Go to the install directory.

sudo make
sudo make install

Install pip 3.6 (a package manager)

sudo apt-get install python3-pip
pip install --upgrade pip

Clone the faceswap script and edit requirements

Go back to your main install directory.

cd ~/
git clone

Find or create the requirements.txt file within the faceswap directory. Paste into faceswap/requirements.txt:


Configure the faceswap scripts

pip3.6 install -r requirements-gpu.txt
pip3.6 uninstall tensorflow
pip3.6 uninstall keras

Build Bazel from source

Install ComputeCPP

Download computecpp from here.

Extract and copy ComputeCPP to /usr/local/ (Ctrl+L to find.)

sudo mkdir /usr/local/computecpp
sudo cp -R /computecpp/lib /usr/local/computecpp
sudo cp -R /computecpp/doc /usr/local/computecpp
sudo cp -R /computecpp/include /usr/local/computecpp
sudo cp -R /computecpp/bin /usr/local/computecpp

Add the following to the end of your ~/.bashrc file:

export HOST_CXX_COMPILER=/usr/bin/g++-4.8
export HOST_C_COMPILER=/usr/bin/gcc-4.8
export COMPUTECPP_TOOLKIT_PATH=/usr/local/computecpp
export COMPUTE=:0

Extract the archive you downloaded to the directory /usr/local/computecpp

Install libssl-dev

sudo apt-get install libssl-dev

Install clinfo

sudo apt-get install clinfo

Run clinfo and verify OpenCL detects your GPU

Install CURL

sudo apt-get install curl linux-generic

Build Tensorflow with OpenCL support

Download and install Tensorflow.

cd ~/
git clone
cd tensorflow
git checkout dev/amd_gpu

Download Bazel

sudo apt-get install openjdk-8-jdk
echo "deb [arch=amd64] stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
curl | sudo apt-key add -
sudo apt-get update && sudo apt-get install bazel
sudo apt-get upgrade bazel

Install and activate Env

sudo pip3.6 install virtualenv
virtualenv faceswap_env/
cd ~/faceswap/faceswap_env/bin
source activate

NOTE: commands in RED are entered from within Env

Configure and build

pip3.6 install -r requirements.txt
pip3.6 uninstall tensorflow
pip3.6 uninstall keras


cd ~/tensorflow

Confirm your Python install location, Python Library path, and various options, /faceswap/faceswap_env/bin/python3, site-packages, etc.


Select the following options.

NO to jemalloc support
NO to Google Cloud support
NO to Hadoop support
NO to Amazon S3 support
NO to XLA JIT support
NO to GDR support
NO to VERBS support
YES to OpenCL SYCL support
YES to ComputeCPP support
NO to CUDA support
NO to MPI support

Next, build the pip wheel (slow step):

bazel build -c opt --config=sycl //tensorflow/tools/pip_package:build_pip_package
mkdir /tmp/tensorflow_pkg
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

If you have a modern system, you can try replacing the first line with the line below (see here for more information):

bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-msse4.1 –copt=-msse4.2 --config=sycl -k //tensorflow/tools/pip_package:build_pip_package

Proceed if there are no errors.

cd /tmp/tensorflow_pkg

Install the wheel (replace with the appropriate wheel):

pip3.6 install tensorflow-1.5.0rc0-cp36-cp36m-linux_x86_64.whl


pip3.6 install keras
pip3.6 install face_recognition

This should cover the major installation steps.

Follow the instructions ~/faceswap/ and test the faceswap script.

You probably want to run

sudo radeontop
sudo watch sensors

to check that your GPU is being used and to monitor your GPU temperature.

Brief faceswap primer

Make sure your Env is activated.


Say you have an example data set of Trump and Cage in /photo/trump and /photo/cage, respectively.

python extract -i ~/faceswap/photo/trump -o ~/faceswap/data/trump
python extract -i ~/faceswap/photo/cage -o ~/faceswap/data/cage


python train -A ~/faceswap/data/trump -B ~/faceswap/data/cage -m ~/faceswap/models/

To show a preview:

python train -A ~/faceswap/data/trump -B ~/faceswap/data/cage -m ~/faceswap/models/ -p

Use the -h switch for the help option.


python convert -i ~/faceswap/photo/trump/ -o ~/faceswap/output/ -m ~/faceswap/models/

Create a video

See the tutorial.

Other useful commands

Clear Bazel cache-bug

bazel clean //clear bazel cache-bug

Clear Bazel cache

bazel clean --expunge

Update your package list

sudo apt-get update

Find your GPU information


For missing:

export LD_LIBRARY_PATH=/usr/local/computecpp/lib

Restart bashrc

exec bash

For g++ missing

sudo apt-get install g++-4.8

Thanks to the anonymous users who contributed to refining this tutorial.

Please post in the forum thread if you have issues, as it is easier to collect everything there.

4 thoughts on “Deepfakes with an AMD graphics card tutorial (Updated)

  1. It appears that the amdgpu drivers don’t work with my graphics card (AMD Radeon (TM) R9 M360). Am I just sol for doing deepfakes?

    • There’s some mention of the amdgpu driver not working for a similar R7 graphics card. See, for example. It might be that the laptop versions are less supported.

      I’m looking into other ways to get it to work on AMD… quite difficult. Will take at least a month to see if I can get a solution, if it’s even possible.

  2. Configure the faceswap scripts

    pip3.6 install -r requirements.txt
    pip3.6 uninstall tensorflow
    pip3.6 uninstall keras

    in which directory to run ./configure?

Leave a Comment