Use resolve_download_url() everywhere, Vanish --skip-download flag

This commit is contained in:
henryruhs 2024-11-23 17:56:08 +01:00
parent efd4071a3e
commit 44b4c926da
18 changed files with 63 additions and 82 deletions

View File

@ -103,7 +103,6 @@ execution_queue_count =
[download]
download_providers =
skip_download =
[memory]
video_memory_strategy =

View File

@ -120,7 +120,6 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
apply_state_item('execution_queue_count', args.get('execution_queue_count'))
# download
apply_state_item('download_providers', args.get('download_providers'))
apply_state_item('skip_download', args.get('skip_download'))
# memory
apply_state_item('video_memory_strategy', args.get('video_memory_strategy'))
apply_state_item('system_memory_limit', args.get('system_memory_limit'))

View File

@ -5,7 +5,7 @@ import numpy
from tqdm import tqdm
from facefusion import inference_manager, state_manager, wording
from facefusion.download import conditional_download_hashes, conditional_download_sources
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
from facefusion.filesystem import resolve_relative_path
from facefusion.thread_helper import conditional_thread_semaphore
from facefusion.typing import Fps, InferencePool, ModelOptions, ModelSet, VisionFrame
@ -26,7 +26,7 @@ def create_static_model_set() -> ModelSet:
{
'content_analyser':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/open_nsfw.hash',
'url': resolve_download_url('models-3.0.0', 'open_nsfw.hash'),
'path': resolve_relative_path('../.assets/models/open_nsfw.hash')
}
},
@ -34,7 +34,7 @@ def create_static_model_set() -> ModelSet:
{
'content_analyser':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/open_nsfw.onnx',
'url': resolve_download_url('models-3.0.0', 'open_nsfw.onnx'),
'path': resolve_relative_path('../.assets/models/open_nsfw.onnx')
}
},

View File

@ -52,7 +52,6 @@ def conditional_download_hashes(hashes : DownloadSet) -> bool:
hash_paths = [ hashes.get(hash_key).get('path') for hash_key in hashes.keys() ]
process_manager.check()
if not state_manager.get_item('skip_download'):
_, invalid_hash_paths = validate_hash_paths(hash_paths)
if invalid_hash_paths:
for index in hashes:
@ -78,7 +77,6 @@ def conditional_download_sources(sources : DownloadSet) -> bool:
source_paths = [ sources.get(source_key).get('path') for source_key in sources.keys() ]
process_manager.check()
if not state_manager.get_item('skip_download'):
_, invalid_source_paths = validate_source_paths(source_paths)
if invalid_source_paths:
for index in sources:

View File

@ -4,7 +4,7 @@ from typing import List, Tuple
import numpy
from facefusion import inference_manager
from facefusion.download import conditional_download_hashes, conditional_download_sources
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
from facefusion.face_helper import warp_face_by_face_landmark_5
from facefusion.filesystem import resolve_relative_path
from facefusion.thread_helper import conditional_thread_semaphore
@ -21,7 +21,7 @@ def create_static_model_set() -> ModelSet:
{
'face_classifier':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fairface.hash',
'url': resolve_download_url('models-3.0.0', 'fairface.hash'),
'path': resolve_relative_path('../.assets/models/fairface.hash')
}
},
@ -29,7 +29,7 @@ def create_static_model_set() -> ModelSet:
{
'face_classifier':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fairface.onnx',
'url': resolve_download_url('models-3.0.0', 'fairface.onnx'),
'path': resolve_relative_path('../.assets/models/fairface.onnx')
}
},

View File

