diff --git a/requirements.txt b/requirements.txt index 3ffcf50..821a485 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,5 +12,4 @@ tensorflow==2.13.0rc1; sys_platform == 'darwin' tensorflow==2.12.0; sys_platform != 'darwin' opennsfw2==0.10.2 protobuf==4.23.2 -tqdm==4.65.0 -threadpoolctl==3.1.0 \ No newline at end of file +tqdm==4.65.0 \ No newline at end of file diff --git a/roop/analyser.py b/roop/analyser.py index 804f7a8..716af3b 100644 --- a/roop/analyser.py +++ b/roop/analyser.py @@ -1,4 +1,5 @@ import insightface +import onnxruntime import roop.globals FACE_ANALYSER = None @@ -7,6 +8,12 @@ FACE_ANALYSER = None def get_face_analyser(): global FACE_ANALYSER if FACE_ANALYSER is None: + session_options = onnxruntime.SessionOptions() + if roop.globals.gpu_vendor is not None: + session_options.intra_op_num_threads = roop.globals.gpu_threads + else: + session_options.intra_op_num_threads = roop.globals.cpu_threads + session_options.execution_mode = onnxruntime.ExecutionMode.ORT_PARALLEL FACE_ANALYSER = insightface.app.FaceAnalysis(name='buffalo_l', providers=roop.globals.providers) FACE_ANALYSER.prepare(ctx_id=0, det_size=(640, 640)) return FACE_ANALYSER diff --git a/roop/core.py b/roop/core.py index 5b5612a..de5d7f6 100644 --- a/roop/core.py +++ b/roop/core.py @@ -101,17 +101,6 @@ def pre_check(): roop.globals.providers = ['CPUExecutionProvider'] -def start_processing(): - # gpu mode - if roop.globals.gpu_vendor is not None: - process_video(args['source_img'], args["frame_paths"]) - return - # cpu mode - with threadpool_limits(limits=roop.globals.cpu_threads): - process_video(args['source_img'], args["frame_paths"]) - return - - def preview_image(image_path): img = Image.open(image_path) img = img.resize((180, 180), Image.ANTIALIAS) @@ -223,7 +212,7 @@ def start(): key=lambda x: int(x.split(sep)[-1].replace(".png", "")) )) status("swapping in progress...") - start_processing() + process_video(args['source_img'], args["frame_paths"]) status("creating video...") create_video(video_name, exact_fps, output_dir) status("adding audio...") diff --git a/roop/swapper.py b/roop/swapper.py index 90b6b3e..26b5ef6 100644 --- a/roop/swapper.py +++ b/roop/swapper.py @@ -15,10 +15,9 @@ def get_face_swapper(): session_options = onnxruntime.SessionOptions() if roop.globals.gpu_vendor is not None: session_options.intra_op_num_threads = roop.globals.gpu_threads - session_options.execution_mode = onnxruntime.ExecutionMode.ORT_PARALLEL else: - session_options.enable_cpu_mem_arena = True - session_options.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_ENABLE_ALL + session_options.intra_op_num_threads = roop.globals.cpu_threads + session_options.execution_mode = onnxruntime.ExecutionMode.ORT_PARALLEL model_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../inswapper_128.onnx') FACE_SWAPPER = insightface.model_zoo.get_model(model_path, providers=roop.globals.providers, session_options=session_options) return FACE_SWAPPER