mirror of
https://github.com/facefusion/facefusion.git
synced 2026-06-06 20:53:54 +02:00
flatten the face store
This commit is contained in:
@@ -9,7 +9,7 @@ import facefusion.choices
|
||||
from facefusion import content_analyser, core, state_manager
|
||||
from facefusion.cli_helper import render_table
|
||||
from facefusion.download import conditional_download, resolve_download_url
|
||||
from facefusion.face_store import clear_static_faces
|
||||
from facefusion.face_store import clear_faces
|
||||
from facefusion.filesystem import get_file_extension
|
||||
from facefusion.types import BenchmarkCycleSet
|
||||
from facefusion.vision import count_video_frame_total, detect_video_fps
|
||||
@@ -64,7 +64,7 @@ def cycle(cycle_count : int) -> BenchmarkCycleSet:
|
||||
if state_manager.get_item('benchmark_mode') == 'cold':
|
||||
content_analyser.analyse_image.cache_clear()
|
||||
content_analyser.analyse_video.cache_clear()
|
||||
clear_static_faces()
|
||||
clear_faces()
|
||||
|
||||
start_time = perf_counter()
|
||||
core.conditional_process()
|
||||
|
||||
@@ -9,7 +9,7 @@ from facefusion.face_detector import detect_faces, detect_faces_by_angle
|
||||
from facefusion.face_helper import apply_nms, convert_to_face_landmark_5, estimate_face_angle, get_nms_threshold
|
||||
from facefusion.face_landmarker import detect_face_landmark, estimate_face_landmark_68_5
|
||||
from facefusion.face_recognizer import calculate_face_embedding
|
||||
from facefusion.face_store import get_static_faces, set_static_faces
|
||||
from facefusion.face_store import get_faces, set_faces
|
||||
from facefusion.types import BoundingBox, Face, FaceLandmark5, FaceLandmarkSet, FaceScoreSet, Score, VisionFrame
|
||||
|
||||
|
||||
@@ -98,9 +98,9 @@ def get_many_faces(vision_frames : List[VisionFrame]) -> List[Face]:
|
||||
|
||||
for vision_frame in vision_frames:
|
||||
if numpy.any(vision_frame):
|
||||
static_faces = get_static_faces(vision_frame)
|
||||
if static_faces:
|
||||
many_faces.extend(static_faces)
|
||||
faces = get_faces(vision_frame)
|
||||
if faces:
|
||||
many_faces.extend(faces)
|
||||
else:
|
||||
all_bounding_boxes = []
|
||||
all_face_scores = []
|
||||
@@ -120,7 +120,7 @@ def get_many_faces(vision_frames : List[VisionFrame]) -> List[Face]:
|
||||
|
||||
if faces:
|
||||
many_faces.extend(faces)
|
||||
set_static_faces(vision_frame, faces)
|
||||
set_faces(vision_frame, faces)
|
||||
return many_faces
|
||||
|
||||
|
||||
|
||||
@@ -3,26 +3,19 @@ from typing import List, Optional
|
||||
from facefusion.hash_helper import create_hash
|
||||
from facefusion.types import Face, FaceStore, VisionFrame
|
||||
|
||||
FACE_STORE : FaceStore =\
|
||||
{
|
||||
'static_faces': {}
|
||||
}
|
||||
FACE_STORE : FaceStore = {}
|
||||
|
||||
|
||||
def get_face_store() -> FaceStore:
|
||||
return FACE_STORE
|
||||
|
||||
|
||||
def get_static_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
|
||||
def get_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
|
||||
vision_hash = create_hash(vision_frame.tobytes())
|
||||
return FACE_STORE.get('static_faces').get(vision_hash)
|
||||
return FACE_STORE.get(vision_hash)
|
||||
|
||||
|
||||
def set_static_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
|
||||
def set_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
|
||||
vision_hash = create_hash(vision_frame.tobytes())
|
||||
if vision_hash:
|
||||
FACE_STORE['static_faces'][vision_hash] = faces
|
||||
FACE_STORE[vision_hash] = faces
|
||||
|
||||
|
||||
def clear_static_faces() -> None:
|
||||
FACE_STORE['static_faces'].clear()
|
||||
def clear_faces() -> None:
|
||||
FACE_STORE.clear()
|
||||
|
||||
+1
-5
@@ -44,11 +44,7 @@ Face = namedtuple('Face',
|
||||
'age',
|
||||
'race'
|
||||
])
|
||||
FaceSet : TypeAlias = Dict[str, List[Face]]
|
||||
FaceStore = TypedDict('FaceStore',
|
||||
{
|
||||
'static_faces' : FaceSet
|
||||
})
|
||||
FaceStore : TypeAlias = Dict[str, List[Face]]
|
||||
|
||||
Language = Literal['en']
|
||||
Locales : TypeAlias = Dict[Language, Dict[str, Any]]
|
||||
|
||||
@@ -9,7 +9,7 @@ from facefusion import state_manager, translator
|
||||
from facefusion.common_helper import calculate_float_step, calculate_int_step
|
||||
from facefusion.face_analyser import get_many_faces
|
||||
from facefusion.face_selector import sort_and_filter_faces
|
||||
from facefusion.face_store import clear_static_faces
|
||||
from facefusion.face_store import clear_faces
|
||||
from facefusion.filesystem import is_image, is_video
|
||||
from facefusion.types import FaceSelectorMode, FaceSelectorOrder, Gender, Race, VisionFrame
|
||||
from facefusion.uis.core import get_ui_component, get_ui_components, register_ui_component
|
||||
@@ -194,7 +194,7 @@ def clear_reference_frame_number() -> None:
|
||||
|
||||
|
||||
def clear_and_update_reference_position_gallery() -> gradio.Gallery:
|
||||
clear_static_faces()
|
||||
clear_faces()
|
||||
return update_reference_position_gallery()
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from facefusion.common_helper import get_first
|
||||
from facefusion.content_analyser import analyse_frame
|
||||
from facefusion.face_analyser import get_one_face
|
||||
from facefusion.face_selector import select_faces
|
||||
from facefusion.face_store import clear_static_faces
|
||||
from facefusion.face_store import clear_faces
|
||||
from facefusion.filesystem import filter_audio_paths, is_image, is_video
|
||||
from facefusion.processors.core import get_processors_modules
|
||||
from facefusion.types import AudioFrame, Face, Mask, VisionFrame
|
||||
@@ -218,7 +218,7 @@ def update_preview_image(preview_mode : PreviewMode, preview_resolution : str, f
|
||||
|
||||
|
||||
def clear_and_update_preview_image(preview_mode : PreviewMode, preview_resolution : str, frame_number : int = 0) -> gradio.Image:
|
||||
clear_static_faces()
|
||||
clear_faces()
|
||||
return update_preview_image(preview_mode, preview_resolution, frame_number)
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import Optional, Tuple
|
||||
import gradio
|
||||
|
||||
from facefusion import state_manager, translator
|
||||
from facefusion.face_store import clear_static_faces
|
||||
from facefusion.face_store import clear_faces
|
||||
from facefusion.filesystem import is_image, is_video
|
||||
from facefusion.uis.core import register_ui_component
|
||||
from facefusion.uis.types import ComponentOptions, File
|
||||
@@ -51,7 +51,7 @@ def listen() -> None:
|
||||
|
||||
|
||||
def update(file : File) -> Tuple[gradio.Image, gradio.Video]:
|
||||
clear_static_faces()
|
||||
clear_faces()
|
||||
|
||||
if file and is_image(file.name):
|
||||
state_manager.set_item('target_path', file.name)
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import Optional, Tuple
|
||||
from gradio_rangeslider import RangeSlider
|
||||
|
||||
from facefusion import state_manager, translator
|
||||
from facefusion.face_store import clear_static_faces
|
||||
from facefusion.face_store import clear_faces
|
||||
from facefusion.filesystem import is_video
|
||||
from facefusion.uis.core import get_ui_components
|
||||
from facefusion.uis.types import ComponentOptions
|
||||
@@ -53,7 +53,7 @@ def remote_update() -> RangeSlider:
|
||||
|
||||
|
||||
def update_trim_frame(trim_frame : Tuple[float, float]) -> None:
|
||||
clear_static_faces()
|
||||
clear_faces()
|
||||
trim_frame_start, trim_frame_end = trim_frame
|
||||
video_frame_total = count_video_frame_total(state_manager.get_item('target_path'))
|
||||
trim_frame_start = int(trim_frame_start) if trim_frame_start > 0 else None
|
||||
|
||||
@@ -5,7 +5,7 @@ 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.face_store import clear_faces
|
||||
from facefusion.vision import read_static_image
|
||||
from .helper import get_test_example_file, get_test_examples_directory
|
||||
|
||||
@@ -38,7 +38,7 @@ def before_each() -> None:
|
||||
face_detector.clear_inference_pool()
|
||||
face_landmarker.clear_inference_pool()
|
||||
face_recognizer.clear_inference_pool()
|
||||
clear_static_faces()
|
||||
clear_faces()
|
||||
|
||||
|
||||
def test_get_one_face_with_retinaface() -> None:
|
||||
|
||||
Reference in New Issue
Block a user