2023-09-06 00:25:18 +02:00
|
|
|
from typing import Dict, Tuple
|
|
|
|
|
import subprocess
|
2023-10-09 10:16:13 +02:00
|
|
|
from argparse import ArgumentParser, HelpFormatter
|
2023-09-06 00:25:18 +02:00
|
|
|
|
|
|
|
|
subprocess.call([ 'pip', 'install' , 'inquirer', '-q' ])
|
|
|
|
|
|
|
|
|
|
import inquirer
|
|
|
|
|
|
2023-09-19 11:21:18 +02:00
|
|
|
from facefusion import metadata, wording
|
2023-09-06 00:25:18 +02:00
|
|
|
|
2023-10-09 10:16:13 +02:00
|
|
|
TORCH : Dict[str, str] =\
|
|
|
|
|
{
|
|
|
|
|
'cpu': 'https://download.pytorch.org/whl/cpu',
|
|
|
|
|
'cuda': 'https://download.pytorch.org/whl/cu118',
|
|
|
|
|
'rocm': 'https://download.pytorch.org/whl/rocm5.6'
|
|
|
|
|
}
|
2023-09-06 00:25:18 +02:00
|
|
|
ONNXRUNTIMES : Dict[str, Tuple[str, str]] =\
|
|
|
|
|
{
|
2023-09-22 10:28:38 +02:00
|
|
|
'cpu': ('onnxruntime', '1.16.0 '),
|
|
|
|
|
'cuda': ('onnxruntime-gpu', '1.16.0'),
|
2023-09-06 00:25:18 +02:00
|
|
|
'coreml-legacy': ('onnxruntime-coreml', '1.13.1'),
|
2023-10-09 10:16:13 +02:00
|
|
|
'coreml-silicon': ('onnxruntime-silicon', '1.16.0'),
|
2023-09-22 10:28:38 +02:00
|
|
|
'directml': ('onnxruntime-directml', '1.16.0'),
|
2023-09-06 00:25:18 +02:00
|
|
|
'openvino': ('onnxruntime-openvino', '1.15.0')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-09 10:16:13 +02:00
|
|
|
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'), dest = 'torch', choices = TORCH.keys())
|
|
|
|
|
program.add_argument('--onnxruntime', help = wording.get('install_dependency_help').format(dependency = 'onnxruntime'), dest = 'onnxruntime', choices = ONNXRUNTIMES.keys())
|
2023-09-19 11:21:18 +02:00
|
|
|
program.add_argument('-v', '--version', version = metadata.get('name') + ' ' + metadata.get('version'), action = 'version')
|
2023-10-09 10:16:13 +02:00
|
|
|
run(program)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(program : ArgumentParser) -> None:
|
2023-09-19 11:21:18 +02:00
|
|
|
args = program.parse_args()
|
|
|
|
|
|
|
|
|
|
if args.onnxruntime:
|
|
|
|
|
answers =\
|
|
|
|
|
{
|
2023-10-09 10:16:13 +02:00
|
|
|
'torch': args.torch,
|
2023-09-19 11:21:18 +02:00
|
|
|
'onnxruntime': args.onnxruntime
|
|
|
|
|
}
|
|
|
|
|
else:
|
|
|
|
|
answers = inquirer.prompt(
|
|
|
|
|
[
|
2023-10-09 10:16:13 +02:00
|
|
|
inquirer.List(
|
|
|
|
|
'torch',
|
|
|
|
|
message = wording.get('install_dependency_help').format(dependency = 'torch'),
|
|
|
|
|
choices = list(TORCH.keys())
|
|
|
|
|
),
|
2023-09-19 11:21:18 +02:00
|
|
|
inquirer.List(
|
|
|
|
|
'onnxruntime',
|
2023-10-09 10:16:13 +02:00
|
|
|
message = wording.get('install_dependency_help').format(dependency = 'onnxruntime'),
|
2023-09-19 11:21:18 +02:00
|
|
|
choices = list(ONNXRUNTIMES.keys())
|
|
|
|
|
)
|
|
|
|
|
])
|
2023-09-06 00:25:18 +02:00
|
|
|
if answers is not None:
|
2023-10-09 10:16:13 +02:00
|
|
|
torch = answers['torch']
|
|
|
|
|
torch_url = TORCH[torch]
|
2023-09-19 11:21:18 +02:00
|
|
|
onnxruntime = answers['onnxruntime']
|
|
|
|
|
onnxruntime_name, onnxruntime_version = ONNXRUNTIMES[onnxruntime]
|
2023-09-07 01:26:33 +02:00
|
|
|
subprocess.call([ 'pip', 'uninstall', 'torch', '-y' ])
|
2023-10-09 10:16:13 +02:00
|
|
|
subprocess.call([ 'pip', 'install', '-r', 'requirements.txt', '--extra-index-url', torch_url ])
|
2023-09-19 11:21:18 +02:00
|
|
|
if onnxruntime != 'cpu':
|
2023-09-06 00:25:18 +02:00
|
|
|
subprocess.call([ 'pip', 'uninstall', 'onnxruntime', onnxruntime_name, '-y' ])
|
2023-10-09 10:16:13 +02:00
|
|
|
subprocess.call([ 'pip', 'install', onnxruntime_name + '==' + onnxruntime_version ])
|