mirror of
https://github.com/zebrajr/faceswap.git
synced 2025-12-06 12:20:27 +01:00
Bump minimum TF Version
This commit is contained in:
parent
5c9fa1aa03
commit
20a657d6cf
|
|
@ -1,4 +1,4 @@
|
|||
FROM tensorflow/tensorflow:2.2.1-py3
|
||||
FROM tensorflow/tensorflow:2.8.2
|
||||
|
||||
# To disable tzdata and others from asking for input
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
|
|
|
|||
12
INSTALL.md
12
INSTALL.md
|
|
@ -21,13 +21,21 @@
|
|||
- [Create a desktop shortcut](#create-a-desktop-shortcut)
|
||||
- [Updating faceswap](#updating-faceswap)
|
||||
- [macOS (Apple Silicon) Install Guide](#macos-apple-silicon-install-guide)
|
||||
- [Prerequisites](#prerequisites-2)
|
||||
- [OS](#os)
|
||||
- [XCode Tools](#xcode-tools)
|
||||
- [XQuartz](#xquartz)
|
||||
- [Conda](#conda)
|
||||
- [Setup](#setup-1)
|
||||
- [faceswap](#faceswap-1)
|
||||
- [Easy install](#easy-install-1)
|
||||
- [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)
|
||||
- [Setup](#setup-1)
|
||||
- [Setup](#setup-2)
|
||||
- [About some of the options](#about-some-of-the-options)
|
||||
- [Run the project](#run-the-project)
|
||||
- [Notes](#notes)
|
||||
|
|
@ -193,7 +201,7 @@ Obtain git for your distribution from the [git website](https://git-scm.com/down
|
|||
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)
|
||||
|
||||
Alternatively you can install Python (>= 3.7-3.8 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.2. Release v1.0: Tensorflow 1.15). You can check for the compatible versions here: (https://www.tensorflow.org/install/source#gpu).
|
||||
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).
|
||||
- Python distributions:
|
||||
- apt/yum install python3 (Linux)
|
||||
- [Installer](https://www.python.org/downloads/release/python-368/) (Windows)
|
||||
|
|
|
|||
|
|
@ -53,9 +53,10 @@ class ScriptExecutor(): # pylint:disable=too-few-public-methods
|
|||
Raises
|
||||
------
|
||||
FaceswapError
|
||||
If Tensorflow is not found, or is not between versions 2.2 and 2.8
|
||||
If Tensorflow is not found, or is not between versions 2.4 and 2.8
|
||||
"""
|
||||
min_ver = 2.2
|
||||
amd_ver = 2.2
|
||||
min_ver = 2.4
|
||||
max_ver = 2.8
|
||||
try:
|
||||
# Ensure tensorflow doesn't pin all threads to one core when using Math Kernel Library
|
||||
|
|
@ -78,14 +79,19 @@ class ScriptExecutor(): # pylint:disable=too-few-public-methods
|
|||
self._handle_import_error(msg)
|
||||
|
||||
tf_ver = get_tf_version()
|
||||
if tf_ver < min_ver:
|
||||
backend = get_backend()
|
||||
if backend != "amd" and tf_ver < min_ver:
|
||||
msg = (f"The minimum supported Tensorflow is version {min_ver} but you have version "
|
||||
f"{tf_ver} installed. Please upgrade Tensorflow.")
|
||||
self._handle_import_error(msg)
|
||||
if tf_ver > max_ver:
|
||||
if backend != "amd" and tf_ver > max_ver:
|
||||
msg = (f"The maximum supported Tensorflow is version {max_ver} but you have version "
|
||||
f"{tf_ver} installed. Please downgrade Tensorflow.")
|
||||
self._handle_import_error(msg)
|
||||
if backend == "amd" and tf_ver != amd_ver:
|
||||
msg = (f"The supported Tensorflow version for AMD cards is {amd_ver} but you have "
|
||||
"version {tf_ver} installed. Please install the correct version.")
|
||||
self._handle_import_error(msg)
|
||||
logger.debug("Installed Tensorflow Version: %s", tf_ver)
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ from lib.serializer import get_serializer
|
|||
from lib.model.backup_restore import Backup
|
||||
from lib.model import losses, optimizers
|
||||
from lib.model.nn_blocks import set_config as set_nnblock_config
|
||||
from lib.utils import get_backend, get_tf_version, FaceswapError
|
||||
from lib.utils import get_backend, FaceswapError
|
||||
from plugins.train._config import Config
|
||||
|
||||
if get_backend() == "amd":
|
||||
|
|
@ -433,7 +433,8 @@ class ModelBase():
|
|||
10 ** int(self.config["epsilon_exponent"]),
|
||||
self._args).optimizer
|
||||
if self._settings.use_mixed_precision:
|
||||
optimizer = self._settings.loss_scale_optimizer(optimizer)
|
||||
optimizer = tf.keras.mixed_precision.LossScaleOptimizer(optimizer)
|
||||
|
||||
if get_backend() == "amd":
|
||||
self._rewrite_plaid_outputs()
|
||||
|
||||
|
|
@ -714,14 +715,6 @@ class _Settings():
|
|||
self._set_tf_settings(allow_growth, arguments.exclude_gpus)
|
||||
|
||||
use_mixed_precision = not is_predict and mixed_precision and get_backend() == "nvidia"
|
||||
# Mixed precision moved out of experimental in tensorflow 2.4
|
||||
if use_mixed_precision and get_tf_version() < 2.4:
|
||||
self._mixed_precision = tf.keras.mixed_precision.experimental
|
||||
elif use_mixed_precision:
|
||||
self._mixed_precision = tf.keras.mixed_precision
|
||||
else:
|
||||
self._mixed_precision = None
|
||||
|
||||
self._use_mixed_precision = self._set_keras_mixed_precision(use_mixed_precision,
|
||||
bool(arguments.exclude_gpus))
|
||||
|
||||
|
|
@ -739,25 +732,6 @@ class _Settings():
|
|||
""" bool: ``True`` if mixed precision training has been enabled, otherwise ``False``. """
|
||||
return self._use_mixed_precision
|
||||
|
||||
def loss_scale_optimizer(self, optimizer):
|
||||
""" Optimize loss scaling for mixed precision training.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
optimizer: :class:`tf.keras.optimizers.Optimizer`
|
||||
The optimizer instance to wrap
|
||||
|
||||
Returns
|
||||
--------
|
||||
:class:`tf.keras.mixed_precision.loss_scale_optimizer.LossScaleOptimizer`
|
||||
The original optimizer with loss scaling applied
|
||||
"""
|
||||
# tensorflow versions < 2.4 had different kwargs where scaling needs to be explicitly
|
||||
# defined
|
||||
kwargs = dict(loss_scale="dynamic") if get_tf_version() < 2.4 else {}
|
||||
logger.debug("tf version: %s, kwargs: %s", get_tf_version(), kwargs)
|
||||
return self._mixed_precision.LossScaleOptimizer(optimizer, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def _set_tf_settings(cls, allow_growth, exclude_devices):
|
||||
""" Specify Devices to place operations on and Allow TensorFlow to manage VRAM growth.
|
||||
|
|
@ -796,7 +770,8 @@ class _Settings():
|
|||
tf.config.experimental.set_memory_growth(gpu, True)
|
||||
logger.debug("Set Tensorflow 'allow_growth' option")
|
||||
|
||||
def _set_keras_mixed_precision(self, use_mixed_precision, exclude_gpus):
|
||||
@classmethod
|
||||
def _set_keras_mixed_precision(cls, use_mixed_precision, exclude_gpus):
|
||||
""" Enable the Keras experimental Mixed Precision API.
|
||||
|
||||
Enables the Keras experimental Mixed Precision API if requested in the user configuration
|
||||
|
|
@ -809,19 +784,6 @@ class _Settings():
|
|||
otherwise ``False``.
|
||||
exclude_gpus: bool
|
||||
``True`` If connected GPUs are being excluded otherwise ``False``.
|
||||
|
||||
There is a bug in Tensorflow 2.2 that will cause a failure if "set_visible_devices" has
|
||||
been set and mixed_precision is enabled. This can happen if GPUs have been excluded.
|
||||
The issue is Specifically in
|
||||
:file:`tensorflow.python.keras.mixed_precision.experimental.device_compatibility_check`
|
||||
|
||||
From doc-string: "if list_local_devices() and tf.config.set_visible_devices() are both
|
||||
called, TensorFlow will crash. However, GPU names and compute capabilities cannot be
|
||||
checked without list_local_devices().
|
||||
|
||||
To get around this, we hack in to set a global parameter to indicate the test has
|
||||
already been performed. This is likely to cause some issues, but not as many as
|
||||
guaranteed failure when limiting GPU devices
|
||||
"""
|
||||
logger.debug("use_mixed_precision: %s, exclude_gpus: %s",
|
||||
use_mixed_precision, exclude_gpus)
|
||||
|
|
@ -831,23 +793,8 @@ class _Settings():
|
|||
return False
|
||||
logger.info("Enabling Mixed Precision Training.")
|
||||
|
||||
if exclude_gpus and get_tf_version() == 2.2:
|
||||
# TODO remove this hacky fix to disable mixed precision compatibility testing when
|
||||
# tensorflow 2.2 support dropped
|
||||
# pylint:disable=import-outside-toplevel,protected-access
|
||||
# pylint:disable=import-error,no-name-in-module
|
||||
from tensorflow.python.keras.mixed_precision.experimental import \
|
||||
device_compatibility_check
|
||||
logger.debug("Overriding tensorflow _logged_compatibility_check parameter. Initial "
|
||||
"value: %s", device_compatibility_check._logged_compatibility_check)
|
||||
device_compatibility_check._logged_compatibility_check = True
|
||||
logger.debug("New value: %s", device_compatibility_check._logged_compatibility_check)
|
||||
|
||||
policy = self._mixed_precision.Policy('mixed_float16')
|
||||
if get_tf_version() < 2.4:
|
||||
self._mixed_precision.set_policy(policy)
|
||||
else:
|
||||
self._mixed_precision.set_global_policy(policy)
|
||||
policy = tf.keras.mixed_precision.Policy('mixed_float16')
|
||||
tf.keras.mixed_precision.set_global_policy(policy)
|
||||
logger.debug("Enabled mixed precision. (Compute dtype: %s, variable_dtype: %s)",
|
||||
policy.compute_dtype, policy.variable_dtype)
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
-r _requirements_base.txt
|
||||
tensorflow>=2.2.0,<2.9.0
|
||||
tensorflow>=2.4.0,<2.9.0
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
-r _requirements_base.txt
|
||||
tensorflow-gpu>=2.2.0,<2.9.0
|
||||
tensorflow-gpu>=2.4.0,<2.9.0
|
||||
|
|
|
|||
69
setup.py
69
setup.py
|
|
@ -17,8 +17,7 @@ from pkg_resources import parse_requirements, Requirement
|
|||
INSTALL_FAILED = False
|
||||
# Revisions of tensorflow GPU and cuda/cudnn requirements. These relate specifically to the
|
||||
# Tensorflow builds available from pypi
|
||||
TENSORFLOW_REQUIREMENTS = {">=2.2.0,<2.4.0": ["10.1", "7.6"],
|
||||
">=2.4.0,<2.5.0": ["11.0", "8.0"],
|
||||
TENSORFLOW_REQUIREMENTS = {">=2.4.0,<2.5.0": ["11.0", "8.0"],
|
||||
">=2.5.0,<2.9.0": ["11.2", "8.1"]}
|
||||
# Mapping of Python packages to their conda names if different from pip or in non-default channel
|
||||
CONDA_MAPPING = {
|
||||
|
|
@ -256,7 +255,7 @@ class Environment():
|
|||
return
|
||||
|
||||
self.output.warning(
|
||||
"The minimum Tensorflow requirement is 2.3 \n"
|
||||
"The minimum Tensorflow requirement is 2.4 \n"
|
||||
"Tensorflow currently has no official prebuild for your CUDA, cuDNN "
|
||||
"combination.\nEither install a combination that Tensorflow supports or "
|
||||
"build and install your own tensorflow-gpu.\r\n"
|
||||
|
|
@ -643,8 +642,6 @@ class Install():
|
|||
not self.env.missing_packages and not self.env.conda_missing_packages):
|
||||
self.output.info("All Dependencies are up to date")
|
||||
return
|
||||
if self.env.updater:
|
||||
self._remove_unrequired_packages()
|
||||
self.install_missing_dep()
|
||||
if self.env.updater:
|
||||
return
|
||||
|
|
@ -691,42 +688,6 @@ class Install():
|
|||
self.env.conda_missing_packages.append(pkg)
|
||||
continue
|
||||
|
||||
def _remove_unrequired_packages(self):
|
||||
""" Remove packages that have been installed by Pip that might now be installed by
|
||||
Conda.
|
||||
|
||||
This specifically relates to tensorflow 2.2 when a Conda version was not available for
|
||||
Windows, so needed to be installed by Pip, with the Cuda toolkit coming from Conda.
|
||||
|
||||
This method is left here in case it is needed in the future. """
|
||||
if not self.env.is_conda or self.env.os_version[0] != "Windows":
|
||||
return
|
||||
installed_pip = self.env.get_installed_packages()
|
||||
if "tensorflow-gpu" not in installed_pip:
|
||||
return
|
||||
if not installed_pip["tensorflow-gpu"].startswith("2.2"):
|
||||
return
|
||||
# The below are a load of pip installed tf dependencies. They may not need to be all
|
||||
# removed, but won't hurt to take them out of pip and put in Conda
|
||||
remove_packages = ["urllib3", "pyasn1", "idna", "chardet", "rsa", "requests",
|
||||
"pyasn1-modules", "oauthlib", "cachetools", "requests-oauthlib",
|
||||
"google-auth", "werkzeug", "tensorboard-plugin-wit", "protobuf",
|
||||
"numpy", "markdown", "grpcio", "google-auth-oauthlib", "absl-py",
|
||||
"wrapt", "termcolor", "tensorflow-gpu-estimator", "tensorboard",
|
||||
"opt-einsum", "keras-preprocessing", "h5py", "google-pasta", "gast",
|
||||
"astunparse", "tensorflow-gpu"]
|
||||
self.output.info("Uninstalling Pip Tensorflow 2.2")
|
||||
pipexe = [sys.executable, "-m", "pip", "uninstall", "-y", "-qq"]
|
||||
if not self.env.is_admin and not self.env.is_virtualenv:
|
||||
pipexe.append("--user")
|
||||
pipexe.extend([pkg for pkg in remove_packages if pkg in installed_pip])
|
||||
|
||||
try:
|
||||
run(pipexe, check=True)
|
||||
except CalledProcessError:
|
||||
self.output.warning("Couldn't remove Tensorflow 2.2 with pip. You should attempt this "
|
||||
"manually")
|
||||
|
||||
def install_missing_dep(self):
|
||||
""" Install missing dependencies """
|
||||
# Install conda packages first
|
||||
|
|
@ -841,32 +802,6 @@ class Install():
|
|||
self.output.warning(f"Couldn't install {package} with pip. "
|
||||
"Please install this package manually")
|
||||
|
||||
def _tensorflow_dependency_install(self):
|
||||
""" Install the Cuda/cuDNN dependencies from Conda when tensorflow is not available
|
||||
in Conda.
|
||||
|
||||
This was used whilst Tensorflow 2.2 was not available for Windows in Conda. It is kept
|
||||
here in case it is required again in the future.
|
||||
"""
|
||||
# TODO This will need to be more robust if/when we accept multiple Tensorflow Versions
|
||||
versions = list(TENSORFLOW_REQUIREMENTS.values())[-1]
|
||||
condaexe = ["conda", "search"]
|
||||
pkgs = ["cudatoolkit", "cudnn"]
|
||||
shell = self.env.os_version[0] == "Windows"
|
||||
for pkg in pkgs:
|
||||
with Popen(condaexe + [pkg], shell=shell, stdout=PIPE) as chk:
|
||||
available = [line.split()
|
||||
for line
|
||||
in chk.communicate()[0].decode(self.env.encoding).splitlines()
|
||||
if line.startswith(pkg)]
|
||||
compatible = [req for req in available
|
||||
if (pkg == "cudatoolkit" and req[1].startswith(versions[0]))
|
||||
or (pkg == "cudnn" and versions[0] in req[2]
|
||||
and req[1].startswith(versions[1]))]
|
||||
|
||||
candidate = "==".join(sorted(compatible, key=lambda x: x[1])[-1][:2])
|
||||
self.conda_installer(candidate, verbose=True, conda_only=True)
|
||||
|
||||
|
||||
class Tips():
|
||||
""" Display installation Tips """
|
||||
|
|
|
|||
|
|
@ -31,6 +31,5 @@ def test_backend(dummy): # pylint:disable=unused-argument
|
|||
def test_keras(dummy): # pylint:disable=unused-argument
|
||||
""" Sanity check to ensure that tensorflow keras is being used for CPU and standard
|
||||
keras for AMD. """
|
||||
assert ((_BACKEND == "cpu" and keras.__version__ in ("2.3.0-tf", "2.4.0",
|
||||
"2.6.0", "2.7.0", "2.8.0")) or
|
||||
assert ((_BACKEND == "cpu" and keras.__version__ in ("2.4.0", "2.6.0", "2.7.0", "2.8.0")) or
|
||||
(_BACKEND == "amd" and keras.__version__ == "2.2.4"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user