@ -5,7 +5,7 @@ import numpy
from charset_normalizer.md import lru_cache
from facefusion import inference_manager, state_manager
from facefusion.download import conditional_download_hashes, conditional_download_sources
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
from facefusion.face_helper import create_rotated_matrix_and_size, create_static_anchors, distance_to_bounding_box, distance_to_face_landmark_5, normalize_bounding_box, transform_bounding_box, transform_points
from facefusion.filesystem import resolve_relative_path
from facefusion.thread_helper import thread_semaphore
@ -23,7 +23,7 @@ def create_static_model_set() -> ModelSet:
{
'retinaface':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/retinaface_10g.hash',
'url': resolve_download_url('models-3.0.0', 'retinaface_10g.hash'),
'path': resolve_relative_path('../.assets/models/retinaface_10g.hash')
}
},
@ -31,7 +31,7 @@ def create_static_model_set() -> ModelSet:
{
'retinaface':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/retinaface_10g.onnx',
'url': resolve_download_url('models-3.0.0', 'retinaface_10g.onnx'),
'path': resolve_relative_path('../.assets/models/retinaface_10g.onnx')
}
}
@ -42,7 +42,7 @@ def create_static_model_set() -> ModelSet:
{
'scrfd':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/scrfd_2.5g.hash',
'url': resolve_download_url('models-3.0.0', 'scrfd_2.5g.hash'),
'path': resolve_relative_path('../.assets/models/scrfd_2.5g.hash')
}
},
@ -50,7 +50,7 @@ def create_static_model_set() -> ModelSet:
{
'scrfd':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/scrfd_2.5g.onnx',
'url': resolve_download_url('models-3.0.0', 'scrfd_2.5g.onnx'),
'path': resolve_relative_path('../.assets/models/scrfd_2.5g.onnx')
}
}
@ -61,7 +61,7 @@ def create_static_model_set() -> ModelSet:
{
'yoloface':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/yoloface_8n.hash',
'url': resolve_download_url('models-3.0.0', 'yoloface_8n.hash'),
'path': resolve_relative_path('../.assets/models/yoloface_8n.hash')
}
},
@ -69,7 +69,7 @@ def create_static_model_set() -> ModelSet:
{
'yoloface':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/yoloface_8n.onnx',
'url': resolve_download_url('models-3.0.0', 'yoloface_8n.onnx'),
'path': resolve_relative_path('../.assets/models/yoloface_8n.onnx')
}
}

View File

@ -5,7 +5,7 @@ import cv2
import numpy
from facefusion import inference_manager, state_manager
from facefusion.download import conditional_download_hashes, conditional_download_sources
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
from facefusion.face_helper import create_rotated_matrix_and_size, estimate_matrix_by_face_landmark_5, transform_points, warp_face_by_translation
from facefusion.filesystem import resolve_relative_path
from facefusion.thread_helper import conditional_thread_semaphore
@ -22,7 +22,7 @@ def create_static_model_set() -> ModelSet:
{
'2dfan4':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/2dfan4.hash',
'url': resolve_download_url('models-3.0.0', '2dfan4.hash'),
'path': resolve_relative_path('../.assets/models/2dfan4.hash')
}
},
@ -30,7 +30,7 @@ def create_static_model_set() -> ModelSet:
{
'2dfan4':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/2dfan4.onnx',
'url': resolve_download_url('models-3.0.0', '2dfan4.onnx'),
'path': resolve_relative_path('../.assets/models/2dfan4.onnx')
}
},
@ -42,7 +42,7 @@ def create_static_model_set() -> ModelSet:
{
'peppa_wutz':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/peppa_wutz.hash',
'url': resolve_download_url('models-3.0.0', 'peppa_wutz.hash'),
'path': resolve_relative_path('../.assets/models/peppa_wutz.hash')
}
},
@ -50,7 +50,7 @@ def create_static_model_set() -> ModelSet:
{
'peppa_wutz':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/peppa_wutz.onnx',
'url': resolve_download_url('models-3.0.0', 'peppa_wutz.onnx'),
'path': resolve_relative_path('../.assets/models/peppa_wutz.onnx')
}
},
@ -62,7 +62,7 @@ def create_static_model_set() -> ModelSet:
{
'fan_68_5':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fan_68_5.hash',
'url': resolve_download_url('models-3.0.0', 'fan_68_5.hash'),
'path': resolve_relative_path('../.assets/models/fan_68_5.hash')
}
},
@ -70,7 +70,7 @@ def create_static_model_set() -> ModelSet:
{
'fan_68_5':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fan_68_5.onnx',
'url': resolve_download_url('models-3.0.0', 'fan_68_5.onnx'),
'path': resolve_relative_path('../.assets/models/fan_68_5.onnx')
}
}

View File

