Files
faceswap/tools.py

49 lines
1.5 KiB
Python
Raw Normal View History

Adding tools.py as main script for using tools, as well as integrating all feature requests from #255 and #278 (#298) * Add tools.py command and control script for use as the main interface for various tools. The structure and approach is the same as faceswap.py Add many new features to tools/sort.py: various new sorting methods, grouping by folders, logging file renaming/movemeng, keeping original files in the input directory and improved cli options documentation. Argument parsing has been re-written to inteface with tools.py Add __init__.py empty file in tools directory for python to register it as a module so that sort.py and future tools can be easily imported. * Fix various bugs where the correct sorting method would not get called. Add new sorting methon: face-cnn-dissim. Update help documentation for face-cnn-dissim. Change default grouping to rename. Update initial print in all sorting/grouping methods to say precisely which method is being used. * Major refactor and redesign. Use dynamic method allocation to avoid large amounts of nested if-elif statements in process() function and to allow easily combine sort and group methods. Change cli arguments to make them more intuitive and work with the new design. Previous: '-g/--grouping' -> '-f/--final-processing' {folders,rename} Previous: '-by/--by' -> '-s/--sort-by' {blur,face,face-cnn,face-cnn-dissim,face-dissim,hist,hist-dissim} New: '-g/--group-by' {blur,face,face-cnn,hist} Add: '--logfile' -> '-lg/--logfile' PATH_TO_LOGFILE Greatly improve grouping performance. Grouping now has to sort using one of the sorting methods which makes the grouping stable and no longer dependent on how well the the target files are already sorted. Sorting and grouping methods can be combined in any way. If no -g/--group-by is specified by user, it will default to group by the non '-dissim' version of sort method. Different combinations of sorting and grouping methods work well for different sets of data. Fixes Fix progress updates not showing properly by setting them to print to stdout instead of stderror. Fix bug in grouping by face-cnn where wrong score method was being called. Misc Add documentation for reload_list() and splice_lists() methods because it's not obvious what they do. Add warning message to tools.py to tell users to make sure they understand how the tool they want to use works before using it. Add warning message to tools/sort.py to tell users to make sure they undrestand how the sort tool works before using it. Update help documentation to reflect new functionality and options. Set defaults for group by face-cnn to work properly with the correct score method. Amend commit in order to sign it. * Perform unittests for all options and combinations of sort and group methods: everything OK. Fix typos in help documentation.
2018-03-21 11:12:12 +01:00
#!/usr/bin/env python3
Gui v3.0b (#436) * GUI version 3 (#411) GUI version 3.0a * Required for Shaonlu mode (#416) Added two modes - Original and Shaonlu. The later requires this file to function. * model update (#417) New, functional Original 128 model * OriginalHighRes 128 model update (#418) Required for OriginalHighRes Model to function * Add OriginalHighRes 128 update to gui branch (#421) * Required for Shaonlu mode (#416) Added two modes - Original and Shaonlu. The later requires this file to function. * model update (#417) New, functional Original 128 model * OriginalHighRes 128 model update (#418) Required for OriginalHighRes Model to function * Dev gui (#420) * reduce singletons * Fix tooltips and screen boundaries on popup * Remove dpi fix. Fix context filebrowsers * fix tools.py execution and context filebrowser bugs * Bugfixes (#422) * Bump matplotlib requirement. Fix polyfit. Fix TQDM on sort * Fixed memory usage at 6GB cards. (#423) - Switched default encoder to ORIGINAL - Fixed memory consumption. Tested with geforce gtx 9800 ti with 6Gb; batch_size 8 no OOM or memory warnings now. * Staging (#426) * altered trainer (#425) altered trainer to accommodate with model change * Update Model.py (#424) - Added saving state (currently only saved epoch number, to be extended in future) - Changed saving to ThreadPoolExecutor * Add DPI Scaling (#428) * Add dpi scaling * Hotfix for effmpeg. (#429) effmpeg fixed so it works both in cli and gui. Initial work done to add previewing feature to effmpeg (currently does nothing). Some small spacing changes in other files to improve PEP8 conformity. * PEP8 Linting (#430) * pep8 linting * Requirements version bump (#432) * altered trainer (#425) altered trainer to accommodate with model change * Update Model.py (#424) - Added saving state (currently only saved epoch number, to be extended in future) - Changed saving to ThreadPoolExecutor * Requirements version bump (#431) This bumps the versions of: scandir h5py Keras opencv-python to their latest vesions. Virtual Environment will need to be setup again to make use of these. * High DPI Fixes (#433) * dpi scaling * DPI Fixes * Fix and improve context manager. (#434) effmpeg tool: Context manager for GUI fixed. Context manager in general: Functionality extended to allow configuring the context with both: command -> action command -> variable (cli argument) -> action * Change epoch option to iterations * Change epochs to iterations
2018-06-20 19:25:31 +02:00
""" The master tools.py script """
2021-02-18 23:53:01 +00:00
import gettext
import os
Adding tools.py as main script for using tools, as well as integrating all feature requests from #255 and #278 (#298) * Add tools.py command and control script for use as the main interface for various tools. The structure and approach is the same as faceswap.py Add many new features to tools/sort.py: various new sorting methods, grouping by folders, logging file renaming/movemeng, keeping original files in the input directory and improved cli options documentation. Argument parsing has been re-written to inteface with tools.py Add __init__.py empty file in tools directory for python to register it as a module so that sort.py and future tools can be easily imported. * Fix various bugs where the correct sorting method would not get called. Add new sorting methon: face-cnn-dissim. Update help documentation for face-cnn-dissim. Change default grouping to rename. Update initial print in all sorting/grouping methods to say precisely which method is being used. * Major refactor and redesign. Use dynamic method allocation to avoid large amounts of nested if-elif statements in process() function and to allow easily combine sort and group methods. Change cli arguments to make them more intuitive and work with the new design. Previous: '-g/--grouping' -> '-f/--final-processing' {folders,rename} Previous: '-by/--by' -> '-s/--sort-by' {blur,face,face-cnn,face-cnn-dissim,face-dissim,hist,hist-dissim} New: '-g/--group-by' {blur,face,face-cnn,hist} Add: '--logfile' -> '-lg/--logfile' PATH_TO_LOGFILE Greatly improve grouping performance. Grouping now has to sort using one of the sorting methods which makes the grouping stable and no longer dependent on how well the the target files are already sorted. Sorting and grouping methods can be combined in any way. If no -g/--group-by is specified by user, it will default to group by the non '-dissim' version of sort method. Different combinations of sorting and grouping methods work well for different sets of data. Fixes Fix progress updates not showing properly by setting them to print to stdout instead of stderror. Fix bug in grouping by face-cnn where wrong score method was being called. Misc Add documentation for reload_list() and splice_lists() methods because it's not obvious what they do. Add warning message to tools.py to tell users to make sure they understand how the tool they want to use works before using it. Add warning message to tools/sort.py to tell users to make sure they undrestand how the sort tool works before using it. Update help documentation to reflect new functionality and options. Set defaults for group by face-cnn to work properly with the correct score method. Amend commit in order to sign it. * Perform unittests for all options and combinations of sort and group methods: everything OK. Fix typos in help documentation.
2018-03-21 11:12:12 +01:00
import sys
from importlib import import_module
Adding tools.py as main script for using tools, as well as integrating all feature requests from #255 and #278 (#298) * Add tools.py command and control script for use as the main interface for various tools. The structure and approach is the same as faceswap.py Add many new features to tools/sort.py: various new sorting methods, grouping by folders, logging file renaming/movemeng, keeping original files in the input directory and improved cli options documentation. Argument parsing has been re-written to inteface with tools.py Add __init__.py empty file in tools directory for python to register it as a module so that sort.py and future tools can be easily imported. * Fix various bugs where the correct sorting method would not get called. Add new sorting methon: face-cnn-dissim. Update help documentation for face-cnn-dissim. Change default grouping to rename. Update initial print in all sorting/grouping methods to say precisely which method is being used. * Major refactor and redesign. Use dynamic method allocation to avoid large amounts of nested if-elif statements in process() function and to allow easily combine sort and group methods. Change cli arguments to make them more intuitive and work with the new design. Previous: '-g/--grouping' -> '-f/--final-processing' {folders,rename} Previous: '-by/--by' -> '-s/--sort-by' {blur,face,face-cnn,face-cnn-dissim,face-dissim,hist,hist-dissim} New: '-g/--group-by' {blur,face,face-cnn,hist} Add: '--logfile' -> '-lg/--logfile' PATH_TO_LOGFILE Greatly improve grouping performance. Grouping now has to sort using one of the sorting methods which makes the grouping stable and no longer dependent on how well the the target files are already sorted. Sorting and grouping methods can be combined in any way. If no -g/--group-by is specified by user, it will default to group by the non '-dissim' version of sort method. Different combinations of sorting and grouping methods work well for different sets of data. Fixes Fix progress updates not showing properly by setting them to print to stdout instead of stderror. Fix bug in grouping by face-cnn where wrong score method was being called. Misc Add documentation for reload_list() and splice_lists() methods because it's not obvious what they do. Add warning message to tools.py to tell users to make sure they understand how the tool they want to use works before using it. Add warning message to tools/sort.py to tell users to make sure they undrestand how the sort tool works before using it. Update help documentation to reflect new functionality and options. Set defaults for group by face-cnn to work properly with the correct score method. Amend commit in order to sign it. * Perform unittests for all options and combinations of sort and group methods: everything OK. Fix typos in help documentation.
2018-03-21 11:12:12 +01:00
# Importing the various tools
from lib.cli.args import FullHelpArgumentParser
Adding tools.py as main script for using tools, as well as integrating all feature requests from #255 and #278 (#298) * Add tools.py command and control script for use as the main interface for various tools. The structure and approach is the same as faceswap.py Add many new features to tools/sort.py: various new sorting methods, grouping by folders, logging file renaming/movemeng, keeping original files in the input directory and improved cli options documentation. Argument parsing has been re-written to inteface with tools.py Add __init__.py empty file in tools directory for python to register it as a module so that sort.py and future tools can be easily imported. * Fix various bugs where the correct sorting method would not get called. Add new sorting methon: face-cnn-dissim. Update help documentation for face-cnn-dissim. Change default grouping to rename. Update initial print in all sorting/grouping methods to say precisely which method is being used. * Major refactor and redesign. Use dynamic method allocation to avoid large amounts of nested if-elif statements in process() function and to allow easily combine sort and group methods. Change cli arguments to make them more intuitive and work with the new design. Previous: '-g/--grouping' -> '-f/--final-processing' {folders,rename} Previous: '-by/--by' -> '-s/--sort-by' {blur,face,face-cnn,face-cnn-dissim,face-dissim,hist,hist-dissim} New: '-g/--group-by' {blur,face,face-cnn,hist} Add: '--logfile' -> '-lg/--logfile' PATH_TO_LOGFILE Greatly improve grouping performance. Grouping now has to sort using one of the sorting methods which makes the grouping stable and no longer dependent on how well the the target files are already sorted. Sorting and grouping methods can be combined in any way. If no -g/--group-by is specified by user, it will default to group by the non '-dissim' version of sort method. Different combinations of sorting and grouping methods work well for different sets of data. Fixes Fix progress updates not showing properly by setting them to print to stdout instead of stderror. Fix bug in grouping by face-cnn where wrong score method was being called. Misc Add documentation for reload_list() and splice_lists() methods because it's not obvious what they do. Add warning message to tools.py to tell users to make sure they understand how the tool they want to use works before using it. Add warning message to tools/sort.py to tell users to make sure they undrestand how the sort tool works before using it. Update help documentation to reflect new functionality and options. Set defaults for group by face-cnn to work properly with the correct score method. Amend commit in order to sign it. * Perform unittests for all options and combinations of sort and group methods: everything OK. Fix typos in help documentation.
2018-03-21 11:12:12 +01:00
2021-02-18 23:53:01 +00:00
# LOCALES
_LANG = gettext.translation("tools", localedir="locales", fallback=True)
_ = _LANG.gettext
Adding tools.py as main script for using tools, as well as integrating all feature requests from #255 and #278 (#298) * Add tools.py command and control script for use as the main interface for various tools. The structure and approach is the same as faceswap.py Add many new features to tools/sort.py: various new sorting methods, grouping by folders, logging file renaming/movemeng, keeping original files in the input directory and improved cli options documentation. Argument parsing has been re-written to inteface with tools.py Add __init__.py empty file in tools directory for python to register it as a module so that sort.py and future tools can be easily imported. * Fix various bugs where the correct sorting method would not get called. Add new sorting methon: face-cnn-dissim. Update help documentation for face-cnn-dissim. Change default grouping to rename. Update initial print in all sorting/grouping methods to say precisely which method is being used. * Major refactor and redesign. Use dynamic method allocation to avoid large amounts of nested if-elif statements in process() function and to allow easily combine sort and group methods. Change cli arguments to make them more intuitive and work with the new design. Previous: '-g/--grouping' -> '-f/--final-processing' {folders,rename} Previous: '-by/--by' -> '-s/--sort-by' {blur,face,face-cnn,face-cnn-dissim,face-dissim,hist,hist-dissim} New: '-g/--group-by' {blur,face,face-cnn,hist} Add: '--logfile' -> '-lg/--logfile' PATH_TO_LOGFILE Greatly improve grouping performance. Grouping now has to sort using one of the sorting methods which makes the grouping stable and no longer dependent on how well the the target files are already sorted. Sorting and grouping methods can be combined in any way. If no -g/--group-by is specified by user, it will default to group by the non '-dissim' version of sort method. Different combinations of sorting and grouping methods work well for different sets of data. Fixes Fix progress updates not showing properly by setting them to print to stdout instead of stderror. Fix bug in grouping by face-cnn where wrong score method was being called. Misc Add documentation for reload_list() and splice_lists() methods because it's not obvious what they do. Add warning message to tools.py to tell users to make sure they understand how the tool they want to use works before using it. Add warning message to tools/sort.py to tell users to make sure they undrestand how the sort tool works before using it. Update help documentation to reflect new functionality and options. Set defaults for group by face-cnn to work properly with the correct score method. Amend commit in order to sign it. * Perform unittests for all options and combinations of sort and group methods: everything OK. Fix typos in help documentation.
2018-03-21 11:12:12 +01:00
# Python version check
Faceswap 3 (#1516) * FaceSwap 3 (#1515) * Update extract pipeline * Update requirements + setup for nvidia * Remove allow-growth option * tf.keras to keras updates * lib.model.losses - Port + fix all loss functions for Keras3 * lib.model - port initializers, layers. normalization to Keras3 * lib.model.autoclip to Keras 3 * Update mixed precision layer storage * model file to .keras format * Restructure nn_blocks to initialize layers in __init__ * Tensorboard - Trainer: Add Torch compatible Tensorboard callbacks - GUI event reader remove TF dependency * Loss logging - Flush TB logs on save - Replace TB live iterator for GUI * Backup models on total loss drop rather than per side * Update all models to Keras3 Compat * Remove lib.model.session * Update clip ViT to Keras 3 * plugins.extract.mask.unet-dfl - Fix for Keras3/Torch backend * Port AdaBelief to Keras 3 * setup.py: - Add --dev flag for dev tool install * Fix Keras 3 syntax * Fix LR Finder for Keras 3 * Fix mixed precision switching for Keras 3 * Add more optimizers + open up config setting * train: Remove updating FS1 weights to FS2 models * Alignments: Remove support for legacy .json files * tools.model: - Remove TF Saved Format saving - Fix Backup/Restore + Nan-Scan * Fix inference model creation for Keras 3 * Preview tool: Fix for Keras3 * setup.py: Configure keras backend * train: Migration of FS2 models to FS3 * Training: Default coverage to 100% * Remove DirectML backend * Update setup for MacOS * GUI: Force line reading to UTF-8 * Remove redundant Tensorflow references * Remove redundant code * Legacy model loading: Fix TFLamdaOp scalar ops and DepthwiseConv2D * Add vertical offset option for training * Github actions: Add more python versions * Add python version to workflow names * Github workflow: Exclude Python 3.12 for macOS * Implement custom training loop * Fs3 - Add RTX5xxx and ROCm 6.1-6.4 support (#1511) * setup.py: Add Cuda/ROCm version select options * bump minimum python version to 3.11 * Switch from setup.cgf to pyproject.toml * Documentation: Update all docs to use automodapi * Allow sysinfo to run with missing packages + correctly install tk under Linux * Bugfix: dot naming convention in clip models * lib.config: Centralise globally rather than passing as object - Add torch DataParallel for multi-gpu training - GUI: Group switches together when generating cli args - CLI: Remove deprecated multi-character argparse args - Refactor: - Centralise tensorboard reading/writing + unit tests - Create trainer plugin interfaces + add original + distributed * Update installers
2025-12-21 02:45:11 +00:00
if sys.version_info < (3, 11):
raise ValueError("This program requires at least python 3.11")
Adding tools.py as main script for using tools, as well as integrating all feature requests from #255 and #278 (#298) * Add tools.py command and control script for use as the main interface for various tools. The structure and approach is the same as faceswap.py Add many new features to tools/sort.py: various new sorting methods, grouping by folders, logging file renaming/movemeng, keeping original files in the input directory and improved cli options documentation. Argument parsing has been re-written to inteface with tools.py Add __init__.py empty file in tools directory for python to register it as a module so that sort.py and future tools can be easily imported. * Fix various bugs where the correct sorting method would not get called. Add new sorting methon: face-cnn-dissim. Update help documentation for face-cnn-dissim. Change default grouping to rename. Update initial print in all sorting/grouping methods to say precisely which method is being used. * Major refactor and redesign. Use dynamic method allocation to avoid large amounts of nested if-elif statements in process() function and to allow easily combine sort and group methods. Change cli arguments to make them more intuitive and work with the new design. Previous: '-g/--grouping' -> '-f/--final-processing' {folders,rename} Previous: '-by/--by' -> '-s/--sort-by' {blur,face,face-cnn,face-cnn-dissim,face-dissim,hist,hist-dissim} New: '-g/--group-by' {blur,face,face-cnn,hist} Add: '--logfile' -> '-lg/--logfile' PATH_TO_LOGFILE Greatly improve grouping performance. Grouping now has to sort using one of the sorting methods which makes the grouping stable and no longer dependent on how well the the target files are already sorted. Sorting and grouping methods can be combined in any way. If no -g/--group-by is specified by user, it will default to group by the non '-dissim' version of sort method. Different combinations of sorting and grouping methods work well for different sets of data. Fixes Fix progress updates not showing properly by setting them to print to stdout instead of stderror. Fix bug in grouping by face-cnn where wrong score method was being called. Misc Add documentation for reload_list() and splice_lists() methods because it's not obvious what they do. Add warning message to tools.py to tell users to make sure they understand how the tool they want to use works before using it. Add warning message to tools/sort.py to tell users to make sure they undrestand how the sort tool works before using it. Update help documentation to reflect new functionality and options. Set defaults for group by face-cnn to work properly with the correct score method. Amend commit in order to sign it. * Perform unittests for all options and combinations of sort and group methods: everything OK. Fix typos in help documentation.
2018-03-21 11:12:12 +01:00
2020-07-08 18:31:07 +01:00
def bad_args(*args): # pylint:disable=unused-argument
Gui v3.0b (#436) * GUI version 3 (#411) GUI version 3.0a * Required for Shaonlu mode (#416) Added two modes - Original and Shaonlu. The later requires this file to function. * model update (#417) New, functional Original 128 model * OriginalHighRes 128 model update (#418) Required for OriginalHighRes Model to function * Add OriginalHighRes 128 update to gui branch (#421) * Required for Shaonlu mode (#416) Added two modes - Original and Shaonlu. The later requires this file to function. * model update (#417) New, functional Original 128 model * OriginalHighRes 128 model update (#418) Required for OriginalHighRes Model to function * Dev gui (#420) * reduce singletons * Fix tooltips and screen boundaries on popup * Remove dpi fix. Fix context filebrowsers * fix tools.py execution and context filebrowser bugs * Bugfixes (#422) * Bump matplotlib requirement. Fix polyfit. Fix TQDM on sort * Fixed memory usage at 6GB cards. (#423) - Switched default encoder to ORIGINAL - Fixed memory consumption. Tested with geforce gtx 9800 ti with 6Gb; batch_size 8 no OOM or memory warnings now. * Staging (#426) * altered trainer (#425) altered trainer to accommodate with model change * Update Model.py (#424) - Added saving state (currently only saved epoch number, to be extended in future) - Changed saving to ThreadPoolExecutor * Add DPI Scaling (#428) * Add dpi scaling * Hotfix for effmpeg. (#429) effmpeg fixed so it works both in cli and gui. Initial work done to add previewing feature to effmpeg (currently does nothing). Some small spacing changes in other files to improve PEP8 conformity. * PEP8 Linting (#430) * pep8 linting * Requirements version bump (#432) * altered trainer (#425) altered trainer to accommodate with model change * Update Model.py (#424) - Added saving state (currently only saved epoch number, to be extended in future) - Changed saving to ThreadPoolExecutor * Requirements version bump (#431) This bumps the versions of: scandir h5py Keras opencv-python to their latest vesions. Virtual Environment will need to be setup again to make use of these. * High DPI Fixes (#433) * dpi scaling * DPI Fixes * Fix and improve context manager. (#434) effmpeg tool: Context manager for GUI fixed. Context manager in general: Functionality extended to allow configuring the context with both: command -> action command -> variable (cli argument) -> action * Change epoch option to iterations * Change epochs to iterations
2018-06-20 19:25:31 +02:00
""" Print help on bad arguments """
Adding new tool effmpeg ("easy"-ffmpeg) with gui support. Extend gui functionality to support filetypes. Re-opening PR. (#373) * Pre push commit. Add filetypes support to gui through new classes in lib/cli.py Add various new functions to tools/effmpeg.py * Finish developing basic effmpeg functionality. Ready for public alpha test. * Add ffmpy to requirements. Fix gen-vid to allow specifying a new file in GUI. Fix extract throwing an error when supplied with a valid directory. Add two new gui user pop interactions: save (allows you to create new files/directories) and nothing (disables the prompt button when it's not needed). Improve logic and argument processing in effmpeg. * Fix post merge bugs. Reformat tools.py to match the new style of faceswap.py Fix some whitespace issues. * Fix matplotlib.use() being called after pyplot was imported. * Fix various effmpeg bugs and add ability do terminate nested subprocess to GUI. effmpeg changes: Fix get-fps not printing to terminal. Fix mux-audio not working. Add verbosity option. If verbose is not specified than ffmpeg output is reduced with the -hide_banner flag. scripts/gui.py changes: Add ability to terminate nested subprocesses, i.e. the following type of process tree should now be terminated safely: gui -> command -> command-subprocess -> command-subprocess -> command-sub-subprocess * Add functionality to tools/effmpeg.py, fix some docstring and print statement issues in some files. tools/effmpeg.py: Transpose choices now display detailed name in GUI, while in cli they can still be entered as a number or the full command name. Add quiet option to effmpeg that only shows critical ffmpeg errors. Improve user input handling. lib/cli.py; scripts/convert.py; scripts/extract.py; scripts/train.py: Fix some line length issues and typos in docstrings, help text and print statements. Fix some whitespace issues. lib/cli.py: Add filetypes to '--alignments' argument. Change argument action to DirFullPaths where appropriate. * Bug fixes and improvements to tools/effmpeg.py Fix bug where duration would not be used even when end time was not set. Add option to specify output filetype for extraction. Enchance gen-vid to be able to generate a video from images that were zero padded to any arbitrary number, and not just 5. Enchance gen-vid to be able to use any of the image formats that a video can be extracted into. Improve gen-vid output video quality. Minor code quality improvements and ffmpeg argument formatting improvements. * Remove dependency on psutil in scripts/gui.py and various small improvements. lib/utils.py: Add _image_extensions and _video_extensions as global variables to make them easily portable across all of faceswap. Fix lack of new lines between function and class declarions to conform to PEP8. Fix some typos and line length issues in doctsrings and comments. scripts/convert.py: Make tqdm print to stdout. scripts/extract.py: Make tqdm print to stdout. Apply workaround for occasional TqdmSynchronisationWarning being thrown. Fix some typos and line length issues in doctsrings and comments. scripts/fsmedia.py: Did TODO in scripts/fsmedia.py in Faces.load_extractor(): TODO Pass extractor_name as argument Fix lack of new lines between function and class declarions to conform to PEP8. Fix some typos and line length issues in doctsrings and comments. Change 2 print statements to use format() for string formatting instead of the old '%'. scripts/gui.py: Refactor subprocess generation and termination to remove dependency on psutil. Fix some typos and line length issues in comments. tools/effmpeg.py Refactor DataItem class to use new lib/utils.py global media file extensions. Improve ffmpeg subprocess termination handling.
2018-05-09 19:47:17 +02:00
PARSER.print_help()
sys.exit(0)
def _get_cli_opts():
""" Optain the subparsers and cli options for available tools """
base_path = os.path.realpath(os.path.dirname(sys.argv[0]))
tools_dir = os.path.join(base_path, "tools")
for tool_name in sorted(os.listdir(tools_dir)):
cli_file = os.path.join(tools_dir, tool_name, "cli.py")
if os.path.exists(cli_file):
mod = ".".join(("tools", tool_name, "cli"))
module = import_module(mod)
cliarg_class = getattr(module, f"{tool_name.title()}Args")
help_text = getattr(module, "_HELPTEXT")
yield tool_name, help_text, cliarg_class
Adding tools.py as main script for using tools, as well as integrating all feature requests from #255 and #278 (#298) * Add tools.py command and control script for use as the main interface for various tools. The structure and approach is the same as faceswap.py Add many new features to tools/sort.py: various new sorting methods, grouping by folders, logging file renaming/movemeng, keeping original files in the input directory and improved cli options documentation. Argument parsing has been re-written to inteface with tools.py Add __init__.py empty file in tools directory for python to register it as a module so that sort.py and future tools can be easily imported. * Fix various bugs where the correct sorting method would not get called. Add new sorting methon: face-cnn-dissim. Update help documentation for face-cnn-dissim. Change default grouping to rename. Update initial print in all sorting/grouping methods to say precisely which method is being used. * Major refactor and redesign. Use dynamic method allocation to avoid large amounts of nested if-elif statements in process() function and to allow easily combine sort and group methods. Change cli arguments to make them more intuitive and work with the new design. Previous: '-g/--grouping' -> '-f/--final-processing' {folders,rename} Previous: '-by/--by' -> '-s/--sort-by' {blur,face,face-cnn,face-cnn-dissim,face-dissim,hist,hist-dissim} New: '-g/--group-by' {blur,face,face-cnn,hist} Add: '--logfile' -> '-lg/--logfile' PATH_TO_LOGFILE Greatly improve grouping performance. Grouping now has to sort using one of the sorting methods which makes the grouping stable and no longer dependent on how well the the target files are already sorted. Sorting and grouping methods can be combined in any way. If no -g/--group-by is specified by user, it will default to group by the non '-dissim' version of sort method. Different combinations of sorting and grouping methods work well for different sets of data. Fixes Fix progress updates not showing properly by setting them to print to stdout instead of stderror. Fix bug in grouping by face-cnn where wrong score method was being called. Misc Add documentation for reload_list() and splice_lists() methods because it's not obvious what they do. Add warning message to tools.py to tell users to make sure they understand how the tool they want to use works before using it. Add warning message to tools/sort.py to tell users to make sure they undrestand how the sort tool works before using it. Update help documentation to reflect new functionality and options. Set defaults for group by face-cnn to work properly with the correct score method. Amend commit in order to sign it. * Perform unittests for all options and combinations of sort and group methods: everything OK. Fix typos in help documentation.
2018-03-21 11:12:12 +01:00
if __name__ == "__main__":
Gui v3.0b (#436) * GUI version 3 (#411) GUI version 3.0a * Required for Shaonlu mode (#416) Added two modes - Original and Shaonlu. The later requires this file to function. * model update (#417) New, functional Original 128 model * OriginalHighRes 128 model update (#418) Required for OriginalHighRes Model to function * Add OriginalHighRes 128 update to gui branch (#421) * Required for Shaonlu mode (#416) Added two modes - Original and Shaonlu. The later requires this file to function. * model update (#417) New, functional Original 128 model * OriginalHighRes 128 model update (#418) Required for OriginalHighRes Model to function * Dev gui (#420) * reduce singletons * Fix tooltips and screen boundaries on popup * Remove dpi fix. Fix context filebrowsers * fix tools.py execution and context filebrowser bugs * Bugfixes (#422) * Bump matplotlib requirement. Fix polyfit. Fix TQDM on sort * Fixed memory usage at 6GB cards. (#423) - Switched default encoder to ORIGINAL - Fixed memory consumption. Tested with geforce gtx 9800 ti with 6Gb; batch_size 8 no OOM or memory warnings now. * Staging (#426) * altered trainer (#425) altered trainer to accommodate with model change * Update Model.py (#424) - Added saving state (currently only saved epoch number, to be extended in future) - Changed saving to ThreadPoolExecutor * Add DPI Scaling (#428) * Add dpi scaling * Hotfix for effmpeg. (#429) effmpeg fixed so it works both in cli and gui. Initial work done to add previewing feature to effmpeg (currently does nothing). Some small spacing changes in other files to improve PEP8 conformity. * PEP8 Linting (#430) * pep8 linting * Requirements version bump (#432) * altered trainer (#425) altered trainer to accommodate with model change * Update Model.py (#424) - Added saving state (currently only saved epoch number, to be extended in future) - Changed saving to ThreadPoolExecutor * Requirements version bump (#431) This bumps the versions of: scandir h5py Keras opencv-python to their latest vesions. Virtual Environment will need to be setup again to make use of these. * High DPI Fixes (#433) * dpi scaling * DPI Fixes * Fix and improve context manager. (#434) effmpeg tool: Context manager for GUI fixed. Context manager in general: Functionality extended to allow configuring the context with both: command -> action command -> variable (cli argument) -> action * Change epoch option to iterations * Change epochs to iterations
2018-06-20 19:25:31 +02:00
PARSER = FullHelpArgumentParser()
Adding new tool effmpeg ("easy"-ffmpeg) with gui support. Extend gui functionality to support filetypes. Re-opening PR. (#373) * Pre push commit. Add filetypes support to gui through new classes in lib/cli.py Add various new functions to tools/effmpeg.py * Finish developing basic effmpeg functionality. Ready for public alpha test. * Add ffmpy to requirements. Fix gen-vid to allow specifying a new file in GUI. Fix extract throwing an error when supplied with a valid directory. Add two new gui user pop interactions: save (allows you to create new files/directories) and nothing (disables the prompt button when it's not needed). Improve logic and argument processing in effmpeg. * Fix post merge bugs. Reformat tools.py to match the new style of faceswap.py Fix some whitespace issues. * Fix matplotlib.use() being called after pyplot was imported. * Fix various effmpeg bugs and add ability do terminate nested subprocess to GUI. effmpeg changes: Fix get-fps not printing to terminal. Fix mux-audio not working. Add verbosity option. If verbose is not specified than ffmpeg output is reduced with the -hide_banner flag. scripts/gui.py changes: Add ability to terminate nested subprocesses, i.e. the following type of process tree should now be terminated safely: gui -> command -> command-subprocess -> command-subprocess -> command-sub-subprocess * Add functionality to tools/effmpeg.py, fix some docstring and print statement issues in some files. tools/effmpeg.py: Transpose choices now display detailed name in GUI, while in cli they can still be entered as a number or the full command name. Add quiet option to effmpeg that only shows critical ffmpeg errors. Improve user input handling. lib/cli.py; scripts/convert.py; scripts/extract.py; scripts/train.py: Fix some line length issues and typos in docstrings, help text and print statements. Fix some whitespace issues. lib/cli.py: Add filetypes to '--alignments' argument. Change argument action to DirFullPaths where appropriate. * Bug fixes and improvements to tools/effmpeg.py Fix bug where duration would not be used even when end time was not set. Add option to specify output filetype for extraction. Enchance gen-vid to be able to generate a video from images that were zero padded to any arbitrary number, and not just 5. Enchance gen-vid to be able to use any of the image formats that a video can be extracted into. Improve gen-vid output video quality. Minor code quality improvements and ffmpeg argument formatting improvements. * Remove dependency on psutil in scripts/gui.py and various small improvements. lib/utils.py: Add _image_extensions and _video_extensions as global variables to make them easily portable across all of faceswap. Fix lack of new lines between function and class declarions to conform to PEP8. Fix some typos and line length issues in doctsrings and comments. scripts/convert.py: Make tqdm print to stdout. scripts/extract.py: Make tqdm print to stdout. Apply workaround for occasional TqdmSynchronisationWarning being thrown. Fix some typos and line length issues in doctsrings and comments. scripts/fsmedia.py: Did TODO in scripts/fsmedia.py in Faces.load_extractor(): TODO Pass extractor_name as argument Fix lack of new lines between function and class declarions to conform to PEP8. Fix some typos and line length issues in doctsrings and comments. Change 2 print statements to use format() for string formatting instead of the old '%'. scripts/gui.py: Refactor subprocess generation and termination to remove dependency on psutil. Fix some typos and line length issues in comments. tools/effmpeg.py Refactor DataItem class to use new lib/utils.py global media file extensions. Improve ffmpeg subprocess termination handling.
2018-05-09 19:47:17 +02:00
SUBPARSER = PARSER.add_subparsers()
for tool, helptext, cli_args in _get_cli_opts():
cli_args(SUBPARSER, tool, helptext)
Adding new tool effmpeg ("easy"-ffmpeg) with gui support. Extend gui functionality to support filetypes. Re-opening PR. (#373) * Pre push commit. Add filetypes support to gui through new classes in lib/cli.py Add various new functions to tools/effmpeg.py * Finish developing basic effmpeg functionality. Ready for public alpha test. * Add ffmpy to requirements. Fix gen-vid to allow specifying a new file in GUI. Fix extract throwing an error when supplied with a valid directory. Add two new gui user pop interactions: save (allows you to create new files/directories) and nothing (disables the prompt button when it's not needed). Improve logic and argument processing in effmpeg. * Fix post merge bugs. Reformat tools.py to match the new style of faceswap.py Fix some whitespace issues. * Fix matplotlib.use() being called after pyplot was imported. * Fix various effmpeg bugs and add ability do terminate nested subprocess to GUI. effmpeg changes: Fix get-fps not printing to terminal. Fix mux-audio not working. Add verbosity option. If verbose is not specified than ffmpeg output is reduced with the -hide_banner flag. scripts/gui.py changes: Add ability to terminate nested subprocesses, i.e. the following type of process tree should now be terminated safely: gui -> command -> command-subprocess -> command-subprocess -> command-sub-subprocess * Add functionality to tools/effmpeg.py, fix some docstring and print statement issues in some files. tools/effmpeg.py: Transpose choices now display detailed name in GUI, while in cli they can still be entered as a number or the full command name. Add quiet option to effmpeg that only shows critical ffmpeg errors. Improve user input handling. lib/cli.py; scripts/convert.py; scripts/extract.py; scripts/train.py: Fix some line length issues and typos in docstrings, help text and print statements. Fix some whitespace issues. lib/cli.py: Add filetypes to '--alignments' argument. Change argument action to DirFullPaths where appropriate. * Bug fixes and improvements to tools/effmpeg.py Fix bug where duration would not be used even when end time was not set. Add option to specify output filetype for extraction. Enchance gen-vid to be able to generate a video from images that were zero padded to any arbitrary number, and not just 5. Enchance gen-vid to be able to use any of the image formats that a video can be extracted into. Improve gen-vid output video quality. Minor code quality improvements and ffmpeg argument formatting improvements. * Remove dependency on psutil in scripts/gui.py and various small improvements. lib/utils.py: Add _image_extensions and _video_extensions as global variables to make them easily portable across all of faceswap. Fix lack of new lines between function and class declarions to conform to PEP8. Fix some typos and line length issues in doctsrings and comments. scripts/convert.py: Make tqdm print to stdout. scripts/extract.py: Make tqdm print to stdout. Apply workaround for occasional TqdmSynchronisationWarning being thrown. Fix some typos and line length issues in doctsrings and comments. scripts/fsmedia.py: Did TODO in scripts/fsmedia.py in Faces.load_extractor(): TODO Pass extractor_name as argument Fix lack of new lines between function and class declarions to conform to PEP8. Fix some typos and line length issues in doctsrings and comments. Change 2 print statements to use format() for string formatting instead of the old '%'. scripts/gui.py: Refactor subprocess generation and termination to remove dependency on psutil. Fix some typos and line length issues in comments. tools/effmpeg.py Refactor DataItem class to use new lib/utils.py global media file extensions. Improve ffmpeg subprocess termination handling.
2018-05-09 19:47:17 +02:00
PARSER.set_defaults(func=bad_args)
ARGUMENTS = PARSER.parse_args()
ARGUMENTS.func(ARGUMENTS)