From 871c3840e56cae3b8008f148b42a297036a7df86 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 21 Aug 2023 14:35:32 +0200 Subject: [PATCH 1/3] Host assets on GitHub --- .github/workflows/ci.yml | 8 ++++---- .../processors/frame/modules/face_enhancer.py | 2 +- .../processors/frame/modules/face_swapper.py | 2 +- .../processors/frame/modules/frame_enhancer.py | 2 +- facefusion/uis/layouts/benchmark.py | 16 ++++++++-------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a88c200e..15ce7162 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,11 +31,11 @@ jobs: with: python-version: '3.10' - run: pip install -r requirements-ci.txt - - run: curl --create-dirs --output .assets/examples/source.jpg https://huggingface.co/facefusion/examples/resolve/main/source.jpg - - run: curl --create-dirs --output .assets/examples/target-240p.mp4 https://huggingface.co/facefusion/examples/resolve/main/target-240p.mp4 - - run: python run.py --source .assets/examples/source.jpg --target .assets/examples/target-240p.mp4 --output .assets/examples --trim-frame-end 24 + - run: curl --create-dirs --output .assets/examples/source.jpg https://github.com/facefusion/facefusion-assets/releases/download/examples/source.jpg + - run: curl --create-dirs --output .assets/examples/target-240p.mp4 https://github.com/facefusion/facefusion-assets/releases/download/examples/target-240p.mp4 + - run: python run.py --source .assets/examples/source.jpg --target .assets/examples/target-240p.mp4 --output .assets/examples --trim-frame-end 30 if: matrix.os != 'windows-latest' - - run: python run.py --source .assets\examples\source.jpg --target .assets\examples\target-240p.mp4 --output .assets\examples --trim-frame-end 24 + - run: python run.py --source .assets\examples\source.jpg --target .assets\examples\target-240p.mp4 --output .assets\examples --trim-frame-end 30 if: matrix.os == 'windows-latest' - run: ffprobe -show_format -show_streams .assets/examples/source-target-240p.mp4 if: matrix.os != 'windows-latest' diff --git a/facefusion/processors/frame/modules/face_enhancer.py b/facefusion/processors/frame/modules/face_enhancer.py index cdfb0a81..7c076125 100644 --- a/facefusion/processors/frame/modules/face_enhancer.py +++ b/facefusion/processors/frame/modules/face_enhancer.py @@ -39,7 +39,7 @@ def clear_frame_processor() -> None: def pre_check() -> bool: download_directory_path = resolve_relative_path('../.assets/models') - conditional_download(download_directory_path, ['https://huggingface.co/facefusion/models/resolve/main/GFPGANv1.4.pth']) + conditional_download(download_directory_path, ['https://github.com/facefusion/facefusion-assets/releases/download/models/GFPGANv1.4.pth']) return True diff --git a/facefusion/processors/frame/modules/face_swapper.py b/facefusion/processors/frame/modules/face_swapper.py index 338365c3..003bebb4 100644 --- a/facefusion/processors/frame/modules/face_swapper.py +++ b/facefusion/processors/frame/modules/face_swapper.py @@ -35,7 +35,7 @@ def clear_frame_processor() -> None: def pre_check() -> bool: download_directory_path = resolve_relative_path('../.assets/models') - conditional_download(download_directory_path, ['https://huggingface.co/facefusion/models/resolve/main/inswapper_128.onnx']) + conditional_download(download_directory_path, ['https://github.com/facefusion/facefusion-assets/releases/download/models/inswapper_128.onnx']) return True diff --git a/facefusion/processors/frame/modules/frame_enhancer.py b/facefusion/processors/frame/modules/frame_enhancer.py index 6d19273f..21f51ab9 100644 --- a/facefusion/processors/frame/modules/frame_enhancer.py +++ b/facefusion/processors/frame/modules/frame_enhancer.py @@ -47,7 +47,7 @@ def clear_frame_processor() -> None: def pre_check() -> bool: download_directory_path = resolve_relative_path('../.assets/models') - conditional_download(download_directory_path, ['https://huggingface.co/facefusion/models/resolve/main/RealESRGAN_x4plus.pth']) + conditional_download(download_directory_path, ['https://github.com/facefusion/facefusion-assets/releases/download/models/RealESRGAN_x4plus.pth']) return True diff --git a/facefusion/uis/layouts/benchmark.py b/facefusion/uis/layouts/benchmark.py index 109d5e3a..f7ddf370 100644 --- a/facefusion/uis/layouts/benchmark.py +++ b/facefusion/uis/layouts/benchmark.py @@ -7,14 +7,14 @@ from facefusion.utilities import conditional_download def pre_check() -> bool: conditional_download('.assets/examples', [ - 'https://huggingface.co/facefusion/examples/resolve/main/source.jpg', - 'https://huggingface.co/facefusion/examples/resolve/main/target-240p.mp4', - 'https://huggingface.co/facefusion/examples/resolve/main/target-360p.mp4', - 'https://huggingface.co/facefusion/examples/resolve/main/target-540p.mp4', - 'https://huggingface.co/facefusion/examples/resolve/main/target-720p.mp4', - 'https://huggingface.co/facefusion/examples/resolve/main/target-1080p.mp4', - 'https://huggingface.co/facefusion/examples/resolve/main/target-1440p.mp4', - 'https://huggingface.co/facefusion/examples/resolve/main/target-2160p.mp4' + 'https://github.com/facefusion/facefusion-assets/releases/download/examples/source.jpg', + 'https://github.com/facefusion/facefusion-assets/releases/download/examples/target-240p.mp4', + 'https://github.com/facefusion/facefusion-assets/releases/download/examples/target-360p.mp4', + 'https://github.com/facefusion/facefusion-assets/releases/download/examples/target-540p.mp4', + 'https://github.com/facefusion/facefusion-assets/releases/download/examples/target-720p.mp4', + 'https://github.com/facefusion/facefusion-assets/releases/download/examples/target-1080p.mp4', + 'https://github.com/facefusion/facefusion-assets/releases/download/examples/target-1440p.mp4', + 'https://github.com/facefusion/facefusion-assets/releases/download/examples/target-2160p.mp4' ]) return True From 8d1da5ad49d74208bbab4a6c5623d07b033d0838 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 21 Aug 2023 16:19:01 +0200 Subject: [PATCH 2/3] Let's get started with pytest --- .github/workflows/ci.yml | 15 +++------------ requirements-ci.txt | 3 ++- tests/__init__.py | 0 tests/test_cli.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_cli.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15ce7162..a0016eab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,8 @@ jobs: python-version: '3.10' - run: pip install flake8 - run: pip install mypy - - run: flake8 run.py facefusion - - run: mypy run.py facefusion + - run: flake8 run.py facefusion tests + - run: mypy run.py facefusion tests test: strategy: matrix: @@ -31,13 +31,4 @@ jobs: with: python-version: '3.10' - run: pip install -r requirements-ci.txt - - run: curl --create-dirs --output .assets/examples/source.jpg https://github.com/facefusion/facefusion-assets/releases/download/examples/source.jpg - - run: curl --create-dirs --output .assets/examples/target-240p.mp4 https://github.com/facefusion/facefusion-assets/releases/download/examples/target-240p.mp4 - - run: python run.py --source .assets/examples/source.jpg --target .assets/examples/target-240p.mp4 --output .assets/examples --trim-frame-end 30 - if: matrix.os != 'windows-latest' - - run: python run.py --source .assets\examples\source.jpg --target .assets\examples\target-240p.mp4 --output .assets\examples --trim-frame-end 30 - if: matrix.os == 'windows-latest' - - run: ffprobe -show_format -show_streams .assets/examples/source-target-240p.mp4 - if: matrix.os != 'windows-latest' - - run: ffprobe -show_format -show_streams .assets\examples\source-target-240p.mp4 - if: matrix.os == 'windows-latest' + - run: pytest diff --git a/requirements-ci.txt b/requirements-ci.txt index b974e0e5..f381ae5d 100644 --- a/requirements-ci.txt +++ b/requirements-ci.txt @@ -5,6 +5,7 @@ onnxruntime==1.15.1 opencv-python==4.8.0.74 opennsfw2==0.10.2 protobuf==4.23.4 +pytest==7.4.0 psutil==5.9.5 tensorflow==2.13.0 -tqdm==4.65.0 \ No newline at end of file +tqdm==4.65.0 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 00000000..138177ed --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,29 @@ +import subprocess +import pytest + +from facefusion import wording +from facefusion.utilities import conditional_download + + +@pytest.fixture(scope = 'module', autouse = True) +def setup() -> None: + conditional_download('.assets/examples', + [ + 'https://github.com/facefusion/facefusion-assets/releases/download/examples/source.jpg', + 'https://github.com/facefusion/facefusion-assets/releases/download/examples/target-1080p.mp4' + ]) + subprocess.run([ 'ffmpeg', '-i', '.assets/examples/target-1080p.mp4', '-vframes', '1', '.assets/examples/target-1080p.jpg' ]) + + +def test_image_to_image() -> None: + commands = [ 'python', 'run.py', '-s', '.assets/examples/source.jpg', '-t', '.assets/examples/target-1080p.jpg', '-o', '.assets/examples' ] + run = subprocess.run(commands, stdout = subprocess.PIPE) + assert run.returncode == 0 + assert wording.get('processing_image_succeed') in run.stdout.decode() + + +def test_image_to_video() -> None: + commands = [ 'python', 'run.py', '-s', '.assets/examples/source.jpg', '-t', '.assets/examples/target-1080p.mp4', '-o', '.assets/examples', '--trim-frame-end', '10' ] + run = subprocess.run(commands, stdout = subprocess.PIPE) + assert run.returncode == 0 + assert wording.get('processing_video_succeed') in run.stdout.decode() From bead4a6c5f0d22d33eb44d399af35c78e8be2ae2 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 21 Aug 2023 16:37:10 +0200 Subject: [PATCH 3/3] Basic testing for detect_fps --- tests/test_utilities.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/test_utilities.py diff --git a/tests/test_utilities.py b/tests/test_utilities.py new file mode 100644 index 00000000..251d57dd --- /dev/null +++ b/tests/test_utilities.py @@ -0,0 +1,21 @@ +import subprocess +import pytest + +from facefusion.utilities import conditional_download, detect_fps + + +@pytest.fixture(scope = 'module', autouse = True) +def setup() -> None: + conditional_download('.assets/examples', + [ + 'https://github.com/facefusion/facefusion-assets/releases/download/examples/target-1080p.mp4' + ]) + subprocess.run([ 'ffmpeg', '-i', '.assets/examples/target-1080p.mp4', '-vf', 'fps=25', '.assets/examples/target-1080p-25fps.mp4' ]) + subprocess.run([ 'ffmpeg', '-i', '.assets/examples/target-1080p.mp4', '-vf', 'fps=30', '.assets/examples/target-1080p-30fps.mp4' ]) + subprocess.run([ 'ffmpeg', '-i', '.assets/examples/target-1080p.mp4', '-vf', 'fps=60', '.assets/examples/target-1080p-60fps.mp4' ]) + + +def test_detect_fps() -> None: + assert detect_fps('.assets/examples/target-1080p-25fps.mp4') == 25.0 + assert detect_fps('.assets/examples/target-1080p-30fps.mp4') == 30.0 + assert detect_fps('.assets/examples/target-1080p-60fps.mp4') == 60.0