Files
faceswap/INSTALL.md

424 lines
16 KiB
Markdown
Raw Normal View History

2019-06-27 19:47:32 +01:00
# Installing faceswap
2019-11-04 17:29:05 +00:00
- [Installing faceswap](#installing-faceswap)
- [Prerequisites](#prerequisites)
- [Hardware Requirements](#hardware-requirements)
- [Supported operating systems](#supported-operating-systems)
- [Important before you proceed](#important-before-you-proceed)
- [Linux and Windows Install Guide](#linux-and-windows-install-guide)
- [Installer](#installer)
- [Manual Install](#manual-install)
- [Prerequisites](#prerequisites-1)
- [Anaconda](#anaconda)
- [Git](#git)
- [Setup](#setup)
- [Anaconda](#anaconda-1)
- [Set up a virtual environment](#set-up-a-virtual-environment)
- [Entering your virtual environment](#entering-your-virtual-environment)
2019-06-27 19:47:32 +01:00
- [faceswap](#faceswap)
2019-11-04 17:29:05 +00:00
- [Easy install](#easy-install)
- [Manual install](#manual-install-1)
2019-11-04 17:29:05 +00:00
- [Running faceswap](#running-faceswap)
- [Create a desktop shortcut](#create-a-desktop-shortcut)
- [Updating faceswap](#updating-faceswap)
2022-05-07 13:51:01 +02:00
- [macOS (Apple Silicon) Install Guide](#macos-apple-silicon-install-guide)
2022-06-07 10:54:51 +01:00
- [Prerequisites](#prerequisites-2)
- [OS](#os)
- [XCode Tools](#xcode-tools)
- [XQuartz](#xquartz)
- [Conda](#conda)
- [Setup](#setup-1)
- [Create and Activate the Environment](#create-and-activate-the-environment)
2022-06-07 10:54:51 +01:00
- [faceswap](#faceswap-1)
- [Easy install](#easy-install-1)
2019-11-04 17:29:05 +00:00
- [General Install Guide](#general-install-guide)
- [Installing dependencies](#installing-dependencies)
- [Git](#git-1)
- [Python](#python)
- [Virtual Environment](#virtual-environment)
- [Getting the faceswap code](#getting-the-faceswap-code)
2022-06-07 10:54:51 +01:00
- [Setup](#setup-2)
2019-11-04 17:29:05 +00:00
- [About some of the options](#about-some-of-the-options)
- [Docker Install Guide](#docker-install-guide)
- [Docker General](#docker-general)
- [CUDA with Docker in 20 minutes.](#cuda-with-docker-in-20-minutes)
- [CUDA with Docker on Arch Linux](#cuda-with-docker-on-arch-linux)
- [Install docker](#install-docker)
- [A successful setup log, without docker.](#a-successful-setup-log-without-docker)
2019-11-04 17:29:05 +00:00
- [Run the project](#run-the-project)
- [Notes](#notes)
# Prerequisites
2022-05-12 12:29:29 +01:00
Machine learning essentially involves a ton of trial and error. You're letting a program try millions of different settings to land on an algorithm that sort of does what you want it to do. This process is really really slow unless you have the hardware required to speed this up.
The type of computations that the process does are well suited for graphics cards, rather than regular processors. **It is pretty much required that you run the training process on a desktop or server capable GPU.** Running this on your CPU means it can take weeks to train your model, compared to several hours on a GPU.
## Hardware Requirements
**TL;DR: you need at least one of the following:**
- **A powerful CPU**
- Laptop CPUs can often run the software, but will not be fast enough to train at reasonable speeds
- **A powerful GPU**
- Currently, Nvidia GPUs are fully supported. and AMD graphics cards are partially supported through plaidML.
2020-08-28 02:00:03 +01:00
- If using an Nvidia GPU, then it needs to support at least CUDA Compute Capability 3.5. (Release 1.0 will work on Compute Capability 3.0)
To see which version your GPU supports, consult this list: https://developer.nvidia.com/cuda-gpus
Desktop cards later than the 7xx series are most likely supported.
- **A lot of patience**
## Supported operating systems
- **Windows 10**
Windows 7 and 8 might work. Your mileage may vary. Windows has an installer which will set up everything you need. See: https://github.com/deepfakes/faceswap/releases
- **Linux**
2022-05-12 12:29:29 +01:00
Most Ubuntu/Debian or CentOS based Linux distributions will work. There is a Linux install script that will install and set up everything you need. See: https://github.com/deepfakes/faceswap/releases
- **macOS**
2022-05-12 12:29:29 +01:00
Experimental support for GPU-accelerated, native Apple Silicon processing (e.g. Apple M1 chips). Installation instructions can be found [further down this page](#macos-apple-silicon-install-guide).
Intel based macOS systems should work, but you will need to follow the [Manual Install](#manual-install) instructions.
- All operating systems must be 64-bit for Tensorflow to run.
Alternatively, there is a docker image that is based on Debian.
# Important before you proceed
2022-05-12 12:29:29 +01:00
**In its current iteration, the project relies heavily on the use of the command line, although a gui is available. if you are unfamiliar with command line tools, you may have difficulty setting up the environment and should perhaps not attempt any of the steps described in this guide.** This guide assumes you have intermediate knowledge of the command line.
The developers are also not responsible for any damage you might cause to your own computer.
2019-11-04 17:29:05 +00:00
# Linux and Windows Install Guide
## Installer
2019-11-04 17:29:05 +00:00
Windows and Linux now both have an installer which installs everything for you and creates a desktop shortcut to launch straight into the GUI. You can download the installer from https://github.com/deepfakes/faceswap/releases.
2019-06-27 19:47:32 +01:00
If you have issues with the installer then read on for the more manual way to install faceswap on Windows.
## Manual Install
2019-06-27 19:47:32 +01:00
Setting up faceswap can seem a little intimidating to new users, but it isn't that complicated, although a little time consuming. It is recommended to use Linux where possible as Windows will hog about 20% of your GPU Memory, making faceswap run a little slower, however using Windows is perfectly fine and 100% supported.
## Prerequisites
### Anaconda
Download and install the latest Python 3 Anaconda from: https://www.anaconda.com/download/. Unless you know what you are doing, you can leave all the options at default.
### Git
Download and install Git for Windows: https://git-scm.com/download/win. Unless you know what you are doing, you can leave all the options at default.
## Setup
Reboot your PC, so that everything you have just installed gets registered.
### Anaconda
#### Set up a virtual environment
- Open up Anaconda Navigator
- Select "Environments" on the left hand side
- Select "Create" at the bottom
- In the pop up:
- Give it the name: faceswap
Faceswap 2.0 (#1045) * Core Updates - Remove lib.utils.keras_backend_quiet and replace with get_backend() where relevant - Document lib.gpu_stats and lib.sys_info - Remove call to GPUStats.is_plaidml from convert and replace with get_backend() - lib.gui.menu - typofix * Update Dependencies Bump Tensorflow Version Check * Port extraction to tf2 * Add custom import finder for loading Keras or tf.keras depending on backend * Add `tensorflow` to KerasFinder search path * Basic TF2 training running * model.initializers - docstring fix * Fix and pass tests for tf2 * Replace Keras backend tests with faceswap backend tests * Initial optimizers update * Monkey patch tf.keras optimizer * Remove custom Adam Optimizers and Memory Saving Gradients * Remove multi-gpu option. Add Distribution to cli * plugins.train.model._base: Add Mirror, Central and Default distribution strategies * Update tensorboard kwargs for tf2 * Penalized Loss - Fix for TF2 and AMD * Fix syntax for tf2.1 * requirements typo fix * Explicit None for clipnorm if using a distribution strategy * Fix penalized loss for distribution strategies * Update Dlight * typo fix * Pin to TF2.2 * setup.py - Install tensorflow from pip if not available in Conda * Add reduction options and set default for mirrored distribution strategy * Explicitly use default strategy rather than nullcontext * lib.model.backup_restore documentation * Remove mirrored strategy reduction method and default based on OS * Initial restructure - training * Remove PingPong Start model.base refactor * Model saving and resuming enabled * More tidying up of model.base * Enable backup and snapshotting * Re-enable state file Remove loss names from state file Fix print loss function Set snapshot iterations correctly * Revert original model to Keras Model structure rather than custom layer Output full model and sub model summary Change NNBlocks to callables rather than custom keras layers * Apply custom Conv2D layer * Finalize NNBlock restructure Update Dfaker blocks * Fix reloading model under a different distribution strategy * Pass command line arguments through to trainer * Remove training_opts from model and reference params directly * Tidy up model __init__ * Re-enable tensorboard logging Suppress "Model Not Compiled" warning * Fix timelapse * lib.model.nnblocks - Bugfix residual block Port dfaker bugfix original * dfl-h128 ported * DFL SAE ported * IAE Ported * dlight ported * port lightweight * realface ported * unbalanced ported * villain ported * lib.cli.args - Update Batchsize + move allow_growth to config * Remove output shape definition Get image sizes per side rather than globally * Strip mask input from encoder * Fix learn mask and output learned mask to preview * Trigger Allow Growth prior to setting strategy * Fix GUI Graphing * GUI - Display batchsize correctly + fix training graphs * Fix penalized loss * Enable mixed precision training * Update analysis displayed batch to match input * Penalized Loss - Multi-GPU Fix * Fix all losses for TF2 * Fix Reflect Padding * Allow different input size for each side of the model * Fix conv-aware initialization on reload * Switch allow_growth order * Move mixed_precision to cli * Remove distrubution strategies * Compile penalized loss sub-function into LossContainer * Bump default save interval to 250 Generate preview on first iteration but don't save Fix iterations to start at 1 instead of 0 Remove training deprecation warnings Bump some scripts.train loglevels * Add ability to refresh preview on demand on pop-up window * Enable refresh of training preview from GUI * Fix Convert Debug logging in Initializers * Fix Preview Tool * Update Legacy TF1 weights to TF2 Catch stats error on loading stats with missing logs * lib.gui.popup_configure - Make more responsive + document * Multiple Outputs supported in trainer Original Model - Mask output bugfix * Make universal inference model for convert Remove scaling from penalized mask loss (now handled at input to y_true) * Fix inference model to work properly with all models * Fix multi-scale output for convert * Fix clipnorm issue with distribution strategies Edit error message on OOM * Update plaidml losses * Add missing file * Disable gmsd loss for plaidnl * PlaidML - Basic training working * clipnorm rewriting for mixed-precision * Inference model creation bugfixes * Remove debug code * Bugfix: Default clipnorm to 1.0 * Remove all mask inputs from training code * Remove mask inputs from convert * GUI - Analysis Tab - Docstrings * Fix rate in totals row * lib.gui - Only update display pages if they have focus * Save the model on first iteration * plaidml - Fix SSIM loss with penalized loss * tools.alignments - Remove manual and fix jobs * GUI - Remove case formatting on help text * gui MultiSelect custom widget - Set default values on init * vgg_face2 - Move to plugins.extract.recognition and use plugins._base base class cli - Add global GPU Exclude Option tools.sort - Use global GPU Exlude option for backend lib.model.session - Exclude all GPUs when running in CPU mode lib.cli.launcher - Set backend to CPU mode when all GPUs excluded * Cascade excluded devices to GPU Stats * Explicit GPU selection for Train and Convert * Reduce Tensorflow Min GPU Multiprocessor Count to 4 * remove compat.v1 code from extract * Force TF to skip mixed precision compatibility check if GPUs have been filtered * Add notes to config for non-working AMD losses * Rasie error if forcing extract to CPU mode * Fix loading of legace dfl-sae weights + dfl-sae typo fix * Remove unused requirements Update sphinx requirements Fix broken rst file locations * docs: lib.gui.display * clipnorm amd condition check * documentation - gui.display_analysis * Documentation - gui.popup_configure * Documentation - lib.logger * Documentation - lib.model.initializers * Documentation - lib.model.layers * Documentation - lib.model.losses * Documentation - lib.model.nn_blocks * Documetation - lib.model.normalization * Documentation - lib.model.session * Documentation - lib.plaidml_stats * Documentation: lib.training_data * Documentation: lib.utils * Documentation: plugins.train.model._base * GUI Stats: prevent stats from using GPU * Documentation - Original Model * Documentation: plugins.model.trainer._base * linting * unit tests: initializers + losses * unit tests: nn_blocks * bugfix - Exclude gpu devices in train, not include * Enable Exclude-Gpus in Extract * Enable exclude gpus in tools * Disallow multiple plugin types in a single model folder * Automatically add exclude_gpus argument in for cpu backends * Cpu backend fixes * Relax optimizer test threshold * Default Train settings - Set mask to Extended * Update Extractor cli help text Update to Python 3.8 * Fix FAN to run on CPU * lib.plaidml_tools - typofix * Linux installer - check for curl * linux installer - typo fix
2020-08-12 10:36:41 +01:00
- **IMPORTANT**: Select python version 3.8
- Hit "Create" (NB: This may take a while as it will need to download Python)
2020-08-18 19:10:56 +01:00
![Anaconda virtual env setup](https://i.imgur.com/CLIDDfa.png)
#### Entering your virtual environment
To enter the virtual environment:
- Open up Anaconda Navigator
- Select "Environments" on the left hand side
- Hit the ">" arrow next to your faceswap environment and select "Open Terminal"
![Anaconda enter virtual env](https://i.imgur.com/rKSq2Pd.png)
2019-06-27 19:47:32 +01:00
### faceswap
- If you are not already in your virtual environment follow [these steps](#entering-your-virtual-environment)
2019-06-27 19:47:32 +01:00
- Get the faceswap repo by typing: `git clone --depth 1 https://github.com/deepfakes/faceswap.git`
- Enter the faceswap folder: `cd faceswap`
#### Easy install
- Enter the command `python setup.py` and follow the prompts:
- If you have issues/errors follow the Manual install steps below.
#### Manual install
Do not follow these steps if the Easy Install above completed succesfully.
If you are using an Nvidia card make sure you have the correct versions of Cuda/cuDNN installed for the required version of Tensorflow
- Install tkinter (required for the GUI) by typing: `conda install tk`
- Install requirements:
- For Nvidia GPU users: `pip install -r ./requirements/requirements_nvidia.txt`
- For AMD GPU users: `pip install -r ./requirements/requirements_amd.txt`
- For CPU users: `pip install -r ./requirements/requirements_cpu.txt`
2019-06-27 19:47:32 +01:00
## Running faceswap
- If you are not already in your virtual environment follow [these steps](#entering-your-virtual-environment)
- Enter the faceswap folder: `cd faceswap`
- Enter the following to see the list of commands: `python faceswap.py -h` or enter `python faceswap.py gui` to launch the GUI
## Create a desktop shortcut
A desktop shortcut can be added to easily launch straight into the faceswap GUI:
- Open Notepad
- Paste the following:
```
%USERPROFILE%\Anaconda3\envs\faceswap\python.exe %USERPROFILE%/faceswap/faceswap.py gui
```
- Save the file to your desktop as "faceswap.bat"
## Updating faceswap
It's good to keep faceswap up to date as new features are added and bugs are fixed. To do so:
2019-09-29 01:36:59 +02:00
- If using the GUI you can go to the Help menu and select "Check for Updates...". If updates are available go to the Help menu and select "Update Faceswap". Restart Faceswap to complete the update.
- If you are not already in your virtual environment follow [these steps](#entering-your-virtual-environment)
- Enter the faceswap folder: `cd faceswap`
- Enter the following `git pull --all`
- Once the latest version has downloaded, make sure your dependencies are up to date. There is a script to help with this: `python update_deps.py`
2022-05-07 13:51:01 +02:00
# macOS (Apple Silicon) Install Guide
## Prerequisites
### OS
macOS 12.0+
### XCode Tools
```sh
xcode-select --install
```
2022-05-07 13:51:01 +02:00
### XQuartz
Download and install from:
- https://www.xquartz.org/
2022-05-07 13:51:01 +02:00
### Conda
Download and install the latest Conda env from:
- https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
Install Conda:
2022-05-07 13:51:01 +02:00
```sh
$ chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
$ sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
$ source ~/miniforge3/bin/activate
```
## Setup
### Create and Activate the Environment
```sh
$ conda create --name faceswap python=3.9
$ conda activate faceswap
```
2022-05-07 13:51:01 +02:00
### faceswap
- Download the faceswap repo and enter thr faceswap folder:
```sh
$ git clone --depth 1 https://github.com/deepfakes/faceswap.git
$ cd faceswap
```
2022-05-07 13:51:01 +02:00
#### Easy install
```sh
$ python setup.py
2022-05-07 13:51:01 +02:00
```
2022-05-07 13:51:01 +02:00
- If you have issues/errors follow the Manual install steps below.
# General Install Guide
## Installing dependencies
2019-06-27 19:47:32 +01:00
### Git
Git is required for obtaining the code and keeping your codebase up to date.
Obtain git for your distribution from the [git website](https://git-scm.com/downloads).
### Python
The recommended install method is to use a Conda3 Environment as this will handle the installation of Nvidia's CUDA and cuDNN straight into your Conda Environment. This is by far the easiest and most reliable way to setup the project.
- MiniConda3 is recommended: [MiniConda3](https://docs.conda.io/en/latest/miniconda.html)
2022-05-12 12:29:29 +01:00
2022-06-07 10:54:51 +01:00
Alternatively you can install Python (>= 3.7-3.9 64-bit) for your distribution (links below.) If you go down this route and are using an Nvidia GPU you should install CUDA (https://developer.nvidia.com/cuda-zone) and cuDNN (https://developer.nvidia.com/cudnn). for your system. If you do not plan to build Tensorflow yourself, make sure you install the correct Cuda and cuDNN package for the currently installed version of Tensorflow (Current release: Tensorflow 2.8. Release v1.0: Tensorflow 1.15). You can check for the compatible versions here: (https://www.tensorflow.org/install/source#gpu).
2019-06-27 19:47:32 +01:00
- Python distributions:
- apt/yum install python3 (Linux)
- [Installer](https://www.python.org/downloads/release/python-368/) (Windows)
- [brew](https://brew.sh/) install python3 (macOS)
### Virtual Environment
It is highly recommended that you setup faceswap inside a virtual environment. In fact we will not generally support installations that are not within a virtual environment as troubleshooting package conflicts can be next to impossible.
If using Conda3 then setting up virtual environments is relatively straight forward. More information can be found at [Conda Docs](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html)
If using a default Python distribution then [virtualenv](https://github.com/pypa/virtualenv) and [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io) may help when you are not using docker.
## Getting the faceswap code
2019-06-27 19:47:32 +01:00
It is recommended to clone the repo with git instead of downloading the code from http://github.com/deepfakes/faceswap and extracting it as this will make it far easier to get the latest code (which can be done from the GUI). To clone a repo you can either use the Git GUI for your distribution or open up a command prompt, enter the folder where you want to store faceswap and enter:
```bash
git clone https://github.com/deepfakes/faceswap.git
```
## Setup
2019-06-27 19:47:32 +01:00
Enter your virtual environment and then enter the folder that faceswap has been downloaded to and run:
2018-05-10 20:11:00 +01:00
```bash
python setup.py
```
If setup fails for any reason you can still manually install the packages listed within the files in the requirements folder.
2018-05-10 20:11:00 +01:00
### About some of the options
2018-05-10 20:11:00 +01:00
- CUDA: For acceleration. Requires a good nVidia Graphics Card (which supports CUDA inside)
- Docker: Provide a ready-made image. Hide trivial details. Get you straight to the project.
- nVidia-Docker: Access to the nVidia GPU on host machine from inside container.
# Docker Install Guide
## Docker General
<details>
<summary>Click to expand!</summary>
### CUDA with Docker in 20 minutes.
1. Install Docker
https://www.docker.com/community-edition
2. Install Nvidia-Docker & Restart Docker Service
https://github.com/NVIDIA/nvidia-docker
3. Build Docker Image For faceswap
```bash
docker build -t deepfakes-gpu -f Dockerfile.gpu .
```
4. Mount faceswap volume and Run it
a). without `gui.tools.py` gui not working.
```bash
nvidia-docker run --rm -it -p 8888:8888 \
--hostname faceswap-gpu --name faceswap-gpu \
-v /opt/faceswap:/srv \
deepfakes-gpu
```
b). with gui. tools.py gui working.
Enable local access to X11 server
```bash
xhost +local:
```
Enable nvidia device if working under bumblebee
```bash
echo ON > /proc/acpi/bbswitch
```
2022-05-12 12:29:29 +01:00
Create container
```bash
nvidia-docker run -p 8888:8888 \
--hostname faceswap-gpu --name faceswap-gpu \
-v /opt/faceswap:/srv \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
-e AUDIO_GID=`getent group audio | cut -d: -f3` \
-e VIDEO_GID=`getent group video | cut -d: -f3` \
-e GID=`id -g` \
-e UID=`id -u` \
deepfakes-gpu
2022-05-12 12:29:29 +01:00
```
2022-05-12 12:29:29 +01:00
Open a new terminal to interact with the project
2022-05-12 12:29:29 +01:00
```bash
docker exec -it deepfakes-gpu /bin/bash
```
Launch deepfakes gui (Answer 3 for NVIDIA at the prompt)
```bash
python3.8 /srv/faceswap.py gui
```
</details>
## CUDA with Docker on Arch Linux
<details>
<summary>Click to expand!</summary>
### Install docker
```bash
sudo pacman -S docker
```
The steps are same but Arch linux doesn't use nvidia-docker
create container
```bash
docker run -p 8888:8888 --gpus all --privileged -v /dev:/dev \
--hostname faceswap-gpu --name faceswap-gpu \
-v /mnt/hdd2/faceswap:/srv \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
-e AUDIO_GID=`getent group audio | cut -d: -f3` \
-e VIDEO_GID=`getent group video | cut -d: -f3` \
-e GID=`id -g` \
-e UID=`id -u` \
deepfakes-gpu
```
Open a new terminal to interact with the project
2022-05-12 12:29:29 +01:00
```bash
docker exec -it deepfakes-gpu /bin/bash
```
Launch deepfakes gui (Answer 3 for NVIDIA at the prompt)
**With `gui.tools.py` gui working.**
Enable local access to X11 server
```bash
xhost +local:
```
```bash
python3.8 /srv/faceswap.py gui
```
</details>
---
## A successful setup log, without docker.
```
INFO The tool provides tips for installation
and installs required python packages
INFO Setup in Linux 4.14.39-1-MANJARO
2020-08-18 19:10:56 +01:00
INFO Installed Python: 3.7.5 64bit
INFO Installed PIP: 10.0.1
Enable Docker? [Y/n] n
INFO Docker Disabled
2022-05-12 12:29:29 +01:00
Enable CUDA? [Y/n]
INFO CUDA Enabled
INFO CUDA version: 9.1
INFO cuDNN version: 7
WARNING Tensorflow has no official prebuild for CUDA 9.1 currently.
To continue, You have to build your own tensorflow-gpu.
Help: https://www.tensorflow.org/install/install_sources
Are System Dependencies met? [y/N] y
INFO Installing Missing Python Packages...
INFO Installing tensorflow-gpu
......
INFO Installing tqdm
INFO Installing matplotlib
INFO All python3 dependencies are met.
You are good to go.
```
## Run the project
Once all these requirements are installed, you can attempt to run the faceswap tools. Use the `-h` or `--help` options for a list of options.
```bash
python faceswap.py -h
```
2018-05-10 20:11:00 +01:00
or run with `gui` to launch the GUI
```bash
python faceswap.py gui
```
Proceed to [../blob/master/USAGE.md](USAGE.md)
## Notes
2022-05-12 12:29:29 +01:00
This guide is far from complete. Functionality may change over time, and new dependencies are added and removed as time goes on.
2019-09-29 01:36:59 +02:00
If you are experiencing issues, please raise them in the [faceswap Forum](https://faceswap.dev/forum) instead of the main repo. Usage questions raised in the issues within this repo are liable to be closed without response.