@ -6,7 +6,7 @@ import numpy
from cv2.typing import Size
from facefusion import inference_manager
from facefusion.download import conditional_download_hashes, conditional_download_sources
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
from facefusion.filesystem import resolve_relative_path
from facefusion.thread_helper import conditional_thread_semaphore
from facefusion.typing import DownloadSet, FaceLandmark68, FaceMaskRegion, InferencePool, Mask, ModelSet, Padding, VisionFrame
@ -36,7 +36,7 @@ def create_static_model_set() -> ModelSet:
{
'face_occluder':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.1.0/xseg_groggy_5.hash',
'url': resolve_download_url('models-3.1.0', 'xseg_groggy_5.hash'),
'path': resolve_relative_path('../.assets/models/xseg_groggy_5.hash')
}
},
@ -44,7 +44,7 @@ def create_static_model_set() -> ModelSet:
{
'face_occluder':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.1.0/xseg_groggy_5.onnx',
'url': resolve_download_url('models-3.1.0', 'xseg_groggy_5.onnx'),
'path': resolve_relative_path('../.assets/models/xseg_groggy_5.onnx')
}
},
@ -56,7 +56,7 @@ def create_static_model_set() -> ModelSet:
{
'face_parser':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/bisenet_resnet_34.hash',
'url': resolve_download_url('models-3.0.0', 'bisenet_resnet_34.hash'),
'path': resolve_relative_path('../.assets/models/bisenet_resnet_34.hash')
}
},
@ -64,7 +64,7 @@ def create_static_model_set() -> ModelSet:
{
'face_parser':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/bisenet_resnet_34.onnx',
'url': resolve_download_url('models-3.0.0', 'bisenet_resnet_34'),
'path': resolve_relative_path('../.assets/models/bisenet_resnet_34.onnx')
}
},

View File

@ -4,7 +4,7 @@ from typing import Tuple
import numpy
from facefusion import inference_manager
from facefusion.download import conditional_download_hashes, conditional_download_sources
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
from facefusion.face_helper import warp_face_by_face_landmark_5
from facefusion.filesystem import resolve_relative_path
from facefusion.thread_helper import conditional_thread_semaphore
@ -21,7 +21,7 @@ def create_static_model_set() -> ModelSet:
{
'face_recognizer':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_w600k_r50.hash',
'url': resolve_download_url('models-3.0.0', 'arcface_w600k_r50.hash'),
'path': resolve_relative_path('../.assets/models/arcface_w600k_r50.hash')
}
},
@ -29,7 +29,7 @@ def create_static_model_set() -> ModelSet:
{
'face_recognizer':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_w600k_r50.onnx',
'url': resolve_download_url('models-3.0.0', 'arcface_w600k_r50.onnx'),
'path': resolve_relative_path('../.assets/models/arcface_w600k_r50.onnx')
}
},

View File

@ -207,14 +207,6 @@ def create_download_providers_program() -> ArgumentParser:
return program
def create_skip_download_program() -> ArgumentParser:
program = ArgumentParser(add_help = False)
group_download = program.add_argument_group('download')
group_download.add_argument('--skip-download', help = wording.get('help.skip_download'), action = 'store_true', default = config.get_bool_value('misc.skip_download'))
job_store.register_job_keys([ 'skip_download' ])
return program
def create_memory_program() -> ArgumentParser:
program = ArgumentParser(add_help = False)
group_memory = program.add_argument_group('memory')
@ -256,7 +248,7 @@ def collect_step_program() -> ArgumentParser:
def collect_job_program() -> ArgumentParser:
return ArgumentParser(parents= [ create_execution_program(), create_download_providers_program(), create_skip_download_program(), create_memory_program(), create_log_level_program() ], add_help = False)
return ArgumentParser(parents= [ create_execution_program(), create_download_providers_program(), create_memory_program(), create_log_level_program() ], add_help = False)
def create_program() -> ArgumentParser:

View File

