Ban lambda usage
This commit is contained in:
@@ -2,6 +2,7 @@ import itertools
|
|||||||
import shutil
|
import shutil
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
from functools import partial
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
@@ -31,7 +32,7 @@ from facefusion.vision import pack_resolution, read_image, read_static_images, r
|
|||||||
|
|
||||||
def cli() -> None:
|
def cli() -> None:
|
||||||
if pre_check():
|
if pre_check():
|
||||||
signal.signal(signal.SIGINT, lambda signal_number, frame: graceful_exit(0))
|
signal.signal(signal.SIGINT, partial(graceful_exit, 0))
|
||||||
program = create_program()
|
program = create_program()
|
||||||
|
|
||||||
if validate_args(program):
|
if validate_args(program):
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from typing import List
|
|||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
from facefusion import state_manager
|
from facefusion import state_manager
|
||||||
from facefusion.types import Face, FaceSelectorOrder, FaceSet, Gender, Race
|
from facefusion.types import Face, FaceSelectorOrder, FaceSet, Gender, Race, Score
|
||||||
|
|
||||||
|
|
||||||
def find_similar_faces(faces : List[Face], reference_faces : FaceSet, face_distance : float) -> List[Face]:
|
def find_similar_faces(faces : List[Face], reference_faces : FaceSet, face_distance : float) -> List[Face]:
|
||||||
@@ -46,24 +46,40 @@ def sort_and_filter_faces(faces : List[Face]) -> List[Face]:
|
|||||||
|
|
||||||
def sort_faces_by_order(faces : List[Face], order : FaceSelectorOrder) -> List[Face]:
|
def sort_faces_by_order(faces : List[Face], order : FaceSelectorOrder) -> List[Face]:
|
||||||
if order == 'left-right':
|
if order == 'left-right':
|
||||||
return sorted(faces, key = lambda face: face.bounding_box[0])
|
return sorted(faces, key = get_bounding_box_left)
|
||||||
if order == 'right-left':
|
if order == 'right-left':
|
||||||
return sorted(faces, key = lambda face: face.bounding_box[0], reverse = True)
|
return sorted(faces, key = get_bounding_box_left, reverse = True)
|
||||||
if order == 'top-bottom':
|
if order == 'top-bottom':
|
||||||
return sorted(faces, key = lambda face: face.bounding_box[1])
|
return sorted(faces, key = get_bounding_box_top)
|
||||||
if order == 'bottom-top':
|
if order == 'bottom-top':
|
||||||
return sorted(faces, key = lambda face: face.bounding_box[1], reverse = True)
|
return sorted(faces, key = get_bounding_box_top, reverse = True)
|
||||||
if order == 'small-large':
|
if order == 'small-large':
|
||||||
return sorted(faces, key = lambda face: (face.bounding_box[2] - face.bounding_box[0]) * (face.bounding_box[3] - face.bounding_box[1]))
|
return sorted(faces, key = get_bounding_box_area)
|
||||||
if order == 'large-small':
|
if order == 'large-small':
|
||||||
return sorted(faces, key = lambda face: (face.bounding_box[2] - face.bounding_box[0]) * (face.bounding_box[3] - face.bounding_box[1]), reverse = True)
|
return sorted(faces, key = get_bounding_box_area, reverse = True)
|
||||||
if order == 'best-worst':
|
if order == 'best-worst':
|
||||||
return sorted(faces, key = lambda face: face.score_set.get('detector'), reverse = True)
|
return sorted(faces, key = get_face_detector_score, reverse = True)
|
||||||
if order == 'worst-best':
|
if order == 'worst-best':
|
||||||
return sorted(faces, key = lambda face: face.score_set.get('detector'))
|
return sorted(faces, key = get_face_detector_score)
|
||||||
return faces
|
return faces
|
||||||
|
|
||||||
|
|
||||||
|
def get_bounding_box_left(face : Face) -> float:
|
||||||
|
return face.bounding_box[0]
|
||||||
|
|
||||||
|
|
||||||
|
def get_bounding_box_top(face : Face) -> float:
|
||||||
|
return face.bounding_box[1]
|
||||||
|
|
||||||
|
|
||||||
|
def get_bounding_box_area(face : Face) -> float:
|
||||||
|
return (face.bounding_box[2] - face.bounding_box[0]) * (face.bounding_box[3] - face.bounding_box[1])
|
||||||
|
|
||||||
|
|
||||||
|
def get_face_detector_score(face : Face) -> Score:
|
||||||
|
return face.score_set.get('detector')
|
||||||
|
|
||||||
|
|
||||||
def filter_faces_by_gender(faces : List[Face], gender : Gender) -> List[Face]:
|
def filter_faces_by_gender(faces : List[Face], gender : Gender) -> List[Face]:
|
||||||
filter_faces = []
|
filter_faces = []
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from functools import partial
|
||||||
from typing import List, Optional, cast
|
from typing import List, Optional, cast
|
||||||
|
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
@@ -40,6 +41,10 @@ def run_ffmpeg_with_progress(commands : Commands, update_progress : UpdateProgre
|
|||||||
return process
|
return process
|
||||||
|
|
||||||
|
|
||||||
|
def update_progress(progress : tqdm, frame_number : int):
|
||||||
|
progress.update(frame_number - progress.n)
|
||||||
|
|
||||||
|
|
||||||
def run_ffmpeg(commands : Commands) -> subprocess.Popen[bytes]:
|
def run_ffmpeg(commands : Commands) -> subprocess.Popen[bytes]:
|
||||||
log_level = state_manager.get_item('log_level')
|
log_level = state_manager.get_item('log_level')
|
||||||
commands = ffmpeg_builder.run(commands)
|
commands = ffmpeg_builder.run(commands)
|
||||||
@@ -114,7 +119,7 @@ def extract_frames(target_path : str, temp_video_resolution : str, temp_video_fp
|
|||||||
)
|
)
|
||||||
|
|
||||||
with tqdm(total = extract_frame_total, desc = wording.get('extracting'), unit = 'frame', ascii = ' =', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress:
|
with tqdm(total = extract_frame_total, desc = wording.get('extracting'), unit = 'frame', ascii = ' =', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress:
|
||||||
process = run_ffmpeg_with_progress(commands, lambda frame_number: progress.update(frame_number - progress.n))
|
process = run_ffmpeg_with_progress(commands, partial(update_progress, progress))
|
||||||
return process.returncode == 0
|
return process.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
@@ -230,7 +235,7 @@ def merge_video(target_path : str, temp_video_fps : Fps, output_video_resolution
|
|||||||
)
|
)
|
||||||
|
|
||||||
with tqdm(total = merge_frame_total, desc = wording.get('merging'), unit = 'frame', ascii = ' =', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress:
|
with tqdm(total = merge_frame_total, desc = wording.get('merging'), unit = 'frame', ascii = ' =', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress:
|
||||||
process = run_ffmpeg_with_progress(commands, lambda frame_number: progress.update(frame_number - progress.n))
|
process = run_ffmpeg_with_progress(commands, partial(update_progress, progress))
|
||||||
return process.returncode == 0
|
return process.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import signal
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from argparse import ArgumentParser, HelpFormatter
|
from argparse import ArgumentParser, HelpFormatter
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from facefusion import metadata, wording
|
from facefusion import metadata, wording
|
||||||
from facefusion.common_helper import is_linux, is_windows
|
from facefusion.common_helper import is_linux, is_windows
|
||||||
@@ -14,7 +15,7 @@ ONNXRUNTIME_SET =\
|
|||||||
}
|
}
|
||||||
if is_windows() or is_linux():
|
if is_windows() or is_linux():
|
||||||
ONNXRUNTIME_SET['cuda'] = ('onnxruntime-gpu', '1.22.0')
|
ONNXRUNTIME_SET['cuda'] = ('onnxruntime-gpu', '1.22.0')
|
||||||
ONNXRUNTIME_SET['openvino'] = ('onnxruntime-openvino', '1.21.0')
|
ONNXRUNTIME_SET['openvino'] = ('onnxruntime-openvino', '1.22.0')
|
||||||
if is_windows():
|
if is_windows():
|
||||||
ONNXRUNTIME_SET['directml'] = ('onnxruntime-directml', '1.17.3')
|
ONNXRUNTIME_SET['directml'] = ('onnxruntime-directml', '1.17.3')
|
||||||
if is_linux():
|
if is_linux():
|
||||||
@@ -22,8 +23,8 @@ if is_linux():
|
|||||||
|
|
||||||
|
|
||||||
def cli() -> None:
|
def cli() -> None:
|
||||||
signal.signal(signal.SIGINT, lambda signal_number, frame: sys.exit(0))
|
signal.signal(signal.SIGINT, partial(sys.exit, 0))
|
||||||
program = ArgumentParser(formatter_class = lambda prog: HelpFormatter(prog, max_help_position = 50))
|
program = ArgumentParser(formatter_class = partial(HelpFormatter, max_help_position = 50))
|
||||||
program.add_argument('--onnxruntime', help = wording.get('help.install_dependency').format(dependency = 'onnxruntime'), choices = ONNXRUNTIME_SET.keys(), required = True)
|
program.add_argument('--onnxruntime', help = wording.get('help.install_dependency').format(dependency = 'onnxruntime'), choices = ONNXRUNTIME_SET.keys(), required = True)
|
||||||
program.add_argument('--skip-conda', help = wording.get('help.skip_conda'), action = 'store_true')
|
program.add_argument('--skip-conda', help = wording.get('help.skip_conda'), action = 'store_true')
|
||||||
program.add_argument('-v', '--version', version = metadata.get('name') + ' ' + metadata.get('version'), action = 'version')
|
program.add_argument('-v', '--version', version = metadata.get('name') + ' ' + metadata.get('version'), action = 'version')
|
||||||
|
|||||||
@@ -40,4 +40,10 @@ def update_processors(processors : List[str]) -> gradio.CheckboxGroup:
|
|||||||
|
|
||||||
def sort_processors(processors : List[str]) -> List[str]:
|
def sort_processors(processors : List[str]) -> List[str]:
|
||||||
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
||||||
return sorted(available_processors, key = lambda processor : processors.index(processor) if processor in processors else len(processors))
|
current_processors = []
|
||||||
|
|
||||||
|
for processor in processors + available_processors:
|
||||||
|
if processor in available_processors and processor not in current_processors:
|
||||||
|
current_processors.append(processor)
|
||||||
|
|
||||||
|
return current_processors
|
||||||
|
|||||||
Reference in New Issue
Block a user