Allow bulk runner with target pattern only

This commit is contained in:
henryruhs 2024-11-12 18:57:18 +01:00
parent 244df12ff8
commit a6929d6cb4
3 changed files with 36 additions and 26 deletions

View File

@ -318,16 +318,24 @@ def process_bulk(args : Args) -> ErrorCode:
target_paths = resolve_file_pattern(job_args.get('target_pattern'))
if job_manager.create_job(job_id):
if source_paths and target_paths:
for index, (source_path, target_path) in enumerate(itertools.product(source_paths, target_paths)):
step_args['source_paths'] = [ source_path ]
step_args['target_path'] = target_path
step_args['output_path'] = job_args.get('output_pattern').format(index = index)
if not job_manager.add_step(job_id, step_args):
return 1
if job_manager.submit_job(job_id) and job_runner.run_job(job_id, process_step):
return 0
for index, (source_path, target_path) in enumerate(itertools.product(source_paths, target_paths)):
step_args['source_paths'] = [ source_path ]
step_args['target_path'] = target_path
step_args['output_path'] = job_args.get('output_pattern').format(index = index)
if not job_manager.add_step(job_id, step_args):
return 1
if job_manager.submit_job(job_id) and job_runner.run_job(job_id, process_step):
return 0
if not source_paths and target_paths:
for index, target_path in enumerate(target_paths):
step_args['target_path'] = target_path
step_args['output_path'] = job_args.get('output_pattern').format(index = index)
if not job_manager.add_step(job_id, step_args):
return 1
if job_manager.submit_job(job_id) and job_runner.run_job(job_id, process_step):
return 0
return 1

View File

@ -14,8 +14,8 @@ def before_all() -> None:
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p-a.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '2', get_test_example_file('target-240p-b.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p-bulk-1.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '2', get_test_example_file('target-240p-bulk-2.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
@ -25,19 +25,21 @@ def before_each() -> None:
prepare_test_output_directory()
def test_bulk_run_image_to_image() -> None:
commands = [ sys.executable, 'facefusion.py', 'bulk-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-s', get_test_example_file('target-240p-*.jpg'), '-t', get_test_example_file('target-240p-*.jpg'), '-o', get_test_output_file('test-bulk-run-image-to-image-{index}.jpg') ]
def test_bulk_run_targets() -> None:
commands = [ sys.executable, 'facefusion.py', 'bulk-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p-bulk-*.jpg'), '-o', get_test_output_file('test-bulk-run-targets-{index}.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-bulk-run-image-to-image-0.jpg') is True
assert is_test_output_file('test-bulk-run-image-to-image-1.jpg') is True
assert is_test_output_file('test-bulk-run-image-to-image-2.jpg') is True
assert is_test_output_file('test-bulk-run-image-to-image-3.jpg') is True
assert is_test_output_file('test-bulk-run-targets-0.jpg') is True
assert is_test_output_file('test-bulk-run-targets-1.jpg') is True
assert is_test_output_file('test-bulk-run-targets-2.jpg') is False
def test_bulk_run_image_to_video() -> None:
commands = [ sys.executable, 'facefusion.py', 'bulk-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-s', get_test_example_file('target-240p-*.jpg'), '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-bulk-run-image-to-video-{index}.mp4') ]
def test_bulk_run_sources_to_targets() -> None:
commands = [ sys.executable, 'facefusion.py', 'bulk-run', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('target-240p-bulk-*.jpg'), '-t', get_test_example_file('target-240p-bulk-*.jpg'), '-o', get_test_output_file('test-bulk-run-sources-to-targets-{index}.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-bulk-run-image-to-video-0.mp4') is True
assert is_test_output_file('test-bulk-run-image-to-video-1.mp4') is True
assert is_test_output_file('test-bulk-run-sources-to-targets-0.jpg') is True
assert is_test_output_file('test-bulk-run-sources-to-targets-1.jpg') is True
assert is_test_output_file('test-bulk-run-sources-to-targets-2.jpg') is True
assert is_test_output_file('test-bulk-run-sources-to-targets-3.jpg') is True
assert is_test_output_file('test-bulk-run-sources-to-targets-4.jpg') is False

View File

@ -1,6 +1,5 @@
import subprocess
import cv2
import pytest
from facefusion.download import conditional_download
@ -18,6 +17,7 @@ def before_all() -> None:
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-1080p.mp4'), '-vframes', '1', get_test_example_file('target-1080p.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', '-vf', 'hue=s=0', get_test_example_file('target-240p-0sat.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', '-vf', 'transpose=0', get_test_example_file('target-240p-90deg.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-1080p.mp4'), '-vframes', '1', '-vf', 'transpose=0', get_test_example_file('target-1080p-90deg.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'fps=25', get_test_example_file('target-240p-25fps.mp4') ])
@ -118,16 +118,16 @@ def test_unpack_resolution() -> None:
def test_calc_histogram_difference() -> None:
source_vision_frame = read_image(get_test_example_file('target-1080p.jpg'))
target_vision_frame = cv2.cvtColor(cv2.cvtColor(source_vision_frame, cv2.COLOR_BGR2GRAY), cv2.COLOR_GRAY2BGR)
source_vision_frame = read_image(get_test_example_file('target-240p.jpg'))
target_vision_frame = read_image(get_test_example_file('target-240p-0sat.jpg'))
assert calc_histogram_difference(source_vision_frame, source_vision_frame) == 1.0
assert calc_histogram_difference(source_vision_frame, target_vision_frame) < 0.5
def test_match_frame_color() -> None:
source_vision_frame = read_image(get_test_example_file('target-1080p.jpg'))
target_vision_frame = cv2.cvtColor(cv2.cvtColor(source_vision_frame, cv2.COLOR_BGR2GRAY), cv2.COLOR_GRAY2BGR)
source_vision_frame = read_image(get_test_example_file('target-240p.jpg'))
target_vision_frame = read_image(get_test_example_file('target-240p-0sat.jpg'))
output_vision_frame = match_frame_color(source_vision_frame, target_vision_frame)
assert calc_histogram_difference(source_vision_frame, output_vision_frame) > 0.5