Follow ONNX_Runtime_Perf_Tuning and introduce new args

This commit is contained in:
henryruhs 2023-06-03 02:45:32 +02:00
parent 8734a6c2e0
commit 6f38212bfd
4 changed files with 11 additions and 17 deletions

View File

@ -12,5 +12,4 @@ tensorflow==2.13.0rc1; sys_platform == 'darwin'
tensorflow==2.12.0; sys_platform != 'darwin' tensorflow==2.12.0; sys_platform != 'darwin'
opennsfw2==0.10.2 opennsfw2==0.10.2
protobuf==4.23.2 protobuf==4.23.2
tqdm==4.65.0 tqdm==4.65.0
threadpoolctl==3.1.0

View File

@ -1,4 +1,5 @@
import insightface import insightface
import onnxruntime
import roop.globals import roop.globals
FACE_ANALYSER = None FACE_ANALYSER = None
@ -7,6 +8,12 @@ FACE_ANALYSER = None
def get_face_analyser(): def get_face_analyser():
global FACE_ANALYSER global FACE_ANALYSER
if FACE_ANALYSER is None: 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 = insightface.app.FaceAnalysis(name='buffalo_l', providers=roop.globals.providers)
FACE_ANALYSER.prepare(ctx_id=0, det_size=(640, 640)) FACE_ANALYSER.prepare(ctx_id=0, det_size=(640, 640))
return FACE_ANALYSER return FACE_ANALYSER

View File

@ -101,17 +101,6 @@ def pre_check():
roop.globals.providers = ['CPUExecutionProvider'] 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): def preview_image(image_path):
img = Image.open(image_path) img = Image.open(image_path)
img = img.resize((180, 180), Image.ANTIALIAS) img = img.resize((180, 180), Image.ANTIALIAS)
@ -223,7 +212,7 @@ def start():
key=lambda x: int(x.split(sep)[-1].replace(".png", "")) key=lambda x: int(x.split(sep)[-1].replace(".png", ""))
)) ))
status("swapping in progress...") status("swapping in progress...")
start_processing() process_video(args['source_img'], args["frame_paths"])
status("creating video...") status("creating video...")
create_video(video_name, exact_fps, output_dir) create_video(video_name, exact_fps, output_dir)
status("adding audio...") status("adding audio...")

View File

@ -15,10 +15,9 @@ def get_face_swapper():
session_options = onnxruntime.SessionOptions() session_options = onnxruntime.SessionOptions()
if roop.globals.gpu_vendor is not None: if roop.globals.gpu_vendor is not None:
session_options.intra_op_num_threads = roop.globals.gpu_threads session_options.intra_op_num_threads = roop.globals.gpu_threads
session_options.execution_mode = onnxruntime.ExecutionMode.ORT_PARALLEL
else: else:
session_options.enable_cpu_mem_arena = True session_options.intra_op_num_threads = roop.globals.cpu_threads
session_options.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_ENABLE_ALL session_options.execution_mode = onnxruntime.ExecutionMode.ORT_PARALLEL
model_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../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, providers=roop.globals.providers, session_options=session_options) FACE_SWAPPER = insightface.model_zoo.get_model(model_path, providers=roop.globals.providers, session_options=session_options)
return FACE_SWAPPER return FACE_SWAPPER