Skip to content

Commit

Permalink
modified: roop/core.py , enhancer and swapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Moeblack authored and Moeblack committed Jun 13, 2023
1 parent 9734865 commit f37c7bc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
14 changes: 11 additions & 3 deletions roop/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from roop.processors.frame.core import get_frame_processor_module
from roop.utilities import has_image_extension, is_image, is_video, detect_fps, create_video, extract_frames, get_temp_frame_paths, restore_audio, create_temp, move_temp, clean_temp
from roop.face_analyser import get_one_face
from roop.processors.frame.core import get_frame_processor_module

if 'ROCMExecutionProvider' in roop.globals.execution_providers:
del torch
Expand Down Expand Up @@ -139,6 +140,14 @@ def pre_check() -> None:
quit('ffmpeg is not installed.')


def get_frame_processor_modules(frame_processors):
frame_processor_modules = []
for frame_processor in frame_processors:
frame_processor_module = get_frame_processor_module(frame_processor)
frame_processor_modules.append(frame_processor_module)
return frame_processor_modules


def conditional_process_video(source_path: str, temp_frame_paths: List[str], process_video) -> None:
pool_amount = len(temp_frame_paths) // roop.globals.cpu_cores
if pool_amount > 2 and roop.globals.cpu_cores > 1 and roop.globals.execution_providers == ['CPUExecutionProvider']:
Expand Down Expand Up @@ -233,9 +242,8 @@ def destroy() -> None:
def run() -> None:
parse_args()
pre_check()
for frame_processor in roop.globals.frame_processors:
module = get_frame_processor_module(frame_processor)
module.pre_check()
for frame_processor in get_frame_processor_modules(roop.globals.frame_processors):
frame_processor.pre_check()
limit_resources()
if roop.globals.headless:
start()
Expand Down
4 changes: 2 additions & 2 deletions roop/processors/frame/face_enhancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@


def pre_check() -> None:
download_directory_path = resolve_relative_path('../../../models')
download_directory_path = resolve_relative_path('../models')
conditional_download(download_directory_path, ['https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth'])


def get_code_former():
global CODE_FORMER
with THREAD_LOCK:
model_path = resolve_relative_path('../../../models/codeformer.pth')
model_path = resolve_relative_path('../models/codeformer.pth')
if CODE_FORMER is None:
model = torch.load(model_path)['params_ema']
CODE_FORMER = ARCH_REGISTRY.get('CodeFormer')(
Expand Down
4 changes: 2 additions & 2 deletions roop/processors/frame/face_swapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def pre_check() -> None:
download_directory_path = resolve_relative_path('../../../models')
download_directory_path = resolve_relative_path('../models')
conditional_download(download_directory_path, ['https://huggingface.co/deepinsight/inswapper/resolve/main/inswapper_128.onnx'])


Expand All @@ -22,7 +22,7 @@ def get_face_swapper() -> None:

with THREAD_LOCK:
if FACE_SWAPPER is None:
model_path = resolve_relative_path('../../../models/inswapper_128.onnx')
model_path = resolve_relative_path('../models/inswapper_128.onnx')
FACE_SWAPPER = insightface.model_zoo.get_model(model_path, providers=roop.globals.execution_providers)
return FACE_SWAPPER

Expand Down

0 comments on commit f37c7bc

Please sign in to comment.