diff --git a/facefusion/content_analyser.py b/facefusion/content_analyser.py index d333faa2..bf7a3c28 100644 --- a/facefusion/content_analyser.py +++ b/facefusion/content_analyser.py @@ -12,7 +12,7 @@ from facefusion import process_manager, wording from facefusion.typing import VisionFrame, ModelSet, Fps from facefusion.execution import apply_execution_provider_options from facefusion.vision import get_video_frame, count_video_frame_total, read_image, detect_video_fps -from facefusion.filesystem import resolve_relative_path +from facefusion.filesystem import resolve_relative_path, is_file from facefusion.download import conditional_download CONTENT_ANALYSER = None @@ -49,13 +49,15 @@ def clear_content_analyser() -> None: def pre_check() -> bool: + download_directory_path = resolve_relative_path('../.assets/models') + model_url = MODELS.get('open_nsfw').get('url') + model_path = MODELS.get('open_nsfw').get('path') + if not facefusion.globals.skip_download: - download_directory_path = resolve_relative_path('../.assets/models') - model_url = MODELS.get('open_nsfw').get('url') process_manager.check() conditional_download(download_directory_path, [ model_url ]) process_manager.end() - return True + return is_file(model_path) def analyse_stream(vision_frame : VisionFrame, video_fps : Fps) -> bool: diff --git a/facefusion/core.py b/facefusion/core.py index 1c0897f9..c006b3bc 100755 --- a/facefusion/core.py +++ b/facefusion/core.py @@ -276,8 +276,8 @@ def force_download() -> None: for frame_processor_module in get_frame_processors_modules(available_frame_processors): if hasattr(frame_processor_module, 'MODELS'): model_list.append(frame_processor_module.MODELS) - urls = [ models[model].get('url') for models in model_list for model in models ] - conditional_download(download_directory_path, urls) + model_urls = [ models[model].get('url') for models in model_list for model in models ] + conditional_download(download_directory_path, model_urls) def process_image(start_time : float) -> None: diff --git a/facefusion/face_analyser.py b/facefusion/face_analyser.py index 0fd7ef4d..0098ce8e 100644 --- a/facefusion/face_analyser.py +++ b/facefusion/face_analyser.py @@ -12,7 +12,7 @@ from facefusion.face_helper import estimate_matrix_by_face_landmark_5, warp_face from facefusion.face_store import get_static_faces, set_static_faces from facefusion.execution import apply_execution_provider_options from facefusion.download import conditional_download -from facefusion.filesystem import resolve_relative_path +from facefusion.filesystem import resolve_relative_path, is_file from facefusion.typing import VisionFrame, Face, FaceSet, FaceAnalyserOrder, FaceAnalyserAge, FaceAnalyserGender, ModelSet, BoundingBox, FaceLandmarkSet, FaceLandmark5, FaceLandmark68, Score, FaceScoreSet, Embedding from facefusion.vision import resize_frame_resolution, unpack_resolution @@ -125,35 +125,50 @@ def clear_face_analyser() -> Any: def pre_check() -> bool: - if not facefusion.globals.skip_download: - download_directory_path = resolve_relative_path('../.assets/models') - model_urls =\ - [ - MODELS.get('face_landmarker_68').get('url'), - MODELS.get('face_landmarker_68_5').get('url'), - MODELS.get('gender_age').get('url') - ] + download_directory_path = resolve_relative_path('../.assets/models') + model_urls =\ + [ + MODELS.get('face_landmarker_68').get('url'), + MODELS.get('face_landmarker_68_5').get('url'), + MODELS.get('gender_age').get('url') + ] + model_paths =\ + [ + MODELS.get('face_landmarker_68').get('path'), + MODELS.get('face_landmarker_68_5').get('path'), + MODELS.get('gender_age').get('path') + ] - if facefusion.globals.face_detector_model in [ 'many', 'retinaface' ]: - model_urls.append(MODELS.get('face_detector_retinaface').get('url')) - if facefusion.globals.face_detector_model in [ 'many', 'scrfd' ]: - model_urls.append(MODELS.get('face_detector_scrfd').get('url')) - if facefusion.globals.face_detector_model in [ 'many', 'yoloface' ]: - model_urls.append(MODELS.get('face_detector_yoloface').get('url')) - if facefusion.globals.face_detector_model in [ 'yunet' ]: - model_urls.append(MODELS.get('face_detector_yunet').get('url')) - if facefusion.globals.face_recognizer_model == 'arcface_blendswap': - model_urls.append(MODELS.get('face_recognizer_arcface_blendswap').get('url')) - if facefusion.globals.face_recognizer_model == 'arcface_inswapper': - model_urls.append(MODELS.get('face_recognizer_arcface_inswapper').get('url')) - if facefusion.globals.face_recognizer_model == 'arcface_simswap': - model_urls.append(MODELS.get('face_recognizer_arcface_simswap').get('url')) - if facefusion.globals.face_recognizer_model == 'arcface_uniface': - model_urls.append(MODELS.get('face_recognizer_arcface_uniface').get('url')) + if facefusion.globals.face_detector_model in [ 'many', 'retinaface' ]: + model_urls.append(MODELS.get('face_detector_retinaface').get('url')) + model_paths.append(MODELS.get('face_detector_retinaface').get('path')) + if facefusion.globals.face_detector_model in [ 'many', 'scrfd' ]: + model_urls.append(MODELS.get('face_detector_scrfd').get('url')) + model_paths.append(MODELS.get('face_detector_scrfd').get('path')) + if facefusion.globals.face_detector_model in [ 'many', 'yoloface' ]: + model_urls.append(MODELS.get('face_detector_yoloface').get('url')) + model_paths.append(MODELS.get('face_detector_yoloface').get('path')) + if facefusion.globals.face_detector_model in [ 'yunet' ]: + model_urls.append(MODELS.get('face_detector_yunet').get('url')) + model_paths.append(MODELS.get('face_detector_yunet').get('path')) + if facefusion.globals.face_recognizer_model == 'arcface_blendswap': + model_urls.append(MODELS.get('face_recognizer_arcface_blendswap').get('url')) + model_paths.append(MODELS.get('face_recognizer_arcface_blendswap').get('path')) + if facefusion.globals.face_recognizer_model == 'arcface_inswapper': + model_urls.append(MODELS.get('face_recognizer_arcface_inswapper').get('url')) + model_paths.append(MODELS.get('face_recognizer_arcface_inswapper').get('path')) + if facefusion.globals.face_recognizer_model == 'arcface_simswap': + model_urls.append(MODELS.get('face_recognizer_arcface_simswap').get('url')) + model_paths.append(MODELS.get('face_recognizer_arcface_simswap').get('path')) + if facefusion.globals.face_recognizer_model == 'arcface_uniface': + model_urls.append(MODELS.get('face_recognizer_arcface_uniface').get('url')) + model_paths.append(MODELS.get('face_recognizer_arcface_uniface').get('path')) + + if not facefusion.globals.skip_download: process_manager.check() conditional_download(download_directory_path, model_urls) process_manager.end() - return True + return all(is_file(model_path) for model_path in model_paths) def detect_with_retinaface(vision_frame : VisionFrame, face_detector_size : str) -> Tuple[List[BoundingBox], List[FaceLandmark5], List[Score]]: diff --git a/facefusion/face_masker.py b/facefusion/face_masker.py index 25a71160..3c68a4c0 100755 --- a/facefusion/face_masker.py +++ b/facefusion/face_masker.py @@ -11,7 +11,7 @@ import facefusion.globals from facefusion import process_manager from facefusion.typing import FaceLandmark68, VisionFrame, Mask, Padding, FaceMaskRegion, ModelSet from facefusion.execution import apply_execution_provider_options -from facefusion.filesystem import resolve_relative_path +from facefusion.filesystem import resolve_relative_path, is_file from facefusion.download import conditional_download FACE_OCCLUDER = None @@ -82,17 +82,23 @@ def clear_face_parser() -> None: def pre_check() -> bool: + download_directory_path = resolve_relative_path('../.assets/models') + model_urls =\ + [ + MODELS.get('face_occluder').get('url'), + MODELS.get('face_parser').get('url') + ] + model_paths =\ + [ + MODELS.get('face_occluder').get('path'), + MODELS.get('face_parser').get('path') + ] + if not facefusion.globals.skip_download: - download_directory_path = resolve_relative_path('../.assets/models') - model_urls =\ - [ - MODELS.get('face_occluder').get('url'), - MODELS.get('face_parser').get('url'), - ] process_manager.check() conditional_download(download_directory_path, model_urls) process_manager.end() - return True + return all(is_file(model_path) for model_path in model_paths) @lru_cache(maxsize = None) diff --git a/facefusion/processors/frame/modules/face_enhancer.py b/facefusion/processors/frame/modules/face_enhancer.py index d82b0970..af89c335 100755 --- a/facefusion/processors/frame/modules/face_enhancer.py +++ b/facefusion/processors/frame/modules/face_enhancer.py @@ -145,24 +145,27 @@ def apply_args(program : ArgumentParser) -> None: def pre_check() -> bool: + download_directory_path = resolve_relative_path('../.assets/models') + model_url = get_options('model').get('url') + model_path = get_options('model').get('path') + if not facefusion.globals.skip_download: - download_directory_path = resolve_relative_path('../.assets/models') - model_url = get_options('model').get('url') process_manager.check() conditional_download(download_directory_path, [ model_url ]) process_manager.end() - return True + return is_file(model_path) def post_check() -> bool: model_url = get_options('model').get('url') model_path = get_options('model').get('path') - if not facefusion.globals.skip_download and not is_download_done(model_url, model_path): - logger.error(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME) - return False - elif not is_file(model_path): + + if facefusion.globals.skip_download and not is_file(model_path): logger.error(wording.get('model_file_not_present') + wording.get('exclamation_mark'), NAME) return False + if not is_download_done(model_url, model_path): + logger.error(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME) + return False return True diff --git a/facefusion/processors/frame/modules/face_swapper.py b/facefusion/processors/frame/modules/face_swapper.py index a988fbb3..0d440a57 100755 --- a/facefusion/processors/frame/modules/face_swapper.py +++ b/facefusion/processors/frame/modules/face_swapper.py @@ -173,24 +173,27 @@ def apply_args(program : ArgumentParser) -> None: def pre_check() -> bool: + download_directory_path = resolve_relative_path('../.assets/models') + model_url = get_options('model').get('url') + model_path = get_options('model').get('path') + if not facefusion.globals.skip_download: - download_directory_path = resolve_relative_path('../.assets/models') - model_url = get_options('model').get('url') process_manager.check() conditional_download(download_directory_path, [ model_url ]) process_manager.end() - return True + return is_file(model_path) def post_check() -> bool: model_url = get_options('model').get('url') model_path = get_options('model').get('path') - if not facefusion.globals.skip_download and not is_download_done(model_url, model_path): - logger.error(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME) - return False - elif not is_file(model_path): + + if facefusion.globals.skip_download and not is_file(model_path): logger.error(wording.get('model_file_not_present') + wording.get('exclamation_mark'), NAME) return False + if not is_download_done(model_url, model_path): + logger.error(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME) + return False return True diff --git a/facefusion/processors/frame/modules/frame_colorizer.py b/facefusion/processors/frame/modules/frame_colorizer.py index d2e63c76..49691701 100644 --- a/facefusion/processors/frame/modules/frame_colorizer.py +++ b/facefusion/processors/frame/modules/frame_colorizer.py @@ -99,24 +99,27 @@ def apply_args(program : ArgumentParser) -> None: def pre_check() -> bool: + download_directory_path = resolve_relative_path('../.assets/models') + model_url = get_options('model').get('url') + model_path = get_options('model').get('path') + if not facefusion.globals.skip_download: - download_directory_path = resolve_relative_path('../.assets/models') - model_url = get_options('model').get('url') process_manager.check() conditional_download(download_directory_path, [ model_url ]) process_manager.end() - return True + return is_file(model_path) def post_check() -> bool: model_url = get_options('model').get('url') model_path = get_options('model').get('path') - if not facefusion.globals.skip_download and not is_download_done(model_url, model_path): - logger.error(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME) - return False - elif not is_file(model_path): + + if facefusion.globals.skip_download and not is_file(model_path): logger.error(wording.get('model_file_not_present') + wording.get('exclamation_mark'), NAME) return False + if not is_download_done(model_url, model_path): + logger.error(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME) + return False return True diff --git a/facefusion/processors/frame/modules/frame_enhancer.py b/facefusion/processors/frame/modules/frame_enhancer.py index bf65fe10..f631cbf6 100644 --- a/facefusion/processors/frame/modules/frame_enhancer.py +++ b/facefusion/processors/frame/modules/frame_enhancer.py @@ -120,24 +120,27 @@ def apply_args(program : ArgumentParser) -> None: def pre_check() -> bool: + download_directory_path = resolve_relative_path('../.assets/models') + model_url = get_options('model').get('url') + model_path = get_options('model').get('path') + if not facefusion.globals.skip_download: - download_directory_path = resolve_relative_path('../.assets/models') - model_url = get_options('model').get('url') process_manager.check() conditional_download(download_directory_path, [ model_url ]) process_manager.end() - return True + return is_file(model_path) def post_check() -> bool: model_url = get_options('model').get('url') model_path = get_options('model').get('path') - if not facefusion.globals.skip_download and not is_download_done(model_url, model_path): - logger.error(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME) - return False - elif not is_file(model_path): + + if facefusion.globals.skip_download and not is_file(model_path): logger.error(wording.get('model_file_not_present') + wording.get('exclamation_mark'), NAME) return False + if not is_download_done(model_url, model_path): + logger.error(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME) + return False return True diff --git a/facefusion/processors/frame/modules/lip_syncer.py b/facefusion/processors/frame/modules/lip_syncer.py index 9b70ffb3..f29457ec 100755 --- a/facefusion/processors/frame/modules/lip_syncer.py +++ b/facefusion/processors/frame/modules/lip_syncer.py @@ -86,24 +86,27 @@ def apply_args(program : ArgumentParser) -> None: def pre_check() -> bool: + download_directory_path = resolve_relative_path('../.assets/models') + model_url = get_options('model').get('url') + model_path = get_options('model').get('path') + if not facefusion.globals.skip_download: - download_directory_path = resolve_relative_path('../.assets/models') - model_url = get_options('model').get('url') process_manager.check() conditional_download(download_directory_path, [ model_url ]) process_manager.end() - return True + return is_file(model_path) def post_check() -> bool: model_url = get_options('model').get('url') model_path = get_options('model').get('path') - if not facefusion.globals.skip_download and not is_download_done(model_url, model_path): - logger.error(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME) - return False - elif not is_file(model_path): + + if facefusion.globals.skip_download and not is_file(model_path): logger.error(wording.get('model_file_not_present') + wording.get('exclamation_mark'), NAME) return False + if not is_download_done(model_url, model_path): + logger.error(wording.get('model_download_not_done') + wording.get('exclamation_mark'), NAME) + return False return True