Skip to content

Commit 837bc2d

Browse files
authored
Faceswap 3 (#1516)
* FaceSwap 3 (#1515) * Update extract pipeline * Update requirements + setup for nvidia * Remove allow-growth option * tf.keras to keras updates * lib.model.losses - Port + fix all loss functions for Keras3 * lib.model - port initializers, layers. normalization to Keras3 * lib.model.autoclip to Keras 3 * Update mixed precision layer storage * model file to .keras format * Restructure nn_blocks to initialize layers in __init__ * Tensorboard - Trainer: Add Torch compatible Tensorboard callbacks - GUI event reader remove TF dependency * Loss logging - Flush TB logs on save - Replace TB live iterator for GUI * Backup models on total loss drop rather than per side * Update all models to Keras3 Compat * Remove lib.model.session * Update clip ViT to Keras 3 * plugins.extract.mask.unet-dfl - Fix for Keras3/Torch backend * Port AdaBelief to Keras 3 * setup.py: - Add --dev flag for dev tool install * Fix Keras 3 syntax * Fix LR Finder for Keras 3 * Fix mixed precision switching for Keras 3 * Add more optimizers + open up config setting * train: Remove updating FS1 weights to FS2 models * Alignments: Remove support for legacy .json files * tools.model: - Remove TF Saved Format saving - Fix Backup/Restore + Nan-Scan * Fix inference model creation for Keras 3 * Preview tool: Fix for Keras3 * setup.py: Configure keras backend * train: Migration of FS2 models to FS3 * Training: Default coverage to 100% * Remove DirectML backend * Update setup for MacOS * GUI: Force line reading to UTF-8 * Remove redundant Tensorflow references * Remove redundant code * Legacy model loading: Fix TFLamdaOp scalar ops and DepthwiseConv2D * Add vertical offset option for training * Github actions: Add more python versions * Add python version to workflow names * Github workflow: Exclude Python 3.12 for macOS * Implement custom training loop * Fs3 - Add RTX5xxx and ROCm 6.1-6.4 support (#1511) * setup.py: Add Cuda/ROCm version select options * bump minimum python version to 3.11 * Switch from setup.cgf to pyproject.toml * Documentation: Update all docs to use automodapi * Allow sysinfo to run with missing packages + correctly install tk under Linux * Bugfix: dot naming convention in clip models * lib.config: Centralise globally rather than passing as object - Add torch DataParallel for multi-gpu training - GUI: Group switches together when generating cli args - CLI: Remove deprecated multi-character argparse args - Refactor: - Centralise tensorboard reading/writing + unit tests - Create trainer plugin interfaces + add original + distributed * Update installers
1 parent d115fcb commit 837bc2d

File tree

370 files changed

+26140
-20266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

370 files changed

+26140
-20266
lines changed

.github/workflows/pytest.yml

Lines changed: 76 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,67 @@ on:
99

1010
jobs:
1111
build_conda:
12-
name: conda (${{ matrix.os }}, ${{ matrix.backend }})
12+
name: conda (${{ matrix.os }}, ${{ matrix.backend }} ${{ matrix.python-version }})
1313
runs-on: ${{ matrix.os }}
1414
defaults:
1515
run:
1616
shell: bash -el {0}
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
21-
backend: ["nvidia", "cpu"]
22-
include:
23-
- os: "ubuntu-latest"
24-
backend: "rocm"
20+
# TODO revert. Despite documentation to the contrary, MacOS runners are always x86-64
21+
#os: ["ubuntu-latest", "windows-latest", "macos-latest"]
22+
os: ["ubuntu-latest", "windows-latest"]
23+
python-version: ["3.11", "3.12", "3.13"]
24+
backend: ["nvidia", "cpu", "rocm", "apple-silicon"]
25+
exclude:
26+
# CPU + Nvidia only on Windows
2527
- os: "windows-latest"
26-
backend: "directml"
28+
backend: "rocm"
29+
- os: windows-latest
30+
backend: apple-silicon
31+
# No apple-silicon on Linux
32+
- os: ubuntu-latest
33+
backend: apple-silicon
34+
# Only Apple-Silicon on MacOS
35+
- os: "macos-latest"
36+
backend: "rocm"
37+
- os: "macos-latest"
38+
backend: "cpu"
39+
- os: "macos-latest"
40+
backend: "nvidia"
2741
steps:
2842
- uses: actions/checkout@v3
43+
- name: Cleanup space
44+
# We run out of space on rocm. Ref: https://github.com/actions/runner-images/issues/709
45+
if: matrix.backend == 'rocm'
46+
run: |
47+
sudo rm -rf "/usr/local/share/boost" "$AGENT_TOOLSDIRECTORY"
2948
- name: Set cache date
3049
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
31-
- name: Cache conda
32-
uses: actions/cache@v3
33-
env:
34-
# Increase this value to manually reset cache
35-
CACHE_NUMBER: 1
36-
REQ_FILE: ./requirements/requirements_${{ matrix.backend }}.txt
37-
with:
38-
path: ~/conda_pkgs_dir
39-
key: ${{ runner.os }}-${{ matrix.backend }}-conda-${{ env.CACHE_NUMBER }}-${{ env.DATE }}-${{ hashFiles('./requirements/requirements.txt', env.REQ_FILE) }}
50+
# TODO Re-enable. Currently disabled as it does not seem to get used and takes a lot of space
51+
#- name: Cache conda
52+
# uses: actions/cache@v3
53+
# env:
54+
# # Increase this value to manually reset cache
55+
# CACHE_NUMBER: 1
56+
# REQ_FILE: ./requirements/requirements_${{ matrix.backend }}.txt
57+
# with:
58+
# path: ~/conda_pkgs_dir
59+
# key: ${{ runner.os }}-${{ matrix.backend }}-conda-${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}-${{ env.DATE }}-${{ hashFiles('./requirements/requirements.txt', env.REQ_FILE) }}
4060
- name: Set up Conda
4161
uses: conda-incubator/setup-miniconda@v2
4262
with:
43-
python-version: "3.10"
63+
python-version: ${{ matrix.python-version }}
64+
miniconda-version: "latest"
4465
auto-update-conda: true
4566
activate-environment: faceswap
4667
- name: Conda info
4768
run: conda info && conda list
4869
- name: Install
4970
run: |
50-
python setup.py --installer --${{ matrix.backend }}
51-
pip install flake8 pylint mypy pytest pytest-mock wheel pytest-xvfb
52-
pip install types-attrs types-cryptography types-pyOpenSSL types-PyYAML types-setuptools
71+
python setup.py --installer --dev --${{ matrix.backend }}
72+
pip install wheel pytest-xvfb types-attrs types-cryptography types-pyOpenSSL
5373
- name: Lint with flake8
5474
run: |
5575
# stop the build if there are Python syntax errors or undefined names
@@ -60,45 +80,44 @@ jobs:
6080
run: |
6181
mypy .
6282
- name: SysInfo
63-
run: python -c "from lib.sysinfo import sysinfo ; print(sysinfo)"
64-
- name: Simple Tests
83+
run: python -m lib.system.sysinfo
84+
- name: Unit Tests
6585
# These backends will fail as GPU drivers not available
66-
if: matrix.backend != 'rocm' && matrix.backend != 'nvidia' && matrix.backend != 'directml'
86+
if: matrix.backend == 'cpu'
6787
run: |
68-
FACESWAP_BACKEND="${{ matrix.backend }}" py.test -v tests/;
88+
KERAS_BACKEND=torch FACESWAP_BACKEND="${{ matrix.backend }}" py.test -v tests/;
6989
- name: End to End Tests
7090
# These backends will fail as GPU drivers not available
71-
# macOS fails on first extract test with 'died with <Signals.SIGSEGV: 11>'
72-
if: matrix.backend != 'rocm' && matrix.backend != 'nvidia' && matrix.backend != 'directml' && matrix.os != 'macos-latest'
91+
if: matrix.backend == 'cpu'
7392
run: |
74-
FACESWAP_BACKEND="${{ matrix.backend }}" python tests/simple_tests.py;
93+
KERAS_BACKEND=torch FACESWAP_BACKEND="${{ matrix.backend }}" python tests/simple_tests.py;
7594
7695
build_linux:
77-
name: "pip (ubuntu-latest, ${{ matrix.backend }})"
96+
name: "pip (ubuntu-latest, ${{ matrix.backend }} ${{ matrix.python-version }})"
7897
runs-on: ubuntu-latest
7998
strategy:
8099
fail-fast: false
81100
matrix:
82-
python-version: ["3.10"]
101+
python-version: ["3.11", "3.12", "3.13"]
83102
backend: ["cpu"]
84103
include:
85104
- backend: "cpu"
86105
steps:
87-
- uses: actions/checkout@v3
106+
- uses: actions/checkout@v5
88107
- name: Set up Python ${{ matrix.python-version }}
89-
uses: actions/setup-python@v3
108+
uses: actions/setup-python@v6
90109
with:
91110
python-version: ${{ matrix.python-version }}
92111
cache: 'pip'
93-
cache-dependency-path: './requirements/requirements_${{ matrix.backend }}.txt'
112+
cache-dependency-path: |
113+
'./requirements/requirements_base.txt'
114+
'./requirements/requirements_${{ matrix.backend }}.txt'
94115
- name: Install dependencies
95116
run: |
96117
python -m pip install --upgrade pip
97-
pip install flake8 pylint mypy pytest pytest-mock pytest-xvfb wheel
98-
pip install types-attrs types-cryptography types-pyOpenSSL types-PyYAML types-setuptools
99118
pip install -r ./requirements/requirements_${{ matrix.backend }}.txt
100-
- name: List installed packages
101-
run: pip freeze
119+
pip install -r ./requirements/_requirements_dev.txt
120+
pip install wheel pytest-xvfb types-attrs types-cryptography types-pyOpenSSL
102121
- name: Lint with flake8
103122
run: |
104123
# stop the build if there are Python syntax errors or undefined names
@@ -109,42 +128,45 @@ jobs:
109128
continue-on-error: true
110129
run: |
111130
mypy .
112-
- name: Simple Tests
131+
- name: SysInfo
132+
run: FACESWAP_BACKEND="${{ matrix.backend }}" python -m lib.system.sysinfo
133+
- name: Unit Tests
113134
run: |
114-
FACESWAP_BACKEND="${{ matrix.backend }}" py.test -v tests/;
135+
KERAS_BACKEND=torch FACESWAP_BACKEND="${{ matrix.backend }}" py.test -v tests/;
115136
- name: End to End Tests
116137
run: |
117-
FACESWAP_BACKEND="${{ matrix.backend }}" python tests/simple_tests.py;
138+
KERAS_BACKEND=torch FACESWAP_BACKEND="${{ matrix.backend }}" python tests/simple_tests.py;
118139
119140
build_windows:
120-
name: "pip (windows-latest, ${{ matrix.backend }})"
141+
name: "pip (windows-latest, ${{ matrix.backend }} ${{ matrix.python-version }})"
121142
runs-on: windows-latest
122143
strategy:
123144
fail-fast: false
124145
matrix:
125-
python-version: ["3.10"]
126-
backend: ["cpu", "directml"]
146+
python-version: ["3.11", "3.12", "3.13"]
147+
backend: ["cpu"]
127148
include:
128149
- backend: "cpu"
129-
- backend: "directml"
130150
steps:
131-
- uses: actions/checkout@v3
151+
- uses: actions/checkout@v5
132152
- name: Set up Python ${{ matrix.python-version }}
133-
uses: actions/setup-python@v3
153+
uses: actions/setup-python@v6
134154
with:
135155
python-version: ${{ matrix.python-version }}
136156
cache: 'pip'
137-
cache-dependency-path: './requirements/requirements_${{ matrix.backend }}.txt'
157+
cache-dependency-path: |
158+
'./requirements/requirements_base.txt'
159+
'./requirements/requirements_${{ matrix.backend }}.txt'
138160
- name: Install dependencies
139161
run: |
140162
python -m pip install --upgrade pip
141-
pip install flake8 pylint mypy pytest pytest-mock wheel
142-
pip install types-attrs types-cryptography types-pyOpenSSL types-PyYAML types-setuptools
163+
pip install types-attrs types-cryptography types-pyOpenSSL wheel
164+
pip install -r ./requirements/_requirements_dev.txt
143165
pip install -r ./requirements/requirements_${{ matrix.backend }}.txt
144-
- name: List installed packages
145-
run: pip freeze
146-
- name: Set Backend EnvVar
166+
- name: Set Faceswap Backend EnvVar
147167
run: echo "FACESWAP_BACKEND=${{ matrix.backend }}" | Out-File -FilePath $env:GITHUB_ENV -Append
168+
- name: Set Keras Backend EnvVar
169+
run: echo "KERAS_BACKEND=torch" | Out-File -FilePath $env:GITHUB_ENV -Append
148170
- name: Lint with flake8
149171
run: |
150172
# stop the build if there are Python syntax errors or undefined names
@@ -155,7 +177,9 @@ jobs:
155177
continue-on-error: true
156178
run: |
157179
mypy .
158-
- name: Simple Tests
180+
- name: SysInfo
181+
run: python -m lib.system.sysinfo
182+
- name: Unit Tests
159183
run: py.test -v tests
160184
- name: End to End Tests
161185
run: python tests/simple_tests.py

.gitignore

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
!/requirements/
88
!/requirements/*requirements*.txt
99
!/requirements/*conda*.yml
10+
!/requirements/*.py
1011

1112
# Root files
1213
!Dockerfile*
13-
!.pylintrc
14-
!setup.cfg
14+
!pyproject.toml
15+
!.gitignore
1516
!.travis.yml
1617
!/faceswap.py
1718
!/setup.py
@@ -27,13 +28,20 @@
2728
!config/
2829
!.readthedocs.yml
2930
!docs/
30-
!docs/full**
31-
!docs/_static**
31+
!docs/_static/
32+
!docs/_static/*.png
33+
!docs/full/
34+
!docs/full/**/
35+
!docs/full/**/*.rst
3236
!locales/
3337
!locales/**
38+
39+
# Test files
3440
!tests/
3541
!tests/**/
3642
!tests/**/*.py
43+
!tests/**/*.mp4
44+
!tests/**/*.jpg
3745

3846
# Core files
3947
!.fs_cache

.install/linux/faceswap_setup_x64.sh

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
# TODO force conda-forge
23

34
TMP_DIR="/tmp/faceswap_install"
45
DL_CONDA="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh"
@@ -12,10 +13,11 @@ DIR_CONDA="$HOME/miniconda3"
1213
CONDA_EXECUTABLE="${DIR_CONDA}/bin/conda"
1314
CONDA_TO_PATH=false
1415
ENV_NAME="faceswap"
15-
PYENV_VERSION="3.10"
16+
PYENV_VERSION="3.13"
1617

1718
DIR_FACESWAP="$HOME/faceswap"
1819
VERSION="nvidia"
20+
LIB_VERSION="13"
1921

2022
DESKTOP=false
2123

@@ -145,6 +147,40 @@ ask_version() {
145147
done
146148
}
147149

150+
151+
ask_cuda_version() {
152+
# Ask which Cuda Version to install
153+
while true; do
154+
default=1
155+
read -rp $'\e[36mSelect:\t1: RTX 20xx ->\n\t2: GTX 9xx - GTX 10xx\n\t3: GTX 7xx - GTX 9xx\n'"[default: $default]: "$'\e[97m' vers
156+
vers="${vers:-${default}}"
157+
case $vers in
158+
1) LIB_VERSION="13" ; break ;;
159+
2) LIB_VERSION="12" ; break ;;
160+
3) LIB_VERSION="11" ; break ;;
161+
* ) echo "Invalid selection." ;;
162+
esac
163+
done
164+
}
165+
166+
167+
ask_rocm_version() {
168+
# Ask which Cuda Version to install
169+
while true; do
170+
default=1
171+
read -rp $'\e[36mSelect:\t1: ROCm 6.4\n\t2: ROCm 6.3\n\t3: ROCm 6.2\n\t4: ROCm 6.1\n\t5: ROCm 6.0\n'"[default: $default]: "$'\e[97m' vers
172+
vers="${vers:-${default}}"
173+
case $vers in
174+
1) LIB_VERSION="64" ; break ;;
175+
2) LIB_VERSION="63" ; break ;;
176+
3) LIB_VERSION="62" ; break ;;
177+
4) LIB_VERSION="61" ; break ;;
178+
5) LIB_VERSION="60" ; break ;;
179+
* ) echo "Invalid selection." ;;
180+
esac
181+
done
182+
}
183+
148184
banner () {
149185
echo -e " \e[32m 001"
150186
echo -e " \e[32m 11 10 010"
@@ -280,7 +316,15 @@ faceswap_opts () {
280316
latest graphics card drivers installed from the relevant vendor. Please select the version\
281317
of Faceswap you wish to install."
282318
ask_version
319+
if [ $VERSION == "nvidia" ] ; then
320+
info "Depending on your GPU a different version of Cuda may be required. Please select the \
321+
generation of Nvidia GPU you use below."
322+
ask_cuda_version
323+
fi
283324
if [ $VERSION == "rocm" ] ; then
325+
info "Depending on your installed version of ROCm a different version of PyTorch may be required. \
326+
Please select the ROCm version you use below."
327+
ask_rocm_version
284328
warn "ROCm support is experimental. Please make sure that your GPU is supported by ROCm and that \
285329
ROCm has been installed on your system before proceeding. Installation instructions: \
286330
https://docs.amd.com/bundle/ROCm_Installation_Guidev5.0/page/Overview_of_ROCm_Installation_Methods.html"
@@ -322,7 +366,11 @@ review() {
322366
fi
323367
echo " - Faceswap will be installed in '$DIR_FACESWAP'"
324368
echo " - Installing for '$VERSION'"
369+
if [ $VERSION == "nvidia" ] ; then
370+
echo " - Cuda version $LIB_VERSION will be used"
371+
fi
325372
if [ $VERSION == "rocm" ] ; then
373+
echo " - ROCm version '$LIB_VERSION' will be used"
326374
echo -e " \e[33m- Note: Please ensure that ROCm is supported by your GPU\e[97m"
327375
echo -e " \e[33m and is installed prior to proceeding.\e[97m"
328376
fi
@@ -364,10 +412,10 @@ delete_env() {
364412
}
365413

366414
create_env() {
367-
# Create Python 3.10 env for faceswap
415+
# Create Python 3.13 env for faceswap
368416
delete_env
369417
info "Creating Conda Virtual Environment..."
370-
yellow ; "$CONDA_EXECUTABLE" create -n "$ENV_NAME" -c defaults -q python="$PYENV_VERSION" -y
418+
yellow ; "$CONDA_EXECUTABLE" create -n "$ENV_NAME" -c conda-forge -q python="$PYENV_VERSION" -y
371419
}
372420

373421

@@ -404,7 +452,7 @@ clone_faceswap() {
404452
setup_faceswap() {
405453
# Run faceswap setup script
406454
info "Setting up Faceswap..."
407-
python -u "$DIR_FACESWAP/setup.py" --installer --$VERSION
455+
python -u "$DIR_FACESWAP/setup.py" --installer --$VERSION$LIB_VERSION
408456
}
409457

410458
create_gui_launcher () {

.install/macos/faceswap_setup_macos.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DIR_CONDA="$HOME/miniconda3"
1515
CONDA_EXECUTABLE="${DIR_CONDA}/bin/conda"
1616
CONDA_TO_PATH=false
1717
ENV_NAME="faceswap"
18-
PYENV_VERSION="3.10"
18+
PYENV_VERSION="3.13"
1919

2020
DIR_FACESWAP="$HOME/faceswap"
2121
VERSION="nvidia"
@@ -405,10 +405,10 @@ delete_env() {
405405
}
406406

407407
create_env() {
408-
# Create Python 3.10 env for faceswap
408+
# Create Python 3.13 env for faceswap
409409
delete_env
410410
info "Creating Conda Virtual Environment..."
411-
yellow ; "$CONDA_EXECUTABLE" create -n "$ENV_NAME" -c defaults -q python="$PYENV_VERSION" -y
411+
yellow ; "$CONDA_EXECUTABLE" create -n "$ENV_NAME" -c conda-forge -q python="$PYENV_VERSION" -y
412412
}
413413

414414

0 commit comments

Comments
 (0)