1
0
Fork 0
mirror of https://github.com/deepfakes/faceswap synced 2025-06-09 04:36:50 -04:00
faceswap/tools/model/cli.py
torzdf 6a3b674bef
Rebase code (#1326)
* Remove tensorflow_probability requirement

* setup.py - fix progress bars

* requirements.txt: Remove pre python 3.9 packages

* update apple requirements.txt

* update INSTALL.md

* Remove python<3.9 code

* setup.py - fix Windows Installer

* typing: python3.9 compliant

* Update pytest and readthedocs python versions

* typing fixes

* Python Version updates
  - Reduce max version to 3.10
  - Default to 3.10 in installers
  - Remove incompatible 3.11 tests

* Update dependencies

* Downgrade imageio dep for Windows

* typing: merge optional unions and fixes

* Updates
  - min python version 3.10
  - typing to python 3.10 spec
  - remove pre-tf2.10 code
  - Add conda tests

* train: re-enable optimizer saving

* Update dockerfiles

* Update setup.py
  - Apple Conda deps to setup.py
  - Better Cuda + dependency handling

* bugfix: Patch logging to prevent Autograph errors

* Update dockerfiles

* Setup.py - Setup.py - stdout to utf-8

* Add more OSes to github Actions

* suppress mac-os end to end test
2023-06-27 11:27:47 +01:00

69 lines
3 KiB
Python

#!/usr/bin/env python3
""" Command Line Arguments for tools """
import gettext
import typing as T
from lib.cli.args import FaceSwapArgs
from lib.cli.actions import DirFullPaths, Radio
# LOCALES
_LANG = gettext.translation("tools.restore.cli", localedir="locales", fallback=True)
_ = _LANG.gettext
_HELPTEXT = _("This tool lets you perform actions on saved Faceswap models.")
class ModelArgs(FaceSwapArgs):
""" Class to perform actions on model files """
@staticmethod
def get_info() -> str:
""" Return command information """
return _("A tool for performing actions on Faceswap trained model files")
@staticmethod
def get_argument_list() -> list[dict[str, T.Any]]:
""" Put the arguments in a list so that they are accessible from both argparse and gui """
argument_list = []
argument_list.append(dict(
opts=("-m", "--model-dir"),
action=DirFullPaths,
dest="model_dir",
required=True,
help=_("Model directory. A directory containing the model you wish to perform an "
"action on.")))
argument_list.append(dict(
opts=("-j", "--job"),
action=Radio,
type=str,
choices=("inference", "nan-scan", "restore"),
required=True,
help=_("R|Choose which action you want to perform."
"\nL|'inference' - Create an inference only copy of the model. Strips any "
"layers from the model which are only required for training. NB: This is for "
"exporting the model for use in external applications. Inference generated "
"models cannot be used within Faceswap. See the 'format' option for specifying "
"the model output format."
"\nL|'nan-scan' - Scan the model file for NaNs or Infs (invalid data)."
"\nL|'restore' - Restore a model from backup.")))
argument_list.append(dict(
opts=("-f", "--format"),
action=Radio,
type=str,
choices=("h5", "saved-model"),
default="h5",
group=_("inference"),
help=_("R|The format to save the model as. Note: Only used for 'inference' job."
"\nL|'h5' - Standard Keras H5 format. Does not store any custom layer "
"information. Layers will need to be loaded from Faceswap to use."
"\nL|'saved-model' - Tensorflow's Saved Model format. Contains all information "
"required to load the model outside of Faceswap.")))
argument_list.append(dict(
opts=("-s", "--swap-model"),
action="store_true",
dest="swap_model",
default=False,
group=_("inference"),
help=_("Only used for 'inference' job. Generate the inference model for B -> A "
"instead of A -> B.")))
return argument_list