Skip to content

Commit

Permalink
Update Dependencies (deepfakes#950)
Browse files Browse the repository at this point in the history
* 1st Round update for Python 3.7, TF1.15, Keras2.3
    Move Tensorflow logging verbosity prior to first tensorflow import
    Keras Optimizers and nn_block update
    lib.logger - Change tf deprecation messages from WARNING to DEBUG
    Raise Tensorflow Max version check to 1.15
    Update requirements and conda check for python 3.7+
    Update install scripts, travis and documentation to Python 3.7

* Revert Keras to 2.2.4
  • Loading branch information
torzdf authored Dec 10, 2019
1 parent 6afa6a9 commit ef03be1
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .install/linux/faceswap_setup_x64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ delete_env() {
}

create_env() {
# Create Python 3.6 env for faceswap
# Create Python 3.7 env for faceswap
delete_env
info "Creating Conda Virtual Environment..."
yellow ; "$CONDA_EXECUTABLE" create -n "$ENV_NAME" -q python=3.6 -y
yellow ; "$CONDA_EXECUTABLE" create -n "$ENV_NAME" -q python=3.7 -y
}


Expand Down
2 changes: 1 addition & 1 deletion .install/windows/install.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ InstallDir $PROFILE\faceswap
# Install cli flags
!define flagsConda "/S /RegisterPython=0 /AddToPath=0 /D=$PROFILE\MiniConda3"
!define flagsRepo "--depth 1 --no-single-branch ${wwwRepo}"
!define flagsEnv "-y python=3.6"
!define flagsEnv "-y python=3.7"

# Folders
Var ProgramData
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ language: shell

env:
global:
- CONDA_PYTHON=3.6
- CONDA_PYTHON=3.7
- CONDA_BLD_PATH=${HOME}/conda-bld

os:
Expand Down
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ Reboot your PC, so that everything you have just installed gets registered.
- Select "Create" at the bottom
- In the pop up:
- Give it the name: faceswap
- **IMPORTANT**: Select python version 3.6
- Hit "Create" (NB: This may take a while as it will need to download Python 3.6)
- **IMPORTANT**: Select python version 3.7
- Hit "Create" (NB: This may take a while as it will need to download Python 3.7)
![Anaconda virtual env setup](https://i.imgur.com/59RHnLs.png)

#### Entering your virtual environment
Expand Down
5 changes: 3 additions & 2 deletions lib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from lib.logger import crash_log, log_setup
from lib.model.masks import get_available_masks, get_default_mask
from lib.utils import FaceswapError, get_backend, safe_shutdown
from lib.utils import FaceswapError, get_backend, safe_shutdown, set_system_verbosity
from plugins.plugin_loader import PluginLoader

logger = logging.getLogger(__name__) # pylint: disable=invalid-name
Expand Down Expand Up @@ -46,7 +46,7 @@ def import_script(self):
def test_for_tf_version():
""" Check that the minimum required Tensorflow version is installed """
min_ver = 1.12
max_ver = 1.14
max_ver = 1.15
try:
# Ensure tensorflow doesn't pin all threads to one core when using tf-mkl
os.environ["KMP_AFFINITY"] = "disabled"
Expand Down Expand Up @@ -113,6 +113,7 @@ def check_display():

def execute_script(self, arguments):
""" Run the script for called command """
set_system_verbosity(arguments.loglevel)
is_gui = hasattr(arguments, "redirect_gui") and arguments.redirect_gui
log_setup(arguments.loglevel, arguments.logfile, self.command, is_gui)
logger.debug("Executing: %s. PID: %s", self.command, os.getpid())
Expand Down
10 changes: 10 additions & 0 deletions lib/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class FaceswapFormatter(logging.Formatter):

def format(self, record):
record.message = record.getMessage()
record = self.rewrite_tf_deprecation(record)
# strip newlines
if "\n" in record.message or "\r" in record.message:
record.message = record.message.replace("\n", "\\n").replace("\r", "\\r")
Expand All @@ -64,6 +65,15 @@ def format(self, record):
msg = msg + self.formatStack(record.stack_info)
return msg

@staticmethod
def rewrite_tf_deprecation(record):
""" Change TF deprecation messages from WARNING to DEBUG """
if record.levelno == 30 and (record.funcName == "_tfmw_add_deprecation_warning" or
record.module == "deprecation"):
record.levelno = 10
record.levelname = "DEBUG"
return record


class RollingBuffer(collections.deque):
"""File-like that keeps a certain number of lines of text in memory."""
Expand Down
3 changes: 2 additions & 1 deletion lib/sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def encoding(self):
@property
def is_conda(self):
""" Boolean for whether in a conda environment """
return "conda" in sys.version.lower()
return ("conda" in sys.version.lower() or
os.path.exists(os.path.join(sys.prefix, 'conda-meta')))

@property
def is_linux(self):
Expand Down
3 changes: 1 addition & 2 deletions lib/vgg_face2_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import cv2
import numpy as np
from fastcluster import linkage, linkage_vector
from lib.utils import GetModel, set_system_verbosity, FaceswapError
from lib.utils import GetModel, FaceswapError

logger = logging.getLogger(__name__) # pylint: disable=invalid-name

Expand Down Expand Up @@ -41,7 +41,6 @@ class VGGFace2():
def __init__(self, backend="GPU", loglevel="INFO"):
logger.debug("Initializing %s: (backend: %s, loglevel: %s)",
self.__class__.__name__, backend, loglevel)
set_system_verbosity(loglevel)
backend = backend.upper()
git_model_id = 10
model_filename = ["vggface2_resnet50_v2.h5"]
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
tqdm
psutil
pathlib
numpy==1.16.2
opencv-python==4.1.1.26
numpy==1.17.4
opencv-python==4.1.2.30
scikit-image
Pillow==6.1.0
Pillow==6.2.1
scikit-learn
toposort
fastcluster
matplotlib==2.2.2
imageio==2.5.0
matplotlib==3.1.1
imageio==2.6.1
imageio-ffmpeg
ffmpy==0.2.2
# Revert back to nvidia-ml-py3 when windows/system32 patch is implemented
Expand All @@ -18,7 +18,7 @@ git+https://github.com/deepfakes/nvidia-ml-py3.git
h5py==2.9.0
Keras==2.2.4
pywin32 ; sys_platform == "win32"
pynvx==0.0.4 ; sys_platform == "darwin"
pynvx==1.0.0 ; sys_platform == "darwin"

# tensorflow is included within the docker image.
# If you are looking for dependencies for a manual install,
Expand Down
1 change: 0 additions & 1 deletion scripts/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Convert():
def __init__(self, arguments):
logger.debug("Initializing %s: (args: %s)", self.__class__.__name__, arguments)
self.args = arguments
Utils.set_verbosity(self.args.loglevel)

self.patch_threads = None
self.images = Images(self.args)
Expand Down
1 change: 0 additions & 1 deletion scripts/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class Extract():
def __init__(self, arguments):
logger.debug("Initializing %s: (args: %s", self.__class__.__name__, arguments)
self._args = arguments
Utils.set_verbosity(self._args.loglevel)

self._output_dir = str(get_folder(self._args.output_dir))

Expand Down
7 changes: 1 addition & 6 deletions scripts/fsmedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from lib.alignments import Alignments as AlignmentsBase
from lib.face_filter import FaceFilter as FilterFunc
from lib.image import count_frames, read_image
from lib.utils import (camel_case_split, get_image_paths, set_system_verbosity, _video_extensions)
from lib.utils import (camel_case_split, get_image_paths, _video_extensions)

logger = logging.getLogger(__name__) # pylint: disable=invalid-name

Expand All @@ -24,11 +24,6 @@ class Utils():
""" Holds utility functions that are required by more than one media
object """

@staticmethod
def set_verbosity(loglevel):
""" Set the system output verbosity """
set_system_verbosity(loglevel)

@staticmethod
def finalize(images_found, num_faces_detected, verify_output):
""" Finalize the image processing """
Expand Down
2 changes: 0 additions & 2 deletions scripts/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from lib.gui import (TaskBar, CliOptions, CommandNotebook, ConsoleOut, Session, DisplayNotebook,
get_images, initialize_images, initialize_config, LastSession,
MainMenuBar, ProcessWrapper, StatusBar)
from lib.utils import set_system_verbosity

logger = logging.getLogger(__name__) # pylint: disable=invalid-name

Expand Down Expand Up @@ -208,7 +207,6 @@ def _confirm_close_on_running_task(self):
class Gui(): # pylint: disable=too-few-public-methods
""" The GUI process. """
def __init__(self, arguments):
set_system_verbosity(arguments.loglevel)
self.root = FaceswapGui(arguments.debug)

def process(self):
Expand Down
3 changes: 1 addition & 2 deletions scripts/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from lib.image import read_image
from lib.keypress import KBHit
from lib.multithreading import MultiThread
from lib.utils import get_folder, get_image_paths, set_system_verbosity, deprecation_warning
from lib.utils import get_folder, get_image_paths, deprecation_warning
from plugins.plugin_loader import PluginLoader

logger = logging.getLogger(__name__) # pylint: disable=invalid-name
Expand Down Expand Up @@ -151,7 +151,6 @@ def process(self):
deprecation_warning("`-nac`, ``--no-augment-color``",
additional_info="This option will be available within training "
"config settings (/config/train.ini).")
set_system_verbosity(self._args.loglevel)
thread = self._start_thread()
# from lib.queue_manager import queue_manager; queue_manager.debug_monitor(1)

Expand Down
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
INSTALL_FAILED = False
# Revisions of tensorflow-gpu and cuda/cudnn requirements
TENSORFLOW_REQUIREMENTS = {"==1.12.0": ["9.0", "7.2"],
">=1.13.1,<1.15": ["10.0", "7.4"]} # TF 2.0 Not currently supported
">=1.13.1,<1.16": ["10.0", "7.4"]} # TF 2.0 Not currently supported
# Mapping of Python packages to their conda names if different from pypi or in non-default channel
CONDA_MAPPING = {
# "opencv-python": ("opencv", "conda-forge"), # Periodic issues with conda-forge opencv
Expand Down Expand Up @@ -74,7 +74,8 @@ def py_version(self):
@property
def is_conda(self):
""" Check whether using Conda """
return bool("conda" in sys.version.lower())
return ("conda" in sys.version.lower() or
os.path.exists(os.path.join(sys.prefix, 'conda-meta')))

@property
def ld_library_path(self):
Expand Down Expand Up @@ -220,7 +221,7 @@ def update_tf_dep(self):
return

if not self.enable_cuda:
self.required_packages.append("tensorflow==1.14.0")
self.required_packages.append("tensorflow==1.15.0")
return

tf_ver = None
Expand Down Expand Up @@ -266,9 +267,9 @@ def update_tf_dep(self):
def update_tf_dep_conda(self):
""" Update Conda TF Dependency """
if not self.enable_cuda:
self.required_packages.append("tensorflow==1.14.0")
self.required_packages.append("tensorflow==1.15.0")
else:
self.required_packages.append("tensorflow-gpu==1.14.0")
self.required_packages.append("tensorflow-gpu==1.15.0")

def update_amd_dep(self):
""" Update amd dependency for AMD cards """
Expand Down
3 changes: 0 additions & 3 deletions tools/alignments.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python3
""" Tools for manipulating the alignments seralized file """
import logging

from lib.utils import set_system_verbosity
from .lib_alignments import (AlignmentData, Check, Dfl, Draw, # noqa pylint: disable=unused-import
Extract, Fix, Manual, Merge, Rename,
RemoveAlignments, Sort, Spatial, UpdateHashes)
Expand All @@ -15,7 +13,6 @@ class Alignments():
def __init__(self, arguments):
logger.debug("Initializing %s: (arguments: '%s'", self.__class__.__name__, arguments)
self.args = arguments
set_system_verbosity(self.args.loglevel)
self.alignments = self.load_alignments()
logger.debug("Initialized %s", self.__class__.__name__)

Expand Down
3 changes: 1 addition & 2 deletions tools/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from lib.image import ImagesLoader, ImagesSaver

from lib.multithreading import MultiThread
from lib.utils import set_system_verbosity, get_folder
from lib.utils import get_folder
from plugins.extract.pipeline import Extractor, ExtractMedia


Expand All @@ -33,7 +33,6 @@ class Mask():
"""
def __init__(self, arguments):
logger.debug("Initializing %s: (arguments: %s", self.__class__.__name__, arguments)
set_system_verbosity(arguments.loglevel)
self._update_type = arguments.processing
self._input_is_faces = arguments.input_type == "faces"
self._mask_type = arguments.masker
Expand Down
3 changes: 1 addition & 2 deletions tools/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from lib.faces_detect import DetectedFace
from lib.model.masks import get_available_masks
from lib.multithreading import MultiThread
from lib.utils import FaceswapError, set_system_verbosity
from lib.utils import FaceswapError
from lib.queue_manager import queue_manager
from scripts.fsmedia import Alignments, Images
from scripts.convert import Predict
Expand All @@ -42,7 +42,6 @@ class Preview():

def __init__(self, arguments):
logger.debug("Initializing %s: (arguments: '%s'", self.__class__.__name__, arguments)
set_system_verbosity(arguments.loglevel)
self.config_tools = ConfigTools()
self.lock = Lock()
self.trigger_patch = Event()
Expand Down

0 comments on commit ef03be1

Please sign in to comment.