@ -249,7 +249,6 @@ StateKey = Literal\
'execution_thread_count',
'execution_queue_count',
'download_providers',
'skip_download',
'video_memory_strategy',
'system_memory_limit',
'log_level',
@ -310,7 +309,6 @@ State = TypedDict('State',
'execution_thread_count' : int,
'execution_queue_count' : int,
'download_providers' : List[DownloadProviderKey],
'skip_download' : bool,
'video_memory_strategy' : VideoMemoryStrategy,
'system_memory_limit' : int,
'log_level' : LogLevel,

View File

@ -5,7 +5,7 @@ from facefusion.uis.typing import JobManagerAction, JobRunnerAction, WebcamMode
job_manager_actions : List[JobManagerAction] = [ 'job-create', 'job-submit', 'job-delete', 'job-add-step', 'job-remix-step', 'job-insert-step', 'job-remove-step' ]
job_runner_actions : List[JobRunnerAction] = [ 'job-run', 'job-run-all', 'job-retry', 'job-retry-all' ]
common_options : List[str] = [ 'keep-temp', 'skip-audio', 'skip-download' ]
common_options : List[str] = [ 'keep-temp', 'skip-audio' ]
webcam_modes : List[WebcamMode] = [ 'inline', 'udp', 'v4l2' ]
webcam_resolutions : List[str] = [ '320x240', '640x480', '800x600', '1024x768', '1280x720', '1280x960', '1920x1080', '2560x1440', '3840x2160' ]

View File

@ -13,8 +13,6 @@ def render() -> None:
common_options = []
if state_manager.get_item('skip_download'):
common_options.append('skip-download')
if state_manager.get_item('keep_temp'):
common_options.append('keep-temp')
if state_manager.get_item('skip_audio'):
@ -32,9 +30,7 @@ def listen() -> None:
def update(common_options : List[str]) -> None:
skip_temp = 'skip-download' in common_options
keep_temp = 'keep-temp' in common_options
skip_audio = 'skip-audio' in common_options
state_manager.set_item('skip_download', skip_temp)
state_manager.set_item('keep_temp', keep_temp)
state_manager.set_item('skip_audio', skip_audio)

View File

@ -6,7 +6,6 @@ from facefusion.uis.components import about, age_modifier_options, benchmark, be
def pre_check() -> bool:
if not state_manager.get_item('skip_download'):
conditional_download('.assets/examples',
[
resolve_download_url('examples-3.0.0', 'source.jpg'),
@ -20,7 +19,6 @@ def pre_check() -> bool:
resolve_download_url('examples-3.0.0', 'target-2160p.mp4')
])
return True
return False
def render() -> gradio.Blocks:

View File

@ -5,7 +5,7 @@ import numpy
import scipy
from facefusion import inference_manager
from facefusion.download import conditional_download_hashes, conditional_download_sources
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
from facefusion.filesystem import resolve_relative_path
from facefusion.thread_helper import thread_semaphore
from facefusion.typing import Audio, AudioChunk, InferencePool, ModelOptions, ModelSet
@ -21,7 +21,7 @@ def create_static_model_set() -> ModelSet:
{
'voice_extractor':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/kim_vocal_2.hash',
'url': resolve_download_url('models-3.0.0', 'kim_vocal_2.hash'),
'path': resolve_relative_path('../.assets/models/kim_vocal_2.hash')
}
},
@ -29,7 +29,7 @@ def create_static_model_set() -> ModelSet:
{
'voice_extractor':
{
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/kim_vocal_2.onnx',
'url': resolve_download_url('models-3.0.0', 'kim_vocal_2.onnx'),
'path': resolve_relative_path('../.assets/models/kim_vocal_2.onnx')
}
}

View File

@ -185,7 +185,6 @@ WORDING : Dict[str, Any] =\
'execution_queue_count': 'specify the amount of frames each thread is processing',
# download
'download_providers': 'download using different providers (choices: {choices}, ...)',
'skip_download': 'omit downloads and remote lookups',
# memory
'video_memory_strategy': 'balance fast processing and low VRAM usage',
'system_memory_limit': 'limit the available RAM that can be used while processing',

View File

@ -21,6 +21,7 @@ def before_all() -> None:
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.6:ih*0.6', get_test_example_file('source-60crop.jpg') ])
state_manager.init_item('execution_device_id', 0)
state_manager.init_item('execution_providers', [ 'cpu' ])
state_manager.init_item('download_providers', [ 'github' ])
state_manager.init_item('face_detector_angles', [ 0 ])
state_manager.init_item('face_detector_model', 'many')
state_manager.init_item('face_detector_score', 0.5)

View File

@ -9,9 +9,10 @@ from facefusion.inference_manager import INFERENCE_POOLS, get_inference_pool
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
content_analyser.pre_check()
state_manager.init_item('execution_device_id', 0)
state_manager.init_item('execution_providers', [ 'cpu' ])
state_manager.init_item('download_providers', [ 'github' ])
content_analyser.pre_check()
def test_get_inference_pool() -> None: