From 5feb6b0d7186592c8a1f20f16ca36f090fff6a71 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Tue, 30 May 2023 21:52:39 +0200 Subject: [PATCH] Resolve absolute model path --- core/processor.py | 3 ++- run.py | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/processor.py b/core/processor.py index f1c33e5..0754e04 100644 --- a/core/processor.py +++ b/core/processor.py @@ -11,7 +11,8 @@ FACE_SWAPPER = None def get_face_swapper(): global FACE_SWAPPER if FACE_SWAPPER is None: - FACE_SWAPPER = insightface.model_zoo.get_model('inswapper_128.onnx') + model_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../inswapper_128.onnx') + FACE_SWAPPER = insightface.model_zoo.get_model(model_path) return FACE_SWAPPER diff --git a/run.py b/run.py index 4878164..0b61ab4 100644 --- a/run.py +++ b/run.py @@ -34,11 +34,14 @@ parser.add_argument('--gpu', help='use gpu', dest='gpu', action='store_true', de parser.add_argument('--keep-fps', help='maintain original fps', dest='keep_fps', action='store_true', default=False) parser.add_argument('--keep-frames', help='keep frames directory', dest='keep_frames', action='store_true', default=False) parser.add_argument('--max-memory', help='set max memory', default=16, type=int) -parser.add_argument('--max-cores', help='set max cpu cores', dest='cores_count', type=int, default=psutil.cpu_count()-1) +parser.add_argument('--max-cores', help='set max cpu cores', dest='cores_count', type=int) for name, value in vars(parser.parse_args()).items(): args[name] = value +if not args['cores_count']: + args['cores_count'] = psutil.cpu_count()-1 + sep = "/" if os.name == "nt": sep = "\\" @@ -61,7 +64,8 @@ def pre_check(): quit(f'Python version is not supported - please upgrade to 3.8 or higher') if not shutil.which('ffmpeg'): quit('ffmpeg is not installed!') - if not os.path.isfile('inswapper_128.onnx'): + model_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'inswapper_128.onnx') + if not os.path.isfile(model_path): quit('File "inswapper_128.onnx" does not exist!') if '--gpu' in sys.argv: CUDA_VERSION = torch.version.cuda