1
0
Fork 0
mirror of https://github.com/deepfakes/faceswap synced 2025-06-09 04:36:50 -04:00
faceswap/plugins/extract/_config.py
torzdf 0eff0a1719 Config Changes + Bugfixes
Bugfix: Fully disable keypress monitor for GUI
Bugfix: Preview - Handle missing alignments file
Config changes:
    - Separate plugin defaults into their own files
    - Move mask_type to global training config
    - Add ability to pass in custom config files
2019-06-11 01:13:42 +00:00

42 lines
1.8 KiB
Python

#!/usr/bin/env python3
""" Default configurations for extract """
import logging
import os
import sys
from importlib import import_module
from lib.config import FaceswapConfig
logger = logging.getLogger(__name__) # pylint: disable=invalid-name
class Config(FaceswapConfig):
""" Config File for Models """
def set_defaults(self):
""" Set the default values for config """
logger.debug("Setting defaults")
current_dir = os.path.dirname(__file__)
for dirpath, _, filenames in os.walk(current_dir):
default_files = [fname for fname in filenames if fname.endswith("_defaults.py")]
if not default_files:
continue
base_path = os.path.dirname(os.path.realpath(sys.argv[0]))
import_path = dirpath.replace(base_path, "").replace("/", ".")[1:]
plugin_type = import_path.split(".")[-1]
for filename in default_files:
self.load_module(filename, import_path, plugin_type)
def load_module(self, filename, module_path, plugin_type):
""" Load the defaults module and add defaults """
logger.debug("Adding defaults: (filename: %s, module_path: %s, plugin_type: %s",
filename, module_path, plugin_type)
module = os.path.splitext(filename)[0]
section = ".".join((plugin_type, module.replace("_defaults", "")))
logger.debug("Importing defaults module: %s.%s", module_path, module)
mod = import_module("{}.{}".format(module_path, module))
self.add_section(title=section, info=mod._HELPTEXT) # pylint:disable=protected-access
for key, val in mod._DEFAULTS.items(): # pylint:disable=protected-access
self.add_item(section=section, title=key, **val)
logger.debug("Added defaults: %s", section)