* renaming and restructuring (#282) * Renaming and restructuring * Renaming and restructuring * Renaming and restructuring * Fix gender detection * Implement distance to face debugger * Implement distance to face debugger part2 * Implement distance to face debugger part3 * Mark as next * Fix reference when face_debugger comes first * Use official onnxruntime nightly * CUDA on steroids * CUDA on steroids * Add some testing * Set inswapper_128_fp16 as default * Feat/block until post check (#292) * Block until download is done * Introduce post_check() * Fix webcam * Update dependencies * Add --force-reinstall to installer * Introduce config ini (#298) * Introduce config ini * Fix output video encoder * Revert help listings back to commas, Move SSL hack to download.py * Introduce output-video-preset which defaults to veryfast * Mapping for nvenc encoders * Rework on events and non-blocking UI * Add fast bmp to temp_frame_formats * Add fast bmp to temp_frame_formats * Show total processing time on success * Show total processing time on success * Show total processing time on success * Move are_images, is_image and is_video back to filesystem * Fix some spacings * Pissing everyone of by renaming stuff * Fix seconds output * feat/video output fps (#312) * added output fps slider, removed 'keep fps' option (#311) * added output fps slider, removed 'keep fps' option * now uses passed fps instead of global fps for ffmpeg * fps values are now floats instead of ints * fix previous commit * removed default value from fps slider this is so we can implement a dynamic default value later * Fix seconds output * Some cleanup --------- Co-authored-by: Ran Shaashua <47498956+ranshaa05@users.noreply.github.com> * Allow 0.01 steps for fps * Make fps unregulated * Make fps unregulated * Remove distance from face debugger again (does not work) * Fix gender age * Fix gender age * Hotfix benchmark suite * Warp face normalize (#313) * use normalized kp templates * Update face_helper.py * My 50 cents to warp_face() --------- Co-authored-by: Harisreedhar <46858047+harisreedhar@users.noreply.github.com> * face-swapper-weight (#315) * Move prepare_crop_frame and normalize_crop_frame out of apply_swap * Fix UI bug with different range * feat/output video resolution (#316) * Introduce detect_video_resolution, Rename detect_fps to detect_video_fps * Add calc_video_resolution_range * Make output resolution work, does not auto-select yet * Make output resolution work, does not auto-select yet * Try to keep the origin resolution * Split code into more fragments * Add pack/unpack resolution * Move video_template_sizes to choices * Improve create_video_resolutions * Reword benchmark suite * Optimal speed for benchmark * Introduce different video memory strategies, rename max_memory to max… (#317) * Introduce different video memory strategies, rename max_memory to max_system_memory * Update readme * Fix limit_system_memory call * Apply video_memory_strategy to face debugger * Limit face swapper weight to 3.0 * Remove face swapper weight due bad render outputs * Show/dide logic for output video preset * fix uint8 conversion * Fix whitespace * Finalize layout and update preview * Fix multi renders on face debugger * Restore less restrictive rendering of preview and stream * Fix block mode for model downloads * Add testing * Cosmetic changes * Enforce valid fps and resolution via CLI * Empty config * Cosmetics on args processing * Memory workover (#319) * Cosmetics on args processing * Fix for MacOS * Rename all max_ to _limit * More fixes * Update preview * Fix whitespace --------- Co-authored-by: Ran Shaashua <47498956+ranshaa05@users.noreply.github.com> Co-authored-by: Harisreedhar <46858047+harisreedhar@users.noreply.github.com>
93 lines
4.0 KiB
Python
93 lines
4.0 KiB
Python
from typing import Dict, Tuple
|
|
import sys
|
|
import os
|
|
import platform
|
|
import tempfile
|
|
import subprocess
|
|
from argparse import ArgumentParser, HelpFormatter
|
|
|
|
subprocess.call([ 'pip', 'install' , 'inquirer', '-q' ])
|
|
|
|
import inquirer
|
|
|
|
from facefusion import metadata, wording
|
|
|
|
TORCH : Dict[str, str] =\
|
|
{
|
|
'default': 'default',
|
|
'cpu': 'cpu'
|
|
}
|
|
ONNXRUNTIMES : Dict[str, Tuple[str, str]] =\
|
|
{
|
|
'default': ('onnxruntime', '1.16.3')
|
|
}
|
|
if platform.system().lower() == 'linux' or platform.system().lower() == 'windows':
|
|
TORCH['cuda'] = 'cu118'
|
|
TORCH['cuda-nightly'] = 'cu121'
|
|
ONNXRUNTIMES['cuda'] = ('onnxruntime-gpu', '1.16.3')
|
|
ONNXRUNTIMES['cuda-nightly'] = ('onnxruntime-gpu', '1.17.0')
|
|
ONNXRUNTIMES['openvino'] = ('onnxruntime-openvino', '1.16.0')
|
|
if platform.system().lower() == 'linux':
|
|
TORCH['rocm'] = 'rocm5.6'
|
|
ONNXRUNTIMES['rocm'] = ('onnxruntime-rocm', '1.16.3')
|
|
if platform.system().lower() == 'darwin':
|
|
ONNXRUNTIMES['coreml-legacy'] = ('onnxruntime-coreml', '1.13.1')
|
|
ONNXRUNTIMES['coreml-silicon'] = ('onnxruntime-silicon', '1.16.0')
|
|
if platform.system().lower() == 'windows':
|
|
ONNXRUNTIMES['directml'] = ('onnxruntime-directml', '1.16.3')
|
|
|
|
|
|
def cli() -> None:
|
|
program = ArgumentParser(formatter_class = lambda prog: HelpFormatter(prog, max_help_position = 120))
|
|
program.add_argument('--torch', help = wording.get('install_dependency_help').format(dependency = 'torch'), choices = TORCH.keys())
|
|
program.add_argument('--onnxruntime', help = wording.get('install_dependency_help').format(dependency = 'onnxruntime'), choices = ONNXRUNTIMES.keys())
|
|
program.add_argument('--skip-venv', help = wording.get('skip_venv_help'), action = 'store_true')
|
|
program.add_argument('-v', '--version', version = metadata.get('name') + ' ' + metadata.get('version'), action = 'version')
|
|
run(program)
|
|
|
|
|
|
def run(program : ArgumentParser) -> None:
|
|
args = program.parse_args()
|
|
python_id = 'cp' + str(sys.version_info.major) + str(sys.version_info.minor)
|
|
|
|
if not args.skip_venv:
|
|
os.environ['PIP_REQUIRE_VIRTUALENV'] = '1'
|
|
if args.torch and args.onnxruntime:
|
|
answers =\
|
|
{
|
|
'torch': args.torch,
|
|
'onnxruntime': args.onnxruntime
|
|
}
|
|
else:
|
|
answers = inquirer.prompt(
|
|
[
|
|
inquirer.List('torch', message = wording.get('install_dependency_help').format(dependency = 'torch'), choices = list(TORCH.keys())),
|
|
inquirer.List('onnxruntime', message = wording.get('install_dependency_help').format(dependency = 'onnxruntime'), choices = list(ONNXRUNTIMES.keys()))
|
|
])
|
|
if answers:
|
|
torch = answers['torch']
|
|
torch_wheel = TORCH[torch]
|
|
onnxruntime = answers['onnxruntime']
|
|
onnxruntime_name, onnxruntime_version = ONNXRUNTIMES[onnxruntime]
|
|
|
|
subprocess.call([ 'pip', 'uninstall', 'torch', '-y', '-q' ])
|
|
if torch_wheel == 'default':
|
|
subprocess.call([ 'pip', 'install', '-r', 'requirements.txt', '--force-reinstall' ])
|
|
else:
|
|
subprocess.call([ 'pip', 'install', '-r', 'requirements.txt', '--extra-index-url', 'https://download.pytorch.org/whl/' + torch_wheel, '--force-reinstall' ])
|
|
if onnxruntime == 'rocm':
|
|
if python_id in [ 'cp39', 'cp310', 'cp311' ]:
|
|
wheel_name = 'onnxruntime_training-' + onnxruntime_version + '+rocm56-' + python_id + '-' + python_id + '-manylinux_2_17_x86_64.manylinux2014_x86_64.whl'
|
|
wheel_path = os.path.join(tempfile.gettempdir(), wheel_name)
|
|
wheel_url = 'https://download.onnxruntime.ai/' + wheel_name
|
|
subprocess.call([ 'curl', '--silent', '--location', '--continue-at', '-', '--output', wheel_path, wheel_url ])
|
|
subprocess.call([ 'pip', 'uninstall', wheel_path, '-y', '-q' ])
|
|
subprocess.call([ 'pip', 'install', wheel_path, '--force-reinstall' ])
|
|
os.remove(wheel_path)
|
|
else:
|
|
subprocess.call([ 'pip', 'uninstall', 'onnxruntime', onnxruntime_name, '-y', '-q' ])
|
|
if onnxruntime == 'cuda-nightly':
|
|
subprocess.call([ 'pip', 'install', onnxruntime_name + '==' + onnxruntime_version, '--extra-index-url', 'https://pkgs.dev.azure.com/onnxruntime/onnxruntime/_packaging/onnxruntime-cuda-12/pypi/simple', '--force-reinstall' ])
|
|
else:
|
|
subprocess.call([ 'pip', 'install', onnxruntime_name + '==' + onnxruntime_version, '--force-reinstall' ])
|