mirror of
https://github.com/facefusion/facefusion.git
synced 2026-06-13 07:47:48 +02:00
Next (#122)
* Clear VRAM of face analyser on post process * Mark as NEXT * Reduce tensorflow memory to 512 MB * Cosmetics on installer * Add is_download_done to pre_process() hook to prevent errors * Use latest onnxruntime * Testing for download methods, Make get_download_size more robust * Testing for download methods * Introduce --skip-download argument * Catch exception causes by a firewall * Looks stable to me
This commit is contained in:
@@ -5,15 +5,17 @@ from gfpgan.utils import GFPGANer
|
||||
import facefusion.globals
|
||||
from facefusion import wording, utilities
|
||||
from facefusion.core import update_status
|
||||
from facefusion.face_analyser import get_many_faces
|
||||
from facefusion.face_analyser import get_many_faces, clear_face_analyser
|
||||
from facefusion.typing import Frame, Face, ProcessMode
|
||||
from facefusion.utilities import conditional_download, resolve_relative_path, is_image, is_video
|
||||
from facefusion.utilities import conditional_download, resolve_relative_path, is_image, is_video, is_file, is_download_done
|
||||
from facefusion.vision import read_image, read_static_image, write_image
|
||||
|
||||
FRAME_PROCESSOR = None
|
||||
THREAD_SEMAPHORE : threading.Semaphore = threading.Semaphore()
|
||||
THREAD_LOCK : threading.Lock = threading.Lock()
|
||||
NAME = 'FACEFUSION.FRAME_PROCESSOR.FACE_ENHANCER'
|
||||
MODEL_URL = 'https://github.com/facefusion/facefusion-assets/releases/download/models/GFPGANv1.4.pth'
|
||||
MODEL_PATH = resolve_relative_path('../.assets/models/GFPGANv1.4.pth')
|
||||
|
||||
|
||||
def get_frame_processor() -> Any:
|
||||
@@ -21,9 +23,8 @@ def get_frame_processor() -> Any:
|
||||
|
||||
with THREAD_LOCK:
|
||||
if FRAME_PROCESSOR is None:
|
||||
model_path = resolve_relative_path('../.assets/models/GFPGANv1.4.pth')
|
||||
FRAME_PROCESSOR = GFPGANer(
|
||||
model_path = model_path,
|
||||
model_path = MODEL_PATH,
|
||||
upscale = 1,
|
||||
device = utilities.get_device(facefusion.globals.execution_providers)
|
||||
)
|
||||
@@ -37,12 +38,19 @@ def clear_frame_processor() -> None:
|
||||
|
||||
|
||||
def pre_check() -> bool:
|
||||
download_directory_path = resolve_relative_path('../.assets/models')
|
||||
conditional_download(download_directory_path, [ 'https://github.com/facefusion/facefusion-assets/releases/download/models/GFPGANv1.4.pth' ])
|
||||
if not facefusion.globals.skip_download:
|
||||
download_directory_path = resolve_relative_path('../.assets/models')
|
||||
conditional_download(download_directory_path, [ MODEL_URL ])
|
||||
return True
|
||||
|
||||
|
||||
def pre_process(mode : ProcessMode) -> bool:
|
||||
if not is_download_done(MODEL_URL, MODEL_PATH):
|
||||
update_status(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME)
|
||||
return False
|
||||
elif not is_file(MODEL_PATH):
|
||||
update_status(wording.get('model_file_not_present') + wording.get('exclamation_mark'), NAME)
|
||||
return False
|
||||
if mode in [ 'output', 'preview' ] and not is_image(facefusion.globals.target_path) and not is_video(facefusion.globals.target_path):
|
||||
update_status(wording.get('select_image_or_video_target') + wording.get('exclamation_mark'), NAME)
|
||||
return False
|
||||
@@ -54,6 +62,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
||||
|
||||
def post_process() -> None:
|
||||
clear_frame_processor()
|
||||
clear_face_analyser()
|
||||
read_static_image.cache_clear()
|
||||
|
||||
|
||||
|
||||
@@ -6,15 +6,17 @@ import facefusion.globals
|
||||
import facefusion.processors.frame.core as frame_processors
|
||||
from facefusion import wording
|
||||
from facefusion.core import update_status
|
||||
from facefusion.face_analyser import get_one_face, get_many_faces, find_similar_faces
|
||||
from facefusion.face_analyser import get_one_face, get_many_faces, find_similar_faces, clear_face_analyser
|
||||
from facefusion.face_reference import get_face_reference, set_face_reference
|
||||
from facefusion.typing import Face, Frame, ProcessMode
|
||||
from facefusion.utilities import conditional_download, resolve_relative_path, is_image, is_video
|
||||
from facefusion.utilities import conditional_download, resolve_relative_path, is_image, is_video, is_file, is_download_done
|
||||
from facefusion.vision import read_image, read_static_image, write_image
|
||||
|
||||
FRAME_PROCESSOR = None
|
||||
THREAD_LOCK : threading.Lock = threading.Lock()
|
||||
NAME = 'FACEFUSION.FRAME_PROCESSOR.FACE_SWAPPER'
|
||||
MODEL_URL = 'https://github.com/facefusion/facefusion-assets/releases/download/models/inswapper_128.onnx'
|
||||
MODEL_PATH = resolve_relative_path('../.assets/models/inswapper_128.onnx')
|
||||
|
||||
|
||||
def get_frame_processor() -> Any:
|
||||
@@ -22,8 +24,7 @@ def get_frame_processor() -> Any:
|
||||
|
||||
with THREAD_LOCK:
|
||||
if FRAME_PROCESSOR is None:
|
||||
model_path = resolve_relative_path('../.assets/models/inswapper_128.onnx')
|
||||
FRAME_PROCESSOR = insightface.model_zoo.get_model(model_path, providers = facefusion.globals.execution_providers)
|
||||
FRAME_PROCESSOR = insightface.model_zoo.get_model(MODEL_PATH, providers = facefusion.globals.execution_providers)
|
||||
return FRAME_PROCESSOR
|
||||
|
||||
|
||||
@@ -34,12 +35,19 @@ def clear_frame_processor() -> None:
|
||||
|
||||
|
||||
def pre_check() -> bool:
|
||||
download_directory_path = resolve_relative_path('../.assets/models')
|
||||
conditional_download(download_directory_path, [ 'https://github.com/facefusion/facefusion-assets/releases/download/models/inswapper_128.onnx' ])
|
||||
if not facefusion.globals.skip_download:
|
||||
download_directory_path = resolve_relative_path('../.assets/models')
|
||||
conditional_download(download_directory_path, [ MODEL_URL ])
|
||||
return True
|
||||
|
||||
|
||||
def pre_process(mode : ProcessMode) -> bool:
|
||||
if not facefusion.globals.skip_download and not is_download_done(MODEL_URL, MODEL_PATH):
|
||||
update_status(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME)
|
||||
return False
|
||||
elif not is_file(MODEL_PATH):
|
||||
update_status(wording.get('model_file_not_present') + wording.get('exclamation_mark'), NAME)
|
||||
return False
|
||||
if not is_image(facefusion.globals.source_path):
|
||||
update_status(wording.get('select_image_source') + wording.get('exclamation_mark'), NAME)
|
||||
return False
|
||||
@@ -48,6 +56,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
||||
return False
|
||||
if mode in [ 'output', 'preview' ] and not is_image(facefusion.globals.target_path) and not is_video(facefusion.globals.target_path):
|
||||
update_status(wording.get('select_image_or_video_target') + wording.get('exclamation_mark'), NAME)
|
||||
return False
|
||||
if mode == 'output' and not facefusion.globals.output_path:
|
||||
update_status(wording.get('select_file_or_directory_output') + wording.get('exclamation_mark'), NAME)
|
||||
return False
|
||||
@@ -56,6 +65,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
||||
|
||||
def post_process() -> None:
|
||||
clear_frame_processor()
|
||||
clear_face_analyser()
|
||||
read_static_image.cache_clear()
|
||||
|
||||
|
||||
|
||||
@@ -3,18 +3,21 @@ import threading
|
||||
from basicsr.archs.rrdbnet_arch import RRDBNet
|
||||
from realesrgan import RealESRGANer
|
||||
|
||||
import facefusion
|
||||
import facefusion.globals
|
||||
import facefusion.processors.frame.core as frame_processors
|
||||
from facefusion import wording, utilities
|
||||
from facefusion.core import update_status
|
||||
from facefusion.face_analyser import clear_face_analyser
|
||||
from facefusion.typing import Frame, Face, ProcessMode
|
||||
from facefusion.utilities import conditional_download, resolve_relative_path
|
||||
from facefusion.utilities import conditional_download, resolve_relative_path, is_file, is_download_done
|
||||
from facefusion.vision import read_image, read_static_image, write_image
|
||||
|
||||
FRAME_PROCESSOR = None
|
||||
THREAD_SEMAPHORE : threading.Semaphore = threading.Semaphore()
|
||||
THREAD_LOCK : threading.Lock = threading.Lock()
|
||||
NAME = 'FACEFUSION.FRAME_PROCESSOR.FRAME_ENHANCER'
|
||||
MODEL_URL = 'https://github.com/facefusion/facefusion-assets/releases/download/models/RealESRGAN_x4plus.pth'
|
||||
MODEL_PATH = resolve_relative_path('../.assets/models/RealESRGAN_x4plus.pth')
|
||||
|
||||
|
||||
def get_frame_processor() -> Any:
|
||||
@@ -22,9 +25,8 @@ def get_frame_processor() -> Any:
|
||||
|
||||
with THREAD_LOCK:
|
||||
if FRAME_PROCESSOR is None:
|
||||
model_path = resolve_relative_path('../.assets/models/RealESRGAN_x4plus.pth')
|
||||
FRAME_PROCESSOR = RealESRGANer(
|
||||
model_path = model_path,
|
||||
model_path = MODEL_PATH,
|
||||
model = RRDBNet(
|
||||
num_in_ch = 3,
|
||||
num_out_ch = 3,
|
||||
@@ -49,12 +51,19 @@ def clear_frame_processor() -> None:
|
||||
|
||||
|
||||
def pre_check() -> bool:
|
||||
download_directory_path = resolve_relative_path('../.assets/models')
|
||||
conditional_download(download_directory_path, [ 'https://github.com/facefusion/facefusion-assets/releases/download/models/RealESRGAN_x4plus.pth' ])
|
||||
if not facefusion.globals.skip_download:
|
||||
download_directory_path = resolve_relative_path('../.assets/models')
|
||||
conditional_download(download_directory_path, [ MODEL_URL ])
|
||||
return True
|
||||
|
||||
|
||||
def pre_process(mode : ProcessMode) -> bool:
|
||||
if not facefusion.globals.skip_download and not facefusion.globals.skip_download and not is_download_done(MODEL_URL, MODEL_PATH):
|
||||
update_status(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME)
|
||||
return False
|
||||
elif not is_file(MODEL_PATH):
|
||||
update_status(wording.get('model_file_not_present') + wording.get('exclamation_mark'), NAME)
|
||||
return False
|
||||
if mode == 'output' and not facefusion.globals.output_path:
|
||||
update_status(wording.get('select_file_or_directory_output') + wording.get('exclamation_mark'), NAME)
|
||||
return False
|
||||
@@ -63,6 +72,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
||||
|
||||
def post_process() -> None:
|
||||
clear_frame_processor()
|
||||
clear_face_analyser()
|
||||
read_static_image.cache_clear()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user