mirror of
https://github.com/deepfakes/faceswap
synced 2025-06-08 20:13:52 -04:00
Fix: Occasional memory leak in convert Fix: Dynamic config loading in Windows Change: Better folder naming for snapshots
43 lines
1.8 KiB
Python
43 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
|
|
from lib.utils import full_path_split
|
|
|
|
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 = ".".join(full_path_split(dirpath.replace(base_path, ""))[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)
|