Files
facefusion/tests/test_face_analyser.py
T
Harisreedhar ab24cd3f2e Implement basic webrtc stream (#1054)
* implement basic webrtc_stream

* add aiortc to requirements.txt

* update aiortc version

* rename variables with rtc_ prefix

* changes

* changes

* change helper to assert_helper and stream_helper

* rename variables with rtc_ prefix

* add error handling

* return whole connection

* remove monkey patch and some cleaning

* cleanup

* tiny adjustments

* tiny adjustments

* proper typing and naming for rtc offer set

* - remove async from on_video_track method
- rename source -> target
- add audio

* audio always before video

---------

Co-authored-by: henryruhs <info@henryruhs.com>
2026-03-17 14:02:40 +01:00

134 lines
4.5 KiB
Python

import subprocess
import pytest
from facefusion import face_classifier, face_detector, face_landmarker, face_recognizer, state_manager
from facefusion.download import conditional_download
from facefusion.face_analyser import get_many_faces
from facefusion.face_store import clear_static_faces
from facefusion.vision import read_static_image
from .assert_helper import get_test_example_file, get_test_examples_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.8:ih*0.8', get_test_example_file('source-80crop.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.7:ih*0.7', get_test_example_file('source-70crop.jpg') ])
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_ids', [ 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)
state_manager.init_item('face_landmarker_model', 'many')
state_manager.init_item('face_landmarker_score', 0.5)
face_classifier.pre_check()
face_landmarker.pre_check()
face_recognizer.pre_check()
@pytest.fixture(autouse = True)
def before_each() -> None:
face_classifier.clear_inference_pool()
face_detector.clear_inference_pool()
face_landmarker.clear_inference_pool()
face_recognizer.clear_inference_pool()
clear_static_faces()
def test_get_one_face_with_retinaface() -> None:
state_manager.init_item('face_detector_model', 'retinaface')
state_manager.init_item('face_detector_size', '320x320')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
source_paths =\
[
get_test_example_file('source.jpg'),
get_test_example_file('source-80crop.jpg'),
get_test_example_file('source-70crop.jpg'),
get_test_example_file('source-60crop.jpg')
]
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
assert len(many_faces) == 1
def test_get_one_face_with_scrfd() -> None:
state_manager.init_item('face_detector_model', 'scrfd')
state_manager.init_item('face_detector_size', '320x320')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
source_paths =\
[
get_test_example_file('source.jpg'),
get_test_example_file('source-80crop.jpg'),
get_test_example_file('source-70crop.jpg'),
get_test_example_file('source-60crop.jpg')
]
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
assert len(many_faces) == 1
def test_get_one_face_with_yoloface() -> None:
state_manager.init_item('face_detector_model', 'yolo_face')
state_manager.init_item('face_detector_size', '640x640')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
source_paths =\
[
get_test_example_file('source.jpg'),
get_test_example_file('source-80crop.jpg'),
get_test_example_file('source-70crop.jpg'),
get_test_example_file('source-60crop.jpg')
]
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
assert len(many_faces) == 1
def test_get_one_face_with_yunet() -> None:
state_manager.init_item('face_detector_model', 'yunet')
state_manager.init_item('face_detector_size', '640x640')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
source_paths =\
[
get_test_example_file('source.jpg'),
get_test_example_file('source-80crop.jpg'),
get_test_example_file('source-70crop.jpg'),
get_test_example_file('source-60crop.jpg')
]
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
assert len(many_faces) == 1
def test_get_many_faces() -> None:
source_path = get_test_example_file('source.jpg')
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame, source_frame, source_frame ])
assert len(many_faces) == 3