mirror of
https://github.com/facefusion/facefusion.git
synced 2026-07-28 21:08:54 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6fb48780c | ||
|
|
0b7349bde0 | ||
|
|
3e563a3eb9 | ||
|
|
1baa134126 | ||
|
|
4e5675aa2c | ||
|
|
162025161a | ||
|
|
5118c7229f | ||
|
|
72a0edb6ba | ||
|
|
84b9b60e6e | ||
|
|
7f4b232a4f | ||
|
|
5ebefb6831 | ||
|
|
b6156f6073 | ||
|
|
ff645b9069 | ||
|
|
106c1f20b3 | ||
|
|
aaebc018ce | ||
|
|
b9356d50db | ||
|
|
b9021a8250 | ||
|
|
5db1e3421c | ||
|
|
bb5504c7a4 | ||
|
|
096d31cad6 | ||
|
|
57ef628138 | ||
|
|
4c09f88b42 | ||
|
|
1c5a2337e8 | ||
|
|
89c0493acd | ||
|
|
b480c76e35 | ||
|
|
3250f39708 | ||
|
|
b4e54e6502 | ||
|
|
671acae887 | ||
|
|
6f62d41595 | ||
|
|
e56eabe981 | ||
|
|
65939b0c79 | ||
|
|
dca3c31e51 | ||
|
|
22b9e89eff | ||
|
|
9d7b69b73d | ||
|
|
bdf068521a | ||
|
|
02d500cdb2 | ||
|
|
a07b77b31a | ||
|
|
d43147ffe9 | ||
|
|
679731c02b | ||
|
|
27f77f92fb | ||
|
|
a91cb9a3ed | ||
|
|
7bdd084c20 | ||
|
|
6c49a9779b | ||
|
|
d459ae981e | ||
|
|
f1a4011254 | ||
|
|
288c66f5c0 | ||
|
|
d56d651568 | ||
|
|
0fdbd167f0 | ||
|
|
1d045028ab | ||
|
|
d03e3b3ed7 | ||
|
|
48aaba2786 | ||
|
|
aa1007ff6a | ||
|
|
2bb91a8098 | ||
|
|
944306a19c | ||
|
|
7dbe17596f | ||
|
|
d43cf5cdde | ||
|
|
c0e856ef72 | ||
|
|
81f34bec2b | ||
|
|
75eba39f95 | ||
|
|
b0f37ba46c | ||
|
|
41514c2d67 | ||
|
|
977d8d91b5 | ||
|
|
c7abeb4785 | ||
|
|
96878917b5 | ||
|
|
f3bbd3e16f | ||
|
|
1bdc02014c | ||
|
|
b438b899e8 | ||
|
|
858acd2fe3 | ||
|
|
5e3ab88f63 | ||
|
|
7ceb3389dc | ||
|
|
44165eb0b7 | ||
|
|
997649ed4a | ||
|
|
c25f046c2b | ||
|
|
359dddc121 | ||
|
|
c9296de559 | ||
|
|
e47140ea27 | ||
|
|
616914d38f | ||
|
|
6cc21d7a91 | ||
|
|
6732a82af4 | ||
|
|
51a809310e | ||
|
|
ddd83d0606 | ||
|
|
296eea8577 | ||
|
|
efc9652df4 | ||
|
|
2fc4d2b02e | ||
|
|
c70b45bd39 | ||
|
|
e79a99fac4 | ||
|
|
5dc986d6b2 | ||
|
|
2892dd484d | ||
|
|
1eed88b0f5 | ||
|
|
c363faa757 | ||
|
|
cd6d2012f6 | ||
|
|
1c06023160 | ||
|
|
2e16b10200 | ||
|
|
5f82c8dc7d | ||
|
|
d260c28cf3 | ||
|
|
30d9b038e4 | ||
|
|
02d11435a6 | ||
|
|
b9eb6a7cc0 | ||
|
|
4f32ed7868 | ||
|
|
0e6ee69c53 | ||
|
|
87e3a80491 | ||
|
|
dbbf3445b6 | ||
|
|
5270bd679c | ||
|
|
0ecebc8c82 | ||
|
|
f4255e66fa | ||
|
|
a45754892d | ||
|
|
9dd397579c | ||
|
|
bedd75920d | ||
|
|
3a437fdc92 | ||
|
|
3b80d66bf4 | ||
|
|
330f86a4e4 | ||
|
|
2f66bde116 | ||
|
|
01fff3c419 | ||
|
|
e5278996d1 | ||
|
|
faf5020051 | ||
|
|
732f096da0 | ||
|
|
2d95e409cb | ||
|
|
0553ef4766 | ||
|
|
ed8e25dbb2 | ||
|
|
b11cb07aea | ||
|
|
964fab8724 | ||
|
|
9d9805a03b | ||
|
|
169d578a14 | ||
|
|
63de6a8d8a | ||
|
|
56ba551630 | ||
|
|
b8ebcf9fe3 | ||
|
|
8a9e08f3a2 | ||
|
|
7f90ca72bb | ||
|
|
71092cb951 | ||
|
|
fbe2e57da6 | ||
|
|
99c514c58f | ||
|
|
36ddef4ba1 | ||
|
|
5b76f54332 | ||
|
|
c5bc7c50a5 | ||
|
|
87350eb45f | ||
|
|
6f0675030e | ||
|
|
bb32135af2 | ||
|
|
749abc3406 | ||
|
|
612fd70e54 | ||
|
|
eb2f794ece | ||
|
|
efc49c367a | ||
|
|
d4fba8421f | ||
|
|
1e3bab9644 | ||
|
|
197773c346 | ||
|
|
8656411336 | ||
|
|
8efd7c1fa0 | ||
|
|
b48eac30d0 | ||
|
|
befd75421f | ||
|
|
9d9ebac758 | ||
|
|
9f6000d20f | ||
|
|
d14a75c223 | ||
|
|
a55e0085f7 | ||
|
|
91e4616fe1 | ||
|
|
7a09479fb5 | ||
|
|
ec12f679bf |
@@ -1,5 +1,5 @@
|
|||||||
[flake8]
|
[flake8]
|
||||||
select = E3, E4, F, I1, I2
|
select = E22, E23, E24, E27, E3, E4, E7, F, I1, I2
|
||||||
per-file-ignores = facefusion.py:E402, install.py:E402
|
per-file-ignores = facefusion.py:E402, install.py:E402
|
||||||
plugins = flake8-import-order
|
plugins = flake8-import-order
|
||||||
application_import_names = facefusion
|
application_import_names = facefusion
|
||||||
|
|||||||
+1
-2
@@ -1,2 +1 @@
|
|||||||
github: henryruhs
|
custom: [ buymeacoffee.com/facefusion, ko-fi.com/facefusion ]
|
||||||
custom: [ buymeacoffee.com/henryruhs, paypal.me/henryruhs ]
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.3 MiB |
@@ -8,10 +8,10 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Set up Python 3.10
|
- name: Set up Python 3.12
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.10'
|
python-version: '3.12'
|
||||||
- run: pip install flake8
|
- run: pip install flake8
|
||||||
- run: pip install flake8-import-order
|
- run: pip install flake8-import-order
|
||||||
- run: pip install mypy
|
- run: pip install mypy
|
||||||
@@ -22,17 +22,17 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ macos-13, ubuntu-latest, windows-latest ]
|
os: [ macos-latest, ubuntu-latest, windows-latest ]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Set up FFmpeg
|
- name: Set up FFmpeg
|
||||||
uses: FedericoCarboni/setup-ffmpeg@v3
|
uses: AnimMouse/setup-ffmpeg@v1
|
||||||
- name: Set up Python 3.10
|
- name: Set up Python 3.12
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.10'
|
python-version: '3.12'
|
||||||
- run: python install.py --onnxruntime default --skip-conda
|
- run: python install.py --onnxruntime default --skip-conda
|
||||||
- run: pip install pytest
|
- run: pip install pytest
|
||||||
- run: pytest
|
- run: pytest
|
||||||
@@ -44,10 +44,10 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Set up FFmpeg
|
- name: Set up FFmpeg
|
||||||
uses: FedericoCarboni/setup-ffmpeg@v3
|
uses: FedericoCarboni/setup-ffmpeg@v3
|
||||||
- name: Set up Python 3.10
|
- name: Set up Python 3.12
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.10'
|
python-version: '3.12'
|
||||||
- run: python install.py --onnxruntime default --skip-conda
|
- run: python install.py --onnxruntime default --skip-conda
|
||||||
- run: pip install coveralls
|
- run: pip install coveralls
|
||||||
- run: pip install pytest
|
- run: pip install pytest
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
__pycache__
|
||||||
.assets
|
.assets
|
||||||
.caches
|
.caches
|
||||||
.jobs
|
.jobs
|
||||||
|
|||||||
+2
-2
@@ -1,3 +1,3 @@
|
|||||||
MIT license
|
OpenRAIL-AS license
|
||||||
|
|
||||||
Copyright (c) 2024 Henry Ruhs
|
Copyright (c) 2025 Henry Ruhs
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ FaceFusion
|
|||||||
|
|
||||||
[](https://github.com/facefusion/facefusion/actions?query=workflow:ci)
|
[](https://github.com/facefusion/facefusion/actions?query=workflow:ci)
|
||||||
[](https://coveralls.io/r/facefusion/facefusion)
|
[](https://coveralls.io/r/facefusion/facefusion)
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
Preview
|
Preview
|
||||||
@@ -17,7 +17,7 @@ Preview
|
|||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Be aware, the [installation](https://docs.facefusion.io/installation) needs technical skills and is not recommended for beginners. In case you are not comfortable using a terminal, our [Windows Installer](https://windows-installer.facefusion.io) and [macOS Installer](https://macos-installer.facefusion.io) get you started.
|
Be aware, the [installation](https://docs.facefusion.io/installation) needs technical skills and is not recommended for beginners. In case you are not comfortable using a terminal, our [Windows Installer](http://windows-installer.facefusion.io) and [macOS Installer](http://macos-installer.facefusion.io) get you started.
|
||||||
|
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
@@ -35,6 +35,7 @@ options:
|
|||||||
commands:
|
commands:
|
||||||
run run the program
|
run run the program
|
||||||
headless-run run the program in headless mode
|
headless-run run the program in headless mode
|
||||||
|
batch-run run the program in batch mode
|
||||||
force-download force automate downloads and exit
|
force-download force automate downloads and exit
|
||||||
job-list list jobs by status
|
job-list list jobs by status
|
||||||
job-create create a drafted job
|
job-create create a drafted job
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 20 KiB |
+18
-2
@@ -1,9 +1,15 @@
|
|||||||
[paths]
|
[paths]
|
||||||
|
temp_path =
|
||||||
jobs_path =
|
jobs_path =
|
||||||
source_paths =
|
source_paths =
|
||||||
target_path =
|
target_path =
|
||||||
output_path =
|
output_path =
|
||||||
|
|
||||||
|
[patterns]
|
||||||
|
source_pattern =
|
||||||
|
target_pattern =
|
||||||
|
output_pattern =
|
||||||
|
|
||||||
[face_detector]
|
[face_detector]
|
||||||
face_detector_model =
|
face_detector_model =
|
||||||
face_detector_size =
|
face_detector_size =
|
||||||
@@ -26,6 +32,8 @@ reference_face_distance =
|
|||||||
reference_frame_number =
|
reference_frame_number =
|
||||||
|
|
||||||
[face_masker]
|
[face_masker]
|
||||||
|
face_occluder_model =
|
||||||
|
face_parser_model =
|
||||||
face_mask_types =
|
face_mask_types =
|
||||||
face_mask_blur =
|
face_mask_blur =
|
||||||
face_mask_padding =
|
face_mask_padding =
|
||||||
@@ -41,17 +49,20 @@ keep_temp =
|
|||||||
output_image_quality =
|
output_image_quality =
|
||||||
output_image_resolution =
|
output_image_resolution =
|
||||||
output_audio_encoder =
|
output_audio_encoder =
|
||||||
|
output_audio_quality =
|
||||||
|
output_audio_volume =
|
||||||
output_video_encoder =
|
output_video_encoder =
|
||||||
output_video_preset =
|
output_video_preset =
|
||||||
output_video_quality =
|
output_video_quality =
|
||||||
output_video_resolution =
|
output_video_resolution =
|
||||||
output_video_fps =
|
output_video_fps =
|
||||||
skip_audio =
|
|
||||||
|
|
||||||
[processors]
|
[processors]
|
||||||
processors =
|
processors =
|
||||||
age_modifier_model =
|
age_modifier_model =
|
||||||
age_modifier_direction =
|
age_modifier_direction =
|
||||||
|
deep_swapper_model =
|
||||||
|
deep_swapper_morph =
|
||||||
expression_restorer_model =
|
expression_restorer_model =
|
||||||
expression_restorer_factor =
|
expression_restorer_factor =
|
||||||
face_debugger_items =
|
face_debugger_items =
|
||||||
@@ -72,6 +83,7 @@ face_editor_head_yaw =
|
|||||||
face_editor_head_roll =
|
face_editor_head_roll =
|
||||||
face_enhancer_model =
|
face_enhancer_model =
|
||||||
face_enhancer_blend =
|
face_enhancer_blend =
|
||||||
|
face_enhancer_weight =
|
||||||
face_swapper_model =
|
face_swapper_model =
|
||||||
face_swapper_pixel_boost =
|
face_swapper_pixel_boost =
|
||||||
frame_colorizer_model =
|
frame_colorizer_model =
|
||||||
@@ -92,10 +104,14 @@ execution_providers =
|
|||||||
execution_thread_count =
|
execution_thread_count =
|
||||||
execution_queue_count =
|
execution_queue_count =
|
||||||
|
|
||||||
|
[download]
|
||||||
|
download_providers =
|
||||||
|
download_scope =
|
||||||
|
|
||||||
[memory]
|
[memory]
|
||||||
video_memory_strategy =
|
video_memory_strategy =
|
||||||
system_memory_limit =
|
system_memory_limit =
|
||||||
|
|
||||||
[misc]
|
[misc]
|
||||||
skip_download =
|
|
||||||
log_level =
|
log_level =
|
||||||
|
halt_on_error =
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from facefusion.typing import AppContext
|
from facefusion.types import AppContext
|
||||||
|
|
||||||
|
|
||||||
def detect_app_context() -> AppContext:
|
def detect_app_context() -> AppContext:
|
||||||
|
|||||||
+33
-14
@@ -1,9 +1,9 @@
|
|||||||
from facefusion import state_manager
|
from facefusion import state_manager
|
||||||
from facefusion.filesystem import is_image, is_video, list_directory
|
from facefusion.filesystem import get_file_name, is_image, is_video, resolve_file_paths
|
||||||
from facefusion.jobs import job_store
|
from facefusion.jobs import job_store
|
||||||
from facefusion.normalizer import normalize_fps, normalize_padding
|
from facefusion.normalizer import normalize_fps, normalize_padding
|
||||||
from facefusion.processors.core import get_processors_modules
|
from facefusion.processors.core import get_processors_modules
|
||||||
from facefusion.typing import ApplyStateItem, Args
|
from facefusion.types import ApplyStateItem, Args
|
||||||
from facefusion.vision import create_image_resolutions, create_video_resolutions, detect_image_resolution, detect_video_fps, detect_video_resolution, pack_resolution
|
from facefusion.vision import create_image_resolutions, create_video_resolutions, detect_image_resolution, detect_video_fps, detect_video_resolution, pack_resolution
|
||||||
|
|
||||||
|
|
||||||
@@ -15,6 +15,14 @@ def reduce_step_args(args : Args) -> Args:
|
|||||||
return step_args
|
return step_args
|
||||||
|
|
||||||
|
|
||||||
|
def reduce_job_args(args : Args) -> Args:
|
||||||
|
job_args =\
|
||||||
|
{
|
||||||
|
key: args[key] for key in args if key in job_store.get_job_keys()
|
||||||
|
}
|
||||||
|
return job_args
|
||||||
|
|
||||||
|
|
||||||
def collect_step_args() -> Args:
|
def collect_step_args() -> Args:
|
||||||
step_args =\
|
step_args =\
|
||||||
{
|
{
|
||||||
@@ -35,10 +43,15 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
# general
|
# general
|
||||||
apply_state_item('command', args.get('command'))
|
apply_state_item('command', args.get('command'))
|
||||||
# paths
|
# paths
|
||||||
|
apply_state_item('temp_path', args.get('temp_path'))
|
||||||
apply_state_item('jobs_path', args.get('jobs_path'))
|
apply_state_item('jobs_path', args.get('jobs_path'))
|
||||||
apply_state_item('source_paths', args.get('source_paths'))
|
apply_state_item('source_paths', args.get('source_paths'))
|
||||||
apply_state_item('target_path', args.get('target_path'))
|
apply_state_item('target_path', args.get('target_path'))
|
||||||
apply_state_item('output_path', args.get('output_path'))
|
apply_state_item('output_path', args.get('output_path'))
|
||||||
|
# patterns
|
||||||
|
apply_state_item('source_pattern', args.get('source_pattern'))
|
||||||
|
apply_state_item('target_pattern', args.get('target_pattern'))
|
||||||
|
apply_state_item('output_pattern', args.get('output_pattern'))
|
||||||
# face detector
|
# face detector
|
||||||
apply_state_item('face_detector_model', args.get('face_detector_model'))
|
apply_state_item('face_detector_model', args.get('face_detector_model'))
|
||||||
apply_state_item('face_detector_size', args.get('face_detector_size'))
|
apply_state_item('face_detector_size', args.get('face_detector_size'))
|
||||||
@@ -48,16 +61,18 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
apply_state_item('face_landmarker_model', args.get('face_landmarker_model'))
|
apply_state_item('face_landmarker_model', args.get('face_landmarker_model'))
|
||||||
apply_state_item('face_landmarker_score', args.get('face_landmarker_score'))
|
apply_state_item('face_landmarker_score', args.get('face_landmarker_score'))
|
||||||
# face selector
|
# face selector
|
||||||
state_manager.init_item('face_selector_mode', args.get('face_selector_mode'))
|
apply_state_item('face_selector_mode', args.get('face_selector_mode'))
|
||||||
state_manager.init_item('face_selector_order', args.get('face_selector_order'))
|
apply_state_item('face_selector_order', args.get('face_selector_order'))
|
||||||
state_manager.init_item('face_selector_age_start', args.get('face_selector_age_start'))
|
apply_state_item('face_selector_age_start', args.get('face_selector_age_start'))
|
||||||
state_manager.init_item('face_selector_age_end', args.get('face_selector_age_end'))
|
apply_state_item('face_selector_age_end', args.get('face_selector_age_end'))
|
||||||
state_manager.init_item('face_selector_gender', args.get('face_selector_gender'))
|
apply_state_item('face_selector_gender', args.get('face_selector_gender'))
|
||||||
state_manager.init_item('face_selector_race', args.get('face_selector_race'))
|
apply_state_item('face_selector_race', args.get('face_selector_race'))
|
||||||
state_manager.init_item('reference_face_position', args.get('reference_face_position'))
|
apply_state_item('reference_face_position', args.get('reference_face_position'))
|
||||||
state_manager.init_item('reference_face_distance', args.get('reference_face_distance'))
|
apply_state_item('reference_face_distance', args.get('reference_face_distance'))
|
||||||
state_manager.init_item('reference_frame_number', args.get('reference_frame_number'))
|
apply_state_item('reference_frame_number', args.get('reference_frame_number'))
|
||||||
# face masker
|
# face masker
|
||||||
|
apply_state_item('face_occluder_model', args.get('face_occluder_model'))
|
||||||
|
apply_state_item('face_parser_model', args.get('face_parser_model'))
|
||||||
apply_state_item('face_mask_types', args.get('face_mask_types'))
|
apply_state_item('face_mask_types', args.get('face_mask_types'))
|
||||||
apply_state_item('face_mask_blur', args.get('face_mask_blur'))
|
apply_state_item('face_mask_blur', args.get('face_mask_blur'))
|
||||||
apply_state_item('face_mask_padding', normalize_padding(args.get('face_mask_padding')))
|
apply_state_item('face_mask_padding', normalize_padding(args.get('face_mask_padding')))
|
||||||
@@ -77,6 +92,8 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
else:
|
else:
|
||||||
apply_state_item('output_image_resolution', pack_resolution(output_image_resolution))
|
apply_state_item('output_image_resolution', pack_resolution(output_image_resolution))
|
||||||
apply_state_item('output_audio_encoder', args.get('output_audio_encoder'))
|
apply_state_item('output_audio_encoder', args.get('output_audio_encoder'))
|
||||||
|
apply_state_item('output_audio_quality', args.get('output_audio_quality'))
|
||||||
|
apply_state_item('output_audio_volume', args.get('output_audio_volume'))
|
||||||
apply_state_item('output_video_encoder', args.get('output_video_encoder'))
|
apply_state_item('output_video_encoder', args.get('output_video_encoder'))
|
||||||
apply_state_item('output_video_preset', args.get('output_video_preset'))
|
apply_state_item('output_video_preset', args.get('output_video_preset'))
|
||||||
apply_state_item('output_video_quality', args.get('output_video_quality'))
|
apply_state_item('output_video_quality', args.get('output_video_quality'))
|
||||||
@@ -90,9 +107,8 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
if args.get('output_video_fps') or is_video(args.get('target_path')):
|
if args.get('output_video_fps') or is_video(args.get('target_path')):
|
||||||
output_video_fps = normalize_fps(args.get('output_video_fps')) or detect_video_fps(args.get('target_path'))
|
output_video_fps = normalize_fps(args.get('output_video_fps')) or detect_video_fps(args.get('target_path'))
|
||||||
apply_state_item('output_video_fps', output_video_fps)
|
apply_state_item('output_video_fps', output_video_fps)
|
||||||
apply_state_item('skip_audio', args.get('skip_audio'))
|
|
||||||
# processors
|
# processors
|
||||||
available_processors = list_directory('facefusion/processors/modules')
|
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
||||||
apply_state_item('processors', args.get('processors'))
|
apply_state_item('processors', args.get('processors'))
|
||||||
for processor_module in get_processors_modules(available_processors):
|
for processor_module in get_processors_modules(available_processors):
|
||||||
processor_module.apply_args(args, apply_state_item)
|
processor_module.apply_args(args, apply_state_item)
|
||||||
@@ -105,12 +121,15 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
apply_state_item('execution_providers', args.get('execution_providers'))
|
apply_state_item('execution_providers', args.get('execution_providers'))
|
||||||
apply_state_item('execution_thread_count', args.get('execution_thread_count'))
|
apply_state_item('execution_thread_count', args.get('execution_thread_count'))
|
||||||
apply_state_item('execution_queue_count', args.get('execution_queue_count'))
|
apply_state_item('execution_queue_count', args.get('execution_queue_count'))
|
||||||
|
# download
|
||||||
|
apply_state_item('download_providers', args.get('download_providers'))
|
||||||
|
apply_state_item('download_scope', args.get('download_scope'))
|
||||||
# memory
|
# memory
|
||||||
apply_state_item('video_memory_strategy', args.get('video_memory_strategy'))
|
apply_state_item('video_memory_strategy', args.get('video_memory_strategy'))
|
||||||
apply_state_item('system_memory_limit', args.get('system_memory_limit'))
|
apply_state_item('system_memory_limit', args.get('system_memory_limit'))
|
||||||
# misc
|
# misc
|
||||||
apply_state_item('skip_download', args.get('skip_download'))
|
|
||||||
apply_state_item('log_level', args.get('log_level'))
|
apply_state_item('log_level', args.get('log_level'))
|
||||||
|
apply_state_item('halt_on_error', args.get('halt_on_error'))
|
||||||
# jobs
|
# jobs
|
||||||
apply_state_item('job_id', args.get('job_id'))
|
apply_state_item('job_id', args.get('job_id'))
|
||||||
apply_state_item('job_status', args.get('job_status'))
|
apply_state_item('job_status', args.get('job_status'))
|
||||||
|
|||||||
+41
-37
@@ -3,25 +3,26 @@ from typing import Any, List, Optional
|
|||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
import scipy
|
import scipy
|
||||||
from numpy._typing import NDArray
|
from numpy.typing import NDArray
|
||||||
|
|
||||||
from facefusion.ffmpeg import read_audio_buffer
|
from facefusion.ffmpeg import read_audio_buffer
|
||||||
from facefusion.filesystem import is_audio
|
from facefusion.filesystem import is_audio
|
||||||
from facefusion.typing import Audio, AudioFrame, Fps, Mel, MelFilterBank, Spectrogram
|
from facefusion.types import Audio, AudioFrame, Fps, Mel, MelFilterBank, Spectrogram
|
||||||
from facefusion.voice_extractor import batch_extract_voice
|
from facefusion.voice_extractor import batch_extract_voice
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize = 128)
|
@lru_cache()
|
||||||
def read_static_audio(audio_path : str, fps : Fps) -> Optional[List[AudioFrame]]:
|
def read_static_audio(audio_path : str, fps : Fps) -> Optional[List[AudioFrame]]:
|
||||||
return read_audio(audio_path, fps)
|
return read_audio(audio_path, fps)
|
||||||
|
|
||||||
|
|
||||||
def read_audio(audio_path : str, fps : Fps) -> Optional[List[AudioFrame]]:
|
def read_audio(audio_path : str, fps : Fps) -> Optional[List[AudioFrame]]:
|
||||||
sample_rate = 48000
|
audio_sample_rate = 48000
|
||||||
channel_total = 2
|
audio_sample_size = 16
|
||||||
|
audio_channel_total = 2
|
||||||
|
|
||||||
if is_audio(audio_path):
|
if is_audio(audio_path):
|
||||||
audio_buffer = read_audio_buffer(audio_path, sample_rate, channel_total)
|
audio_buffer = read_audio_buffer(audio_path, audio_sample_rate, audio_sample_size, audio_channel_total)
|
||||||
audio = numpy.frombuffer(audio_buffer, dtype = numpy.int16).reshape(-1, 2)
|
audio = numpy.frombuffer(audio_buffer, dtype = numpy.int16).reshape(-1, 2)
|
||||||
audio = prepare_audio(audio)
|
audio = prepare_audio(audio)
|
||||||
spectrogram = create_spectrogram(audio)
|
spectrogram = create_spectrogram(audio)
|
||||||
@@ -30,21 +31,22 @@ def read_audio(audio_path : str, fps : Fps) -> Optional[List[AudioFrame]]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize = 128)
|
@lru_cache()
|
||||||
def read_static_voice(audio_path : str, fps : Fps) -> Optional[List[AudioFrame]]:
|
def read_static_voice(audio_path : str, fps : Fps) -> Optional[List[AudioFrame]]:
|
||||||
return read_voice(audio_path, fps)
|
return read_voice(audio_path, fps)
|
||||||
|
|
||||||
|
|
||||||
def read_voice(audio_path : str, fps : Fps) -> Optional[List[AudioFrame]]:
|
def read_voice(audio_path : str, fps : Fps) -> Optional[List[AudioFrame]]:
|
||||||
sample_rate = 48000
|
voice_sample_rate = 48000
|
||||||
channel_total = 2
|
voice_sample_size = 16
|
||||||
chunk_size = 240 * 1024
|
voice_channel_total = 2
|
||||||
step_size = 180 * 1024
|
voice_chunk_size = 240 * 1024
|
||||||
|
voice_step_size = 180 * 1024
|
||||||
|
|
||||||
if is_audio(audio_path):
|
if is_audio(audio_path):
|
||||||
audio_buffer = read_audio_buffer(audio_path, sample_rate, channel_total)
|
audio_buffer = read_audio_buffer(audio_path, voice_sample_rate, voice_sample_size, voice_channel_total)
|
||||||
audio = numpy.frombuffer(audio_buffer, dtype = numpy.int16).reshape(-1, 2)
|
audio = numpy.frombuffer(audio_buffer, dtype = numpy.int16).reshape(-1, 2)
|
||||||
audio = batch_extract_voice(audio, chunk_size, step_size)
|
audio = batch_extract_voice(audio, voice_chunk_size, voice_step_size)
|
||||||
audio = prepare_voice(audio)
|
audio = prepare_voice(audio)
|
||||||
spectrogram = create_spectrogram(audio)
|
spectrogram = create_spectrogram(audio)
|
||||||
audio_frames = extract_audio_frames(spectrogram, fps)
|
audio_frames = extract_audio_frames(spectrogram, fps)
|
||||||
@@ -60,6 +62,20 @@ def get_audio_frame(audio_path : str, fps : Fps, frame_number : int = 0) -> Opti
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def extract_audio_frames(spectrogram: Spectrogram, fps: Fps) -> List[AudioFrame]:
|
||||||
|
audio_frames = []
|
||||||
|
mel_filter_total = 80
|
||||||
|
audio_step_size = 16
|
||||||
|
indices = numpy.arange(0, spectrogram.shape[1], mel_filter_total / fps).astype(numpy.int16)
|
||||||
|
indices = indices[indices >= audio_step_size]
|
||||||
|
|
||||||
|
for index in indices:
|
||||||
|
start = max(0, index - audio_step_size)
|
||||||
|
audio_frames.append(spectrogram[:, start:index])
|
||||||
|
|
||||||
|
return audio_frames
|
||||||
|
|
||||||
|
|
||||||
def get_voice_frame(audio_path : str, fps : Fps, frame_number : int = 0) -> Optional[AudioFrame]:
|
def get_voice_frame(audio_path : str, fps : Fps, frame_number : int = 0) -> Optional[AudioFrame]:
|
||||||
if is_audio(audio_path):
|
if is_audio(audio_path):
|
||||||
voice_frames = read_static_voice(audio_path, fps)
|
voice_frames = read_static_voice(audio_path, fps)
|
||||||
@@ -70,8 +86,8 @@ def get_voice_frame(audio_path : str, fps : Fps, frame_number : int = 0) -> Opti
|
|||||||
|
|
||||||
def create_empty_audio_frame() -> AudioFrame:
|
def create_empty_audio_frame() -> AudioFrame:
|
||||||
mel_filter_total = 80
|
mel_filter_total = 80
|
||||||
step_size = 16
|
audio_step_size = 16
|
||||||
audio_frame = numpy.zeros((mel_filter_total, step_size)).astype(numpy.int16)
|
audio_frame = numpy.zeros((mel_filter_total, audio_step_size)).astype(numpy.int16)
|
||||||
return audio_frame
|
return audio_frame
|
||||||
|
|
||||||
|
|
||||||
@@ -84,10 +100,10 @@ def prepare_audio(audio : Audio) -> Audio:
|
|||||||
|
|
||||||
|
|
||||||
def prepare_voice(audio : Audio) -> Audio:
|
def prepare_voice(audio : Audio) -> Audio:
|
||||||
sample_rate = 48000
|
audio_sample_rate = 48000
|
||||||
resample_rate = 16000
|
audio_resample_rate = 16000
|
||||||
|
audio_resample_factor = round(len(audio) * audio_resample_rate / audio_sample_rate)
|
||||||
audio = scipy.signal.resample(audio, int(len(audio) * resample_rate / sample_rate))
|
audio = scipy.signal.resample(audio, audio_resample_factor)
|
||||||
audio = prepare_audio(audio)
|
audio = prepare_audio(audio)
|
||||||
return audio
|
return audio
|
||||||
|
|
||||||
@@ -101,19 +117,20 @@ def convert_mel_to_hertz(mel : Mel) -> NDArray[Any]:
|
|||||||
|
|
||||||
|
|
||||||
def create_mel_filter_bank() -> MelFilterBank:
|
def create_mel_filter_bank() -> MelFilterBank:
|
||||||
|
audio_sample_rate = 16000
|
||||||
|
audio_min_frequency = 55.0
|
||||||
|
audio_max_frequency = 7600.0
|
||||||
mel_filter_total = 80
|
mel_filter_total = 80
|
||||||
mel_bin_total = 800
|
mel_bin_total = 800
|
||||||
sample_rate = 16000
|
|
||||||
min_frequency = 55.0
|
|
||||||
max_frequency = 7600.0
|
|
||||||
mel_filter_bank = numpy.zeros((mel_filter_total, mel_bin_total // 2 + 1))
|
mel_filter_bank = numpy.zeros((mel_filter_total, mel_bin_total // 2 + 1))
|
||||||
mel_frequency_range = numpy.linspace(convert_hertz_to_mel(min_frequency), convert_hertz_to_mel(max_frequency), mel_filter_total + 2)
|
mel_frequency_range = numpy.linspace(convert_hertz_to_mel(audio_min_frequency), convert_hertz_to_mel(audio_max_frequency), mel_filter_total + 2)
|
||||||
indices = numpy.floor((mel_bin_total + 1) * convert_mel_to_hertz(mel_frequency_range) / sample_rate).astype(numpy.int16)
|
indices = numpy.floor((mel_bin_total + 1) * convert_mel_to_hertz(mel_frequency_range) / audio_sample_rate).astype(numpy.int16)
|
||||||
|
|
||||||
for index in range(mel_filter_total):
|
for index in range(mel_filter_total):
|
||||||
start = indices[index]
|
start = indices[index]
|
||||||
end = indices[index + 1]
|
end = indices[index + 1]
|
||||||
mel_filter_bank[index, start:end] = scipy.signal.windows.triang(end - start)
|
mel_filter_bank[index, start:end] = scipy.signal.windows.triang(end - start)
|
||||||
|
|
||||||
return mel_filter_bank
|
return mel_filter_bank
|
||||||
|
|
||||||
|
|
||||||
@@ -124,16 +141,3 @@ def create_spectrogram(audio : Audio) -> Spectrogram:
|
|||||||
spectrogram = scipy.signal.stft(audio, nperseg = mel_bin_total, nfft = mel_bin_total, noverlap = mel_bin_overlap)[2]
|
spectrogram = scipy.signal.stft(audio, nperseg = mel_bin_total, nfft = mel_bin_total, noverlap = mel_bin_overlap)[2]
|
||||||
spectrogram = numpy.dot(mel_filter_bank, numpy.abs(spectrogram))
|
spectrogram = numpy.dot(mel_filter_bank, numpy.abs(spectrogram))
|
||||||
return spectrogram
|
return spectrogram
|
||||||
|
|
||||||
|
|
||||||
def extract_audio_frames(spectrogram : Spectrogram, fps : Fps) -> List[AudioFrame]:
|
|
||||||
mel_filter_total = 80
|
|
||||||
step_size = 16
|
|
||||||
audio_frames = []
|
|
||||||
indices = numpy.arange(0, spectrogram.shape[1], mel_filter_total / fps).astype(numpy.int16)
|
|
||||||
indices = indices[indices >= step_size]
|
|
||||||
|
|
||||||
for index in indices:
|
|
||||||
start = max(0, index - step_size)
|
|
||||||
audio_frames.append(spectrogram[:, start:index])
|
|
||||||
return audio_frames
|
|
||||||
|
|||||||
+104
-23
@@ -2,32 +2,121 @@ import logging
|
|||||||
from typing import List, Sequence
|
from typing import List, Sequence
|
||||||
|
|
||||||
from facefusion.common_helper import create_float_range, create_int_range
|
from facefusion.common_helper import create_float_range, create_int_range
|
||||||
from facefusion.typing import Angle, ExecutionProviderSet, FaceDetectorSet, FaceLandmarkerModel, FaceMaskRegion, FaceMaskType, FaceSelectorMode, FaceSelectorOrder, Gender, JobStatus, LogLevelSet, OutputAudioEncoder, OutputVideoEncoder, OutputVideoPreset, Race, Score, TempFrameFormat, UiWorkflow, VideoMemoryStrategy
|
from facefusion.types import Angle, AudioEncoder, AudioFormat, AudioTypeSet, DownloadProvider, DownloadProviderSet, DownloadScope, EncoderSet, ExecutionProvider, ExecutionProviderSet, FaceDetectorModel, FaceDetectorSet, FaceLandmarkerModel, FaceMaskRegion, FaceMaskRegionSet, FaceMaskType, FaceOccluderModel, FaceParserModel, FaceSelectorMode, FaceSelectorOrder, Gender, ImageFormat, ImageTypeSet, JobStatus, LogLevel, LogLevelSet, Race, Score, TempFrameFormat, UiWorkflow, VideoEncoder, VideoFormat, VideoMemoryStrategy, VideoPreset, VideoTypeSet, WebcamMode
|
||||||
|
|
||||||
video_memory_strategies : List[VideoMemoryStrategy] = [ 'strict', 'moderate', 'tolerant' ]
|
|
||||||
|
|
||||||
face_detector_set : FaceDetectorSet =\
|
face_detector_set : FaceDetectorSet =\
|
||||||
{
|
{
|
||||||
'many': [ '640x640' ],
|
'many': [ '640x640' ],
|
||||||
'retinaface': [ '160x160', '320x320', '480x480', '512x512', '640x640' ],
|
'retinaface': [ '160x160', '320x320', '480x480', '512x512', '640x640' ],
|
||||||
'scrfd': [ '160x160', '320x320', '480x480', '512x512', '640x640' ],
|
'scrfd': [ '160x160', '320x320', '480x480', '512x512', '640x640' ],
|
||||||
'yoloface': [ '640x640' ]
|
'yolo_face': [ '640x640' ]
|
||||||
}
|
}
|
||||||
|
face_detector_models : List[FaceDetectorModel] = list(face_detector_set.keys())
|
||||||
face_landmarker_models : List[FaceLandmarkerModel] = [ 'many', '2dfan4', 'peppa_wutz' ]
|
face_landmarker_models : List[FaceLandmarkerModel] = [ 'many', '2dfan4', 'peppa_wutz' ]
|
||||||
face_selector_modes : List[FaceSelectorMode] = [ 'many', 'one', 'reference' ]
|
face_selector_modes : List[FaceSelectorMode] = [ 'many', 'one', 'reference' ]
|
||||||
face_selector_orders : List[FaceSelectorOrder] = [ 'left-right', 'right-left', 'top-bottom', 'bottom-top', 'small-large', 'large-small', 'best-worst', 'worst-best' ]
|
face_selector_orders : List[FaceSelectorOrder] = [ 'left-right', 'right-left', 'top-bottom', 'bottom-top', 'small-large', 'large-small', 'best-worst', 'worst-best' ]
|
||||||
face_selector_genders : List[Gender] = ['female', 'male']
|
face_selector_genders : List[Gender] = [ 'female', 'male' ]
|
||||||
face_selector_races : List[Race] = ['white', 'black', 'latino', 'asian', 'indian', 'arabic']
|
face_selector_races : List[Race] = [ 'white', 'black', 'latino', 'asian', 'indian', 'arabic' ]
|
||||||
|
face_occluder_models : List[FaceOccluderModel] = [ 'xseg_1', 'xseg_2', 'xseg_3' ]
|
||||||
|
face_parser_models : List[FaceParserModel] = [ 'bisenet_resnet_18', 'bisenet_resnet_34' ]
|
||||||
face_mask_types : List[FaceMaskType] = [ 'box', 'occlusion', 'region' ]
|
face_mask_types : List[FaceMaskType] = [ 'box', 'occlusion', 'region' ]
|
||||||
face_mask_regions : List[FaceMaskRegion] = [ 'skin', 'left-eyebrow', 'right-eyebrow', 'left-eye', 'right-eye', 'glasses', 'nose', 'mouth', 'upper-lip', 'lower-lip' ]
|
face_mask_region_set : FaceMaskRegionSet =\
|
||||||
temp_frame_formats : List[TempFrameFormat] = [ 'bmp', 'jpg', 'png' ]
|
{
|
||||||
output_audio_encoders : List[OutputAudioEncoder] = [ 'aac', 'libmp3lame', 'libopus', 'libvorbis' ]
|
'skin': 1,
|
||||||
output_video_encoders : List[OutputVideoEncoder] = [ 'libx264', 'libx265', 'libvpx-vp9', 'h264_nvenc', 'hevc_nvenc', 'h264_amf', 'hevc_amf', 'h264_videotoolbox', 'hevc_videotoolbox' ]
|
'left-eyebrow': 2,
|
||||||
output_video_presets : List[OutputVideoPreset] = [ 'ultrafast', 'superfast', 'veryfast', 'faster', 'fast', 'medium', 'slow', 'slower', 'veryslow' ]
|
'right-eyebrow': 3,
|
||||||
|
'left-eye': 4,
|
||||||
|
'right-eye': 5,
|
||||||
|
'glasses': 6,
|
||||||
|
'nose': 10,
|
||||||
|
'mouth': 11,
|
||||||
|
'upper-lip': 12,
|
||||||
|
'lower-lip': 13
|
||||||
|
}
|
||||||
|
face_mask_regions : List[FaceMaskRegion] = list(face_mask_region_set.keys())
|
||||||
|
|
||||||
|
audio_type_set : AudioTypeSet =\
|
||||||
|
{
|
||||||
|
'flac': 'audio/flac',
|
||||||
|
'm4a': 'audio/mp4',
|
||||||
|
'mp3': 'audio/mpeg',
|
||||||
|
'ogg': 'audio/ogg',
|
||||||
|
'opus': 'audio/opus',
|
||||||
|
'wav': 'audio/x-wav'
|
||||||
|
}
|
||||||
|
image_type_set : ImageTypeSet =\
|
||||||
|
{
|
||||||
|
'bmp': 'image/bmp',
|
||||||
|
'jpeg': 'image/jpeg',
|
||||||
|
'png': 'image/png',
|
||||||
|
'tiff': 'image/tiff',
|
||||||
|
'webp': 'image/webp'
|
||||||
|
}
|
||||||
|
video_type_set : VideoTypeSet =\
|
||||||
|
{
|
||||||
|
'avi': 'video/x-msvideo',
|
||||||
|
'm4v': 'video/mp4',
|
||||||
|
'mkv': 'video/x-matroska',
|
||||||
|
'mp4': 'video/mp4',
|
||||||
|
'mov': 'video/quicktime',
|
||||||
|
'webm': 'video/webm'
|
||||||
|
}
|
||||||
|
audio_formats : List[AudioFormat] = list(audio_type_set.keys())
|
||||||
|
image_formats : List[ImageFormat] = list(image_type_set.keys())
|
||||||
|
video_formats : List[VideoFormat] = list(video_type_set.keys())
|
||||||
|
temp_frame_formats : List[TempFrameFormat] = [ 'bmp', 'jpeg', 'png', 'tiff' ]
|
||||||
|
|
||||||
|
output_encoder_set : EncoderSet =\
|
||||||
|
{
|
||||||
|
'audio': [ 'flac', 'aac', 'libmp3lame', 'libopus', 'libvorbis', 'pcm_s16le', 'pcm_s32le' ],
|
||||||
|
'video': [ 'libx264', 'libx265', 'libvpx-vp9', 'h264_nvenc', 'hevc_nvenc', 'h264_amf', 'hevc_amf', 'h264_qsv', 'hevc_qsv', 'h264_videotoolbox', 'hevc_videotoolbox', 'rawvideo' ]
|
||||||
|
}
|
||||||
|
output_audio_encoders : List[AudioEncoder] = output_encoder_set.get('audio')
|
||||||
|
output_video_encoders : List[VideoEncoder] = output_encoder_set.get('video')
|
||||||
|
output_video_presets : List[VideoPreset] = [ 'ultrafast', 'superfast', 'veryfast', 'faster', 'fast', 'medium', 'slow', 'slower', 'veryslow' ]
|
||||||
|
|
||||||
image_template_sizes : List[float] = [ 0.25, 0.5, 0.75, 1, 1.5, 2, 2.5, 3, 3.5, 4 ]
|
image_template_sizes : List[float] = [ 0.25, 0.5, 0.75, 1, 1.5, 2, 2.5, 3, 3.5, 4 ]
|
||||||
video_template_sizes : List[int] = [ 240, 360, 480, 540, 720, 1080, 1440, 2160, 4320 ]
|
video_template_sizes : List[int] = [ 240, 360, 480, 540, 720, 1080, 1440, 2160, 4320 ]
|
||||||
|
|
||||||
|
webcam_modes : List[WebcamMode] = [ 'inline', 'udp', 'v4l2' ]
|
||||||
|
webcam_resolutions : List[str] = [ '320x240', '640x480', '800x600', '1024x768', '1280x720', '1280x960', '1920x1080', '2560x1440', '3840x2160' ]
|
||||||
|
|
||||||
|
execution_provider_set : ExecutionProviderSet =\
|
||||||
|
{
|
||||||
|
'cuda': 'CUDAExecutionProvider',
|
||||||
|
'tensorrt': 'TensorrtExecutionProvider',
|
||||||
|
'directml': 'DmlExecutionProvider',
|
||||||
|
'rocm': 'ROCMExecutionProvider',
|
||||||
|
'openvino': 'OpenVINOExecutionProvider',
|
||||||
|
'coreml': 'CoreMLExecutionProvider',
|
||||||
|
'cpu': 'CPUExecutionProvider'
|
||||||
|
}
|
||||||
|
execution_providers : List[ExecutionProvider] = list(execution_provider_set.keys())
|
||||||
|
download_provider_set : DownloadProviderSet =\
|
||||||
|
{
|
||||||
|
'github':
|
||||||
|
{
|
||||||
|
'urls':
|
||||||
|
[
|
||||||
|
'https://github.com'
|
||||||
|
],
|
||||||
|
'path': '/facefusion/facefusion-assets/releases/download/{base_name}/{file_name}'
|
||||||
|
},
|
||||||
|
'huggingface':
|
||||||
|
{
|
||||||
|
'urls':
|
||||||
|
[
|
||||||
|
'https://huggingface.co',
|
||||||
|
'https://hf-mirror.com'
|
||||||
|
],
|
||||||
|
'path': '/facefusion/{base_name}/resolve/main/{file_name}'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
download_providers : List[DownloadProvider] = list(download_provider_set.keys())
|
||||||
|
download_scopes : List[DownloadScope] = [ 'lite', 'full' ]
|
||||||
|
|
||||||
|
video_memory_strategies : List[VideoMemoryStrategy] = [ 'strict', 'moderate', 'tolerant' ]
|
||||||
|
|
||||||
log_level_set : LogLevelSet =\
|
log_level_set : LogLevelSet =\
|
||||||
{
|
{
|
||||||
'error': logging.ERROR,
|
'error': logging.ERROR,
|
||||||
@@ -35,17 +124,7 @@ log_level_set : LogLevelSet =\
|
|||||||
'info': logging.INFO,
|
'info': logging.INFO,
|
||||||
'debug': logging.DEBUG
|
'debug': logging.DEBUG
|
||||||
}
|
}
|
||||||
|
log_levels : List[LogLevel] = list(log_level_set.keys())
|
||||||
execution_provider_set : ExecutionProviderSet =\
|
|
||||||
{
|
|
||||||
'cpu': 'CPUExecutionProvider',
|
|
||||||
'coreml': 'CoreMLExecutionProvider',
|
|
||||||
'cuda': 'CUDAExecutionProvider',
|
|
||||||
'directml': 'DmlExecutionProvider',
|
|
||||||
'openvino': 'OpenVINOExecutionProvider',
|
|
||||||
'rocm': 'ROCMExecutionProvider',
|
|
||||||
'tensorrt': 'TensorrtExecutionProvider'
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_workflows : List[UiWorkflow] = [ 'instant_runner', 'job_runner', 'job_manager' ]
|
ui_workflows : List[UiWorkflow] = [ 'instant_runner', 'job_runner', 'job_manager' ]
|
||||||
job_statuses : List[JobStatus] = [ 'drafted', 'queued', 'completed', 'failed' ]
|
job_statuses : List[JobStatus] = [ 'drafted', 'queued', 'completed', 'failed' ]
|
||||||
@@ -59,6 +138,8 @@ face_landmarker_score_range : Sequence[Score] = create_float_range(0.0, 1.0, 0.0
|
|||||||
face_mask_blur_range : Sequence[float] = create_float_range(0.0, 1.0, 0.05)
|
face_mask_blur_range : Sequence[float] = create_float_range(0.0, 1.0, 0.05)
|
||||||
face_mask_padding_range : Sequence[int] = create_int_range(0, 100, 1)
|
face_mask_padding_range : Sequence[int] = create_int_range(0, 100, 1)
|
||||||
face_selector_age_range : Sequence[int] = create_int_range(0, 100, 1)
|
face_selector_age_range : Sequence[int] = create_int_range(0, 100, 1)
|
||||||
reference_face_distance_range : Sequence[float] = create_float_range(0.0, 1.5, 0.05)
|
reference_face_distance_range : Sequence[float] = create_float_range(0.0, 1.0, 0.05)
|
||||||
output_image_quality_range : Sequence[int] = create_int_range(0, 100, 1)
|
output_image_quality_range : Sequence[int] = create_int_range(0, 100, 1)
|
||||||
|
output_audio_quality_range : Sequence[int] = create_int_range(0, 100, 1)
|
||||||
|
output_audio_volume_range : Sequence[int] = create_int_range(0, 100, 1)
|
||||||
output_video_quality_range : Sequence[int] = create_int_range(0, 100, 1)
|
output_video_quality_range : Sequence[int] = create_int_range(0, 100, 1)
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
from typing import Tuple
|
||||||
|
|
||||||
|
from facefusion.logger import get_package_logger
|
||||||
|
from facefusion.types import TableContents, TableHeaders
|
||||||
|
|
||||||
|
|
||||||
|
def render_table(headers : TableHeaders, contents : TableContents) -> None:
|
||||||
|
package_logger = get_package_logger()
|
||||||
|
table_column, table_separator = create_table_parts(headers, contents)
|
||||||
|
|
||||||
|
package_logger.info(table_separator)
|
||||||
|
package_logger.info(table_column.format(*headers))
|
||||||
|
package_logger.info(table_separator)
|
||||||
|
|
||||||
|
for content in contents:
|
||||||
|
content = [ value if value else '' for value in content ]
|
||||||
|
package_logger.info(table_column.format(*content))
|
||||||
|
|
||||||
|
package_logger.info(table_separator)
|
||||||
|
|
||||||
|
|
||||||
|
def create_table_parts(headers : TableHeaders, contents : TableContents) -> Tuple[str, str]:
|
||||||
|
column_parts = []
|
||||||
|
separator_parts = []
|
||||||
|
widths = [ len(header) for header in headers ]
|
||||||
|
|
||||||
|
for content in contents:
|
||||||
|
for index, value in enumerate(content):
|
||||||
|
widths[index] = max(widths[index], len(str(value)))
|
||||||
|
|
||||||
|
for width in widths:
|
||||||
|
column_parts.append('{:<' + str(width) + '}')
|
||||||
|
separator_parts.append('-' * width)
|
||||||
|
|
||||||
|
return '| ' + ' | '.join(column_parts) + ' |', '+-' + '-+-'.join(separator_parts) + '-+'
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import platform
|
import platform
|
||||||
from typing import Any, Optional, Sequence
|
from typing import Any, Iterable, Optional, Reversible, Sequence
|
||||||
|
|
||||||
|
|
||||||
def is_linux() -> bool:
|
def is_linux() -> bool:
|
||||||
@@ -50,23 +50,35 @@ def calc_float_step(float_range : Sequence[float]) -> float:
|
|||||||
return round(float_range[1] - float_range[0], 2)
|
return round(float_range[1] - float_range[0], 2)
|
||||||
|
|
||||||
|
|
||||||
def cast_int(value : Any) -> Optional[Any]:
|
def cast_int(value : Any) -> Optional[int]:
|
||||||
try:
|
try:
|
||||||
return int(value)
|
return int(value)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def cast_float(value : Any) -> Optional[Any]:
|
def cast_float(value : Any) -> Optional[float]:
|
||||||
try:
|
try:
|
||||||
return float(value)
|
return float(value)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def cast_bool(value : Any) -> Optional[bool]:
|
||||||
|
if value == 'True':
|
||||||
|
return True
|
||||||
|
if value == 'False':
|
||||||
|
return False
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_first(__list__ : Any) -> Any:
|
def get_first(__list__ : Any) -> Any:
|
||||||
return next(iter(__list__), None)
|
if isinstance(__list__, Iterable):
|
||||||
|
return next(iter(__list__), None)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_last(__list__ : Any) -> Any:
|
def get_last(__list__ : Any) -> Any:
|
||||||
return next(reversed(__list__), None)
|
if isinstance(__list__, Reversible):
|
||||||
|
return next(reversed(__list__), None)
|
||||||
|
return None
|
||||||
|
|||||||
+56
-74
@@ -1,92 +1,74 @@
|
|||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from typing import Any, List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from facefusion import state_manager
|
from facefusion import state_manager
|
||||||
from facefusion.common_helper import cast_float, cast_int
|
from facefusion.common_helper import cast_bool, cast_float, cast_int
|
||||||
|
|
||||||
CONFIG = None
|
CONFIG_PARSER = None
|
||||||
|
|
||||||
|
|
||||||
def get_config() -> ConfigParser:
|
def get_config_parser() -> ConfigParser:
|
||||||
global CONFIG
|
global CONFIG_PARSER
|
||||||
|
|
||||||
if CONFIG is None:
|
if CONFIG_PARSER is None:
|
||||||
CONFIG = ConfigParser()
|
CONFIG_PARSER = ConfigParser()
|
||||||
CONFIG.read(state_manager.get_item('config_path'), encoding = 'utf-8')
|
CONFIG_PARSER.read(state_manager.get_item('config_path'), encoding = 'utf-8')
|
||||||
return CONFIG
|
return CONFIG_PARSER
|
||||||
|
|
||||||
|
|
||||||
def clear_config() -> None:
|
def clear_config_parser() -> None:
|
||||||
global CONFIG
|
global CONFIG_PARSER
|
||||||
|
|
||||||
CONFIG = None
|
CONFIG_PARSER = None
|
||||||
|
|
||||||
|
|
||||||
def get_str_value(key : str, fallback : Optional[str] = None) -> Optional[str]:
|
def get_str_value(section : str, option : str, fallback : Optional[str] = None) -> Optional[str]:
|
||||||
value = get_value_by_notation(key)
|
config_parser = get_config_parser()
|
||||||
|
|
||||||
if value or fallback:
|
if config_parser.has_option(section, option) and config_parser.get(section, option).strip():
|
||||||
return str(value or fallback)
|
return config_parser.get(section, option)
|
||||||
|
return fallback
|
||||||
|
|
||||||
|
|
||||||
|
def get_int_value(section : str, option : str, fallback : Optional[str] = None) -> Optional[int]:
|
||||||
|
config_parser = get_config_parser()
|
||||||
|
|
||||||
|
if config_parser.has_option(section, option) and config_parser.get(section, option).strip():
|
||||||
|
return config_parser.getint(section, option)
|
||||||
|
return cast_int(fallback)
|
||||||
|
|
||||||
|
|
||||||
|
def get_float_value(section : str, option : str, fallback : Optional[str] = None) -> Optional[float]:
|
||||||
|
config_parser = get_config_parser()
|
||||||
|
|
||||||
|
if config_parser.has_option(section, option) and config_parser.get(section, option).strip():
|
||||||
|
return config_parser.getfloat(section, option)
|
||||||
|
return cast_float(fallback)
|
||||||
|
|
||||||
|
|
||||||
|
def get_bool_value(section : str, option : str, fallback : Optional[str] = None) -> Optional[bool]:
|
||||||
|
config_parser = get_config_parser()
|
||||||
|
|
||||||
|
if config_parser.has_option(section, option) and config_parser.get(section, option).strip():
|
||||||
|
return config_parser.getboolean(section, option)
|
||||||
|
return cast_bool(fallback)
|
||||||
|
|
||||||
|
|
||||||
|
def get_str_list(section : str, option : str, fallback : Optional[str] = None) -> Optional[List[str]]:
|
||||||
|
config_parser = get_config_parser()
|
||||||
|
|
||||||
|
if config_parser.has_option(section, option) and config_parser.get(section, option).strip():
|
||||||
|
return config_parser.get(section, option).split()
|
||||||
|
if fallback:
|
||||||
|
return fallback.split()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_int_value(key : str, fallback : Optional[str] = None) -> Optional[int]:
|
def get_int_list(section : str, option : str, fallback : Optional[str] = None) -> Optional[List[int]]:
|
||||||
value = get_value_by_notation(key)
|
config_parser = get_config_parser()
|
||||||
|
|
||||||
if value or fallback:
|
if config_parser.has_option(section, option) and config_parser.get(section, option).strip():
|
||||||
return cast_int(value or fallback)
|
return list(map(int, config_parser.get(section, option).split()))
|
||||||
return None
|
if fallback:
|
||||||
|
return list(map(int, fallback.split()))
|
||||||
|
|
||||||
def get_float_value(key : str, fallback : Optional[str] = None) -> Optional[float]:
|
|
||||||
value = get_value_by_notation(key)
|
|
||||||
|
|
||||||
if value or fallback:
|
|
||||||
return cast_float(value or fallback)
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_bool_value(key : str, fallback : Optional[str] = None) -> Optional[bool]:
|
|
||||||
value = get_value_by_notation(key)
|
|
||||||
|
|
||||||
if value == 'True' or fallback == 'True':
|
|
||||||
return True
|
|
||||||
if value == 'False' or fallback == 'False':
|
|
||||||
return False
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_str_list(key : str, fallback : Optional[str] = None) -> Optional[List[str]]:
|
|
||||||
value = get_value_by_notation(key)
|
|
||||||
|
|
||||||
if value or fallback:
|
|
||||||
return [ str(value) for value in (value or fallback).split(' ') ]
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_int_list(key : str, fallback : Optional[str] = None) -> Optional[List[int]]:
|
|
||||||
value = get_value_by_notation(key)
|
|
||||||
|
|
||||||
if value or fallback:
|
|
||||||
return [ cast_int(value) for value in (value or fallback).split(' ') ]
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_float_list(key : str, fallback : Optional[str] = None) -> Optional[List[float]]:
|
|
||||||
value = get_value_by_notation(key)
|
|
||||||
|
|
||||||
if value or fallback:
|
|
||||||
return [ cast_float(value) for value in (value or fallback).split(' ') ]
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_value_by_notation(key : str) -> Optional[Any]:
|
|
||||||
config = get_config()
|
|
||||||
|
|
||||||
if '.' in key:
|
|
||||||
section, name = key.split('.')
|
|
||||||
if section in config and name in config[section]:
|
|
||||||
return config[section][name]
|
|
||||||
if key in config:
|
|
||||||
return config[key]
|
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -1,64 +1,67 @@
|
|||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import cv2
|
|
||||||
import numpy
|
import numpy
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from facefusion import inference_manager, state_manager, wording
|
from facefusion import inference_manager, state_manager, wording
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
from facefusion.filesystem import resolve_relative_path
|
from facefusion.filesystem import resolve_relative_path
|
||||||
from facefusion.thread_helper import conditional_thread_semaphore
|
from facefusion.thread_helper import conditional_thread_semaphore
|
||||||
from facefusion.typing import Fps, InferencePool, ModelOptions, ModelSet, VisionFrame
|
from facefusion.types import Detection, DownloadScope, Fps, InferencePool, ModelOptions, ModelSet, Score, VisionFrame
|
||||||
from facefusion.vision import count_video_frame_total, detect_video_fps, get_video_frame, read_image
|
from facefusion.vision import detect_video_fps, fit_frame, read_image, read_video_frame
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
|
||||||
'open_nsfw':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'content_analyser':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/open_nsfw.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/open_nsfw.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'content_analyser':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/open_nsfw.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/open_nsfw.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'size': (224, 224),
|
|
||||||
'mean': [ 104, 117, 123 ]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PROBABILITY_LIMIT = 0.80
|
|
||||||
RATE_LIMIT = 10
|
|
||||||
STREAM_COUNTER = 0
|
STREAM_COUNTER = 0
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize = None)
|
||||||
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
|
{
|
||||||
|
'yolo_nsfw':
|
||||||
|
{
|
||||||
|
'hashes':
|
||||||
|
{
|
||||||
|
'content_analyser':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.2.0', 'yolo_11m_nsfw.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/yolo_11m_nsfw.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'content_analyser':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.2.0', 'yolo_11m_nsfw.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/yolo_11m_nsfw.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (640, 640)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
model_sources = get_model_options().get('sources')
|
model_names = [ 'yolo_nsfw' ]
|
||||||
return inference_manager.get_inference_pool(__name__, model_sources)
|
model_source_set = get_model_options().get('sources')
|
||||||
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
inference_manager.clear_inference_pool(__name__)
|
model_names = [ 'yolo_nsfw' ]
|
||||||
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def get_model_options() -> ModelOptions:
|
def get_model_options() -> ModelOptions:
|
||||||
return MODEL_SET.get('open_nsfw')
|
return create_static_model_set('full').get('yolo_nsfw')
|
||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set = get_model_options().get('hashes')
|
||||||
model_hashes = get_model_options().get('hashes')
|
model_source_set = get_model_options().get('sources')
|
||||||
model_sources = get_model_options().get('sources')
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def analyse_stream(vision_frame : VisionFrame, video_fps : Fps) -> bool:
|
def analyse_stream(vision_frame : VisionFrame, video_fps : Fps) -> bool:
|
||||||
@@ -71,54 +74,71 @@ def analyse_stream(vision_frame : VisionFrame, video_fps : Fps) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def analyse_frame(vision_frame : VisionFrame) -> bool:
|
def analyse_frame(vision_frame : VisionFrame) -> bool:
|
||||||
vision_frame = prepare_frame(vision_frame)
|
nsfw_scores = detect_nsfw(vision_frame)
|
||||||
probability = forward(vision_frame)
|
|
||||||
|
|
||||||
return probability > PROBABILITY_LIMIT
|
return len(nsfw_scores) > 0
|
||||||
|
|
||||||
|
|
||||||
def forward(vision_frame : VisionFrame) -> float:
|
|
||||||
content_analyser = get_inference_pool().get('content_analyser')
|
|
||||||
|
|
||||||
with conditional_thread_semaphore():
|
|
||||||
probability = content_analyser.run(None,
|
|
||||||
{
|
|
||||||
'input': vision_frame
|
|
||||||
})[0][0][1]
|
|
||||||
|
|
||||||
return probability
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_frame(vision_frame : VisionFrame) -> VisionFrame:
|
|
||||||
model_size = get_model_options().get('size')
|
|
||||||
model_mean = get_model_options().get('mean')
|
|
||||||
vision_frame = cv2.resize(vision_frame, model_size).astype(numpy.float32)
|
|
||||||
vision_frame -= numpy.array(model_mean).astype(numpy.float32)
|
|
||||||
vision_frame = numpy.expand_dims(vision_frame, axis = 0)
|
|
||||||
return vision_frame
|
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize = None)
|
@lru_cache(maxsize = None)
|
||||||
def analyse_image(image_path : str) -> bool:
|
def analyse_image(image_path : str) -> bool:
|
||||||
frame = read_image(image_path)
|
vision_frame = read_image(image_path)
|
||||||
return analyse_frame(frame)
|
return analyse_frame(vision_frame)
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize = None)
|
@lru_cache(maxsize = None)
|
||||||
def analyse_video(video_path : str, start_frame : int, end_frame : int) -> bool:
|
def analyse_video(video_path : str, trim_frame_start : int, trim_frame_end : int) -> bool:
|
||||||
video_frame_total = count_video_frame_total(video_path)
|
|
||||||
video_fps = detect_video_fps(video_path)
|
video_fps = detect_video_fps(video_path)
|
||||||
frame_range = range(start_frame or 0, end_frame or video_frame_total)
|
frame_range = range(trim_frame_start, trim_frame_end)
|
||||||
rate = 0.0
|
rate = 0.0
|
||||||
|
total = 0
|
||||||
counter = 0
|
counter = 0
|
||||||
|
|
||||||
with tqdm(total = len(frame_range), desc = wording.get('analysing'), unit = 'frame', ascii = ' =', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress:
|
with tqdm(total = len(frame_range), desc = wording.get('analysing'), unit = 'frame', ascii = ' =', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress:
|
||||||
|
|
||||||
for frame_number in frame_range:
|
for frame_number in frame_range:
|
||||||
if frame_number % int(video_fps) == 0:
|
if frame_number % int(video_fps) == 0:
|
||||||
frame = get_video_frame(video_path, frame_number)
|
vision_frame = read_video_frame(video_path, frame_number)
|
||||||
if analyse_frame(frame):
|
total += 1
|
||||||
|
if analyse_frame(vision_frame):
|
||||||
counter += 1
|
counter += 1
|
||||||
rate = counter * int(video_fps) / len(frame_range) * 100
|
if counter > 0 and total > 0:
|
||||||
progress.update()
|
rate = counter / total * 100
|
||||||
progress.set_postfix(rate = rate)
|
progress.set_postfix(rate = rate)
|
||||||
return rate > RATE_LIMIT
|
progress.update()
|
||||||
|
|
||||||
|
return rate > 10.0
|
||||||
|
|
||||||
|
|
||||||
|
def detect_nsfw(vision_frame : VisionFrame) -> List[Score]:
|
||||||
|
nsfw_scores = []
|
||||||
|
model_size = get_model_options().get('size')
|
||||||
|
temp_vision_frame = fit_frame(vision_frame, model_size)
|
||||||
|
detect_vision_frame = prepare_detect_frame(temp_vision_frame)
|
||||||
|
detection = forward(detect_vision_frame)
|
||||||
|
detection = numpy.squeeze(detection).T
|
||||||
|
nsfw_scores_raw = numpy.amax(detection[:, 4:], axis = 1)
|
||||||
|
keep_indices = numpy.where(nsfw_scores_raw > 0.2)[0]
|
||||||
|
|
||||||
|
if numpy.any(keep_indices):
|
||||||
|
nsfw_scores_raw = nsfw_scores_raw[keep_indices]
|
||||||
|
nsfw_scores = nsfw_scores_raw.ravel().tolist()
|
||||||
|
|
||||||
|
return nsfw_scores
|
||||||
|
|
||||||
|
|
||||||
|
def forward(vision_frame : VisionFrame) -> Detection:
|
||||||
|
content_analyser = get_inference_pool().get('content_analyser')
|
||||||
|
|
||||||
|
with conditional_thread_semaphore():
|
||||||
|
detection = content_analyser.run(None,
|
||||||
|
{
|
||||||
|
'input': vision_frame
|
||||||
|
})
|
||||||
|
|
||||||
|
return detection
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_detect_frame(temp_vision_frame : VisionFrame) -> VisionFrame:
|
||||||
|
detect_vision_frame = temp_vision_frame / 255.0
|
||||||
|
detect_vision_frame = numpy.expand_dims(detect_vision_frame.transpose(2, 0, 1), axis = 0).astype(numpy.float32)
|
||||||
|
return detect_vision_frame
|
||||||
|
|||||||
+163
-101
@@ -1,3 +1,4 @@
|
|||||||
|
import itertools
|
||||||
import shutil
|
import shutil
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
@@ -5,17 +6,17 @@ from time import time
|
|||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
from facefusion import content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, logger, process_manager, state_manager, voice_extractor, wording
|
from facefusion import cli_helper, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, logger, process_manager, state_manager, voice_extractor, wording
|
||||||
from facefusion.args import apply_args, collect_job_args, reduce_step_args
|
from facefusion.args import apply_args, collect_job_args, reduce_job_args, reduce_step_args
|
||||||
from facefusion.common_helper import get_first
|
from facefusion.common_helper import get_first
|
||||||
from facefusion.content_analyser import analyse_image, analyse_video
|
from facefusion.content_analyser import analyse_image, analyse_video
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
||||||
from facefusion.exit_helper import conditional_exit, graceful_exit, hard_exit
|
from facefusion.exit_helper import graceful_exit, hard_exit
|
||||||
from facefusion.face_analyser import get_average_face, get_many_faces, get_one_face
|
from facefusion.face_analyser import get_average_face, get_many_faces, get_one_face
|
||||||
from facefusion.face_selector import sort_and_filter_faces
|
from facefusion.face_selector import sort_and_filter_faces
|
||||||
from facefusion.face_store import append_reference_face, clear_reference_faces, get_reference_faces
|
from facefusion.face_store import append_reference_face, clear_reference_faces, get_reference_faces
|
||||||
from facefusion.ffmpeg import copy_image, extract_frames, finalize_image, merge_video, replace_audio, restore_audio
|
from facefusion.ffmpeg import copy_image, extract_frames, finalize_image, merge_video, replace_audio, restore_audio
|
||||||
from facefusion.filesystem import filter_audio_paths, is_image, is_video, list_directory, resolve_relative_path
|
from facefusion.filesystem import filter_audio_paths, get_file_name, is_image, is_video, resolve_file_paths, resolve_file_pattern
|
||||||
from facefusion.jobs import job_helper, job_manager, job_runner
|
from facefusion.jobs import job_helper, job_manager, job_runner
|
||||||
from facefusion.jobs.job_list import compose_job_list
|
from facefusion.jobs.job_list import compose_job_list
|
||||||
from facefusion.memory import limit_system_memory
|
from facefusion.memory import limit_system_memory
|
||||||
@@ -23,54 +24,70 @@ from facefusion.processors.core import get_processors_modules
|
|||||||
from facefusion.program import create_program
|
from facefusion.program import create_program
|
||||||
from facefusion.program_helper import validate_args
|
from facefusion.program_helper import validate_args
|
||||||
from facefusion.statistics import conditional_log_statistics
|
from facefusion.statistics import conditional_log_statistics
|
||||||
from facefusion.temp_helper import clear_temp_directory, create_temp_directory, get_temp_file_path, get_temp_frame_paths, move_temp_file
|
from facefusion.temp_helper import clear_temp_directory, create_temp_directory, get_temp_file_path, move_temp_file, resolve_temp_frame_paths
|
||||||
from facefusion.typing import Args, ErrorCode
|
from facefusion.types import Args, ErrorCode
|
||||||
from facefusion.vision import get_video_frame, pack_resolution, read_image, read_static_images, restrict_image_resolution, restrict_video_fps, restrict_video_resolution, unpack_resolution
|
from facefusion.vision import pack_resolution, read_image, read_static_images, read_video_frame, restrict_image_resolution, restrict_trim_frame, restrict_video_fps, restrict_video_resolution, unpack_resolution
|
||||||
|
|
||||||
|
|
||||||
def cli() -> None:
|
def cli() -> None:
|
||||||
signal.signal(signal.SIGINT, lambda signal_number, frame: graceful_exit(0))
|
if pre_check():
|
||||||
program = create_program()
|
signal.signal(signal.SIGINT, lambda signal_number, frame: graceful_exit(0))
|
||||||
|
program = create_program()
|
||||||
|
|
||||||
if validate_args(program):
|
if validate_args(program):
|
||||||
args = vars(program.parse_args())
|
args = vars(program.parse_args())
|
||||||
apply_args(args, state_manager.init_item)
|
apply_args(args, state_manager.init_item)
|
||||||
|
|
||||||
if state_manager.get_item('command'):
|
if state_manager.get_item('command'):
|
||||||
logger.init(state_manager.get_item('log_level'))
|
logger.init(state_manager.get_item('log_level'))
|
||||||
route(args)
|
route(args)
|
||||||
|
else:
|
||||||
|
program.print_help()
|
||||||
else:
|
else:
|
||||||
program.print_help()
|
hard_exit(2)
|
||||||
|
else:
|
||||||
|
hard_exit(2)
|
||||||
|
|
||||||
|
|
||||||
def route(args : Args) -> None:
|
def route(args : Args) -> None:
|
||||||
system_memory_limit = state_manager.get_item('system_memory_limit')
|
system_memory_limit = state_manager.get_item('system_memory_limit')
|
||||||
|
|
||||||
if system_memory_limit and system_memory_limit > 0:
|
if system_memory_limit and system_memory_limit > 0:
|
||||||
limit_system_memory(system_memory_limit)
|
limit_system_memory(system_memory_limit)
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'force-download':
|
if state_manager.get_item('command') == 'force-download':
|
||||||
error_code = force_download()
|
error_code = force_download()
|
||||||
return conditional_exit(error_code)
|
return hard_exit(error_code)
|
||||||
|
|
||||||
if state_manager.get_item('command') in [ 'job-list', 'job-create', 'job-submit', 'job-submit-all', 'job-delete', 'job-delete-all', 'job-add-step', 'job-remix-step', 'job-insert-step', 'job-remove-step' ]:
|
if state_manager.get_item('command') in [ 'job-list', 'job-create', 'job-submit', 'job-submit-all', 'job-delete', 'job-delete-all', 'job-add-step', 'job-remix-step', 'job-insert-step', 'job-remove-step' ]:
|
||||||
if not job_manager.init_jobs(state_manager.get_item('jobs_path')):
|
if not job_manager.init_jobs(state_manager.get_item('jobs_path')):
|
||||||
hard_exit(1)
|
hard_exit(1)
|
||||||
error_code = route_job_manager(args)
|
error_code = route_job_manager(args)
|
||||||
hard_exit(error_code)
|
hard_exit(error_code)
|
||||||
if not pre_check():
|
|
||||||
return conditional_exit(2)
|
|
||||||
if state_manager.get_item('command') == 'run':
|
if state_manager.get_item('command') == 'run':
|
||||||
import facefusion.uis.core as ui
|
import facefusion.uis.core as ui
|
||||||
|
|
||||||
if not common_pre_check() or not processors_pre_check():
|
if not common_pre_check() or not processors_pre_check():
|
||||||
return conditional_exit(2)
|
return hard_exit(2)
|
||||||
for ui_layout in ui.get_ui_layouts_modules(state_manager.get_item('ui_layouts')):
|
for ui_layout in ui.get_ui_layouts_modules(state_manager.get_item('ui_layouts')):
|
||||||
if not ui_layout.pre_check():
|
if not ui_layout.pre_check():
|
||||||
return conditional_exit(2)
|
return hard_exit(2)
|
||||||
|
ui.init()
|
||||||
ui.launch()
|
ui.launch()
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'headless-run':
|
if state_manager.get_item('command') == 'headless-run':
|
||||||
if not job_manager.init_jobs(state_manager.get_item('jobs_path')):
|
if not job_manager.init_jobs(state_manager.get_item('jobs_path')):
|
||||||
hard_exit(1)
|
hard_exit(1)
|
||||||
error_core = process_headless(args)
|
error_core = process_headless(args)
|
||||||
hard_exit(error_core)
|
hard_exit(error_core)
|
||||||
|
|
||||||
|
if state_manager.get_item('command') == 'batch-run':
|
||||||
|
if not job_manager.init_jobs(state_manager.get_item('jobs_path')):
|
||||||
|
hard_exit(1)
|
||||||
|
error_core = process_batch(args)
|
||||||
|
hard_exit(error_core)
|
||||||
|
|
||||||
if state_manager.get_item('command') in [ 'job-run', 'job-run-all', 'job-retry', 'job-retry-all' ]:
|
if state_manager.get_item('command') in [ 'job-run', 'job-run-all', 'job-retry', 'job-retry-all' ]:
|
||||||
if not job_manager.init_jobs(state_manager.get_item('jobs_path')):
|
if not job_manager.init_jobs(state_manager.get_item('jobs_path')):
|
||||||
hard_exit(1)
|
hard_exit(1)
|
||||||
@@ -79,12 +96,14 @@ def route(args : Args) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
if sys.version_info < (3, 9):
|
if sys.version_info < (3, 10):
|
||||||
logger.error(wording.get('python_not_supported').format(version = '3.9'), __name__)
|
logger.error(wording.get('python_not_supported').format(version = '3.10'), __name__)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not shutil.which('curl'):
|
if not shutil.which('curl'):
|
||||||
logger.error(wording.get('curl_not_installed'), __name__)
|
logger.error(wording.get('curl_not_installed'), __name__)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not shutil.which('ffmpeg'):
|
if not shutil.which('ffmpeg'):
|
||||||
logger.error(wording.get('ffmpeg_not_installed'), __name__)
|
logger.error(wording.get('ffmpeg_not_installed'), __name__)
|
||||||
return False
|
return False
|
||||||
@@ -92,7 +111,7 @@ def pre_check() -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def common_pre_check() -> bool:
|
def common_pre_check() -> bool:
|
||||||
modules =\
|
common_modules =\
|
||||||
[
|
[
|
||||||
content_analyser,
|
content_analyser,
|
||||||
face_classifier,
|
face_classifier,
|
||||||
@@ -103,7 +122,7 @@ def common_pre_check() -> bool:
|
|||||||
voice_extractor
|
voice_extractor
|
||||||
]
|
]
|
||||||
|
|
||||||
return all(module.pre_check() for module in modules)
|
return all(module.pre_check() for module in common_modules)
|
||||||
|
|
||||||
|
|
||||||
def processors_pre_check() -> bool:
|
def processors_pre_check() -> bool:
|
||||||
@@ -113,64 +132,28 @@ def processors_pre_check() -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def conditional_process() -> ErrorCode:
|
|
||||||
start_time = time()
|
|
||||||
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
|
||||||
if not processor_module.pre_process('output'):
|
|
||||||
return 2
|
|
||||||
conditional_append_reference_faces()
|
|
||||||
if is_image(state_manager.get_item('target_path')):
|
|
||||||
return process_image(start_time)
|
|
||||||
if is_video(state_manager.get_item('target_path')):
|
|
||||||
return process_video(start_time)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
def conditional_append_reference_faces() -> None:
|
|
||||||
if 'reference' in state_manager.get_item('face_selector_mode') and not get_reference_faces():
|
|
||||||
source_frames = read_static_images(state_manager.get_item('source_paths'))
|
|
||||||
source_faces = get_many_faces(source_frames)
|
|
||||||
source_face = get_average_face(source_faces)
|
|
||||||
if is_video(state_manager.get_item('target_path')):
|
|
||||||
reference_frame = get_video_frame(state_manager.get_item('target_path'), state_manager.get_item('reference_frame_number'))
|
|
||||||
else:
|
|
||||||
reference_frame = read_image(state_manager.get_item('target_path'))
|
|
||||||
reference_faces = sort_and_filter_faces(get_many_faces([ reference_frame ]))
|
|
||||||
reference_face = get_one_face(reference_faces, state_manager.get_item('reference_face_position'))
|
|
||||||
append_reference_face('origin', reference_face)
|
|
||||||
|
|
||||||
if source_face and reference_face:
|
|
||||||
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
|
||||||
abstract_reference_frame = processor_module.get_reference_frame(source_face, reference_face, reference_frame)
|
|
||||||
if numpy.any(abstract_reference_frame):
|
|
||||||
abstract_reference_faces = sort_and_filter_faces(get_many_faces([ abstract_reference_frame ]))
|
|
||||||
abstract_reference_face = get_one_face(abstract_reference_faces, state_manager.get_item('reference_face_position'))
|
|
||||||
append_reference_face(processor_module.__name__, abstract_reference_face)
|
|
||||||
|
|
||||||
|
|
||||||
def force_download() -> ErrorCode:
|
def force_download() -> ErrorCode:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
|
||||||
available_processors = list_directory('facefusion/processors/modules')
|
|
||||||
common_modules =\
|
common_modules =\
|
||||||
[
|
[
|
||||||
content_analyser,
|
content_analyser,
|
||||||
face_classifier,
|
face_classifier,
|
||||||
face_detector,
|
face_detector,
|
||||||
face_landmarker,
|
face_landmarker,
|
||||||
face_recognizer,
|
|
||||||
face_masker,
|
face_masker,
|
||||||
|
face_recognizer,
|
||||||
voice_extractor
|
voice_extractor
|
||||||
]
|
]
|
||||||
|
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
||||||
processor_modules = get_processors_modules(available_processors)
|
processor_modules = get_processors_modules(available_processors)
|
||||||
|
|
||||||
for module in common_modules + processor_modules:
|
for module in common_modules + processor_modules:
|
||||||
if hasattr(module, 'MODEL_SET'):
|
if hasattr(module, 'create_static_model_set'):
|
||||||
for model in module.MODEL_SET.values():
|
for model in module.create_static_model_set(state_manager.get_item('download_scope')).values():
|
||||||
model_hashes = model.get('hashes')
|
model_hash_set = model.get('hashes')
|
||||||
model_sources = model.get('sources')
|
model_source_set = model.get('sources')
|
||||||
|
|
||||||
if model_hashes and model_sources:
|
if model_hash_set and model_source_set:
|
||||||
if not conditional_download_hashes(download_directory_path, model_hashes) or not conditional_download_sources(download_directory_path, model_sources):
|
if not conditional_download_hashes(model_hash_set) or not conditional_download_sources(model_source_set):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -181,39 +164,45 @@ def route_job_manager(args : Args) -> ErrorCode:
|
|||||||
job_headers, job_contents = compose_job_list(state_manager.get_item('job_status'))
|
job_headers, job_contents = compose_job_list(state_manager.get_item('job_status'))
|
||||||
|
|
||||||
if job_contents:
|
if job_contents:
|
||||||
logger.table(job_headers, job_contents)
|
cli_helper.render_table(job_headers, job_contents)
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-create':
|
if state_manager.get_item('command') == 'job-create':
|
||||||
if job_manager.create_job(state_manager.get_item('job_id')):
|
if job_manager.create_job(state_manager.get_item('job_id')):
|
||||||
logger.info(wording.get('job_created').format(job_id = state_manager.get_item('job_id')), __name__)
|
logger.info(wording.get('job_created').format(job_id = state_manager.get_item('job_id')), __name__)
|
||||||
return 0
|
return 0
|
||||||
logger.error(wording.get('job_not_created').format(job_id = state_manager.get_item('job_id')), __name__)
|
logger.error(wording.get('job_not_created').format(job_id = state_manager.get_item('job_id')), __name__)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-submit':
|
if state_manager.get_item('command') == 'job-submit':
|
||||||
if job_manager.submit_job(state_manager.get_item('job_id')):
|
if job_manager.submit_job(state_manager.get_item('job_id')):
|
||||||
logger.info(wording.get('job_submitted').format(job_id = state_manager.get_item('job_id')), __name__)
|
logger.info(wording.get('job_submitted').format(job_id = state_manager.get_item('job_id')), __name__)
|
||||||
return 0
|
return 0
|
||||||
logger.error(wording.get('job_not_submitted').format(job_id = state_manager.get_item('job_id')), __name__)
|
logger.error(wording.get('job_not_submitted').format(job_id = state_manager.get_item('job_id')), __name__)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-submit-all':
|
if state_manager.get_item('command') == 'job-submit-all':
|
||||||
if job_manager.submit_jobs():
|
if job_manager.submit_jobs(state_manager.get_item('halt_on_error')):
|
||||||
logger.info(wording.get('job_all_submitted'), __name__)
|
logger.info(wording.get('job_all_submitted'), __name__)
|
||||||
return 0
|
return 0
|
||||||
logger.error(wording.get('job_all_not_submitted'), __name__)
|
logger.error(wording.get('job_all_not_submitted'), __name__)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-delete':
|
if state_manager.get_item('command') == 'job-delete':
|
||||||
if job_manager.delete_job(state_manager.get_item('job_id')):
|
if job_manager.delete_job(state_manager.get_item('job_id')):
|
||||||
logger.info(wording.get('job_deleted').format(job_id = state_manager.get_item('job_id')), __name__)
|
logger.info(wording.get('job_deleted').format(job_id = state_manager.get_item('job_id')), __name__)
|
||||||
return 0
|
return 0
|
||||||
logger.error(wording.get('job_not_deleted').format(job_id = state_manager.get_item('job_id')), __name__)
|
logger.error(wording.get('job_not_deleted').format(job_id = state_manager.get_item('job_id')), __name__)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-delete-all':
|
if state_manager.get_item('command') == 'job-delete-all':
|
||||||
if job_manager.delete_jobs():
|
if job_manager.delete_jobs(state_manager.get_item('halt_on_error')):
|
||||||
logger.info(wording.get('job_all_deleted'), __name__)
|
logger.info(wording.get('job_all_deleted'), __name__)
|
||||||
return 0
|
return 0
|
||||||
logger.error(wording.get('job_all_not_deleted'), __name__)
|
logger.error(wording.get('job_all_not_deleted'), __name__)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-add-step':
|
if state_manager.get_item('command') == 'job-add-step':
|
||||||
step_args = reduce_step_args(args)
|
step_args = reduce_step_args(args)
|
||||||
|
|
||||||
@@ -222,6 +211,7 @@ def route_job_manager(args : Args) -> ErrorCode:
|
|||||||
return 0
|
return 0
|
||||||
logger.error(wording.get('job_step_not_added').format(job_id = state_manager.get_item('job_id')), __name__)
|
logger.error(wording.get('job_step_not_added').format(job_id = state_manager.get_item('job_id')), __name__)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-remix-step':
|
if state_manager.get_item('command') == 'job-remix-step':
|
||||||
step_args = reduce_step_args(args)
|
step_args = reduce_step_args(args)
|
||||||
|
|
||||||
@@ -230,6 +220,7 @@ def route_job_manager(args : Args) -> ErrorCode:
|
|||||||
return 0
|
return 0
|
||||||
logger.error(wording.get('job_remix_step_not_added').format(job_id = state_manager.get_item('job_id'), step_index = state_manager.get_item('step_index')), __name__)
|
logger.error(wording.get('job_remix_step_not_added').format(job_id = state_manager.get_item('job_id'), step_index = state_manager.get_item('step_index')), __name__)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-insert-step':
|
if state_manager.get_item('command') == 'job-insert-step':
|
||||||
step_args = reduce_step_args(args)
|
step_args = reduce_step_args(args)
|
||||||
|
|
||||||
@@ -238,6 +229,7 @@ def route_job_manager(args : Args) -> ErrorCode:
|
|||||||
return 0
|
return 0
|
||||||
logger.error(wording.get('job_step_not_inserted').format(job_id = state_manager.get_item('job_id'), step_index = state_manager.get_item('step_index')), __name__)
|
logger.error(wording.get('job_step_not_inserted').format(job_id = state_manager.get_item('job_id'), step_index = state_manager.get_item('step_index')), __name__)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-remove-step':
|
if state_manager.get_item('command') == 'job-remove-step':
|
||||||
if job_manager.remove_step(state_manager.get_item('job_id'), state_manager.get_item('step_index')):
|
if job_manager.remove_step(state_manager.get_item('job_id'), state_manager.get_item('step_index')):
|
||||||
logger.info(wording.get('job_step_removed').format(job_id = state_manager.get_item('job_id'), step_index = state_manager.get_item('step_index')), __name__)
|
logger.info(wording.get('job_step_removed').format(job_id = state_manager.get_item('job_id'), step_index = state_manager.get_item('step_index')), __name__)
|
||||||
@@ -255,13 +247,15 @@ def route_job_runner() -> ErrorCode:
|
|||||||
return 0
|
return 0
|
||||||
logger.info(wording.get('processing_job_failed').format(job_id = state_manager.get_item('job_id')), __name__)
|
logger.info(wording.get('processing_job_failed').format(job_id = state_manager.get_item('job_id')), __name__)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-run-all':
|
if state_manager.get_item('command') == 'job-run-all':
|
||||||
logger.info(wording.get('running_jobs'), __name__)
|
logger.info(wording.get('running_jobs'), __name__)
|
||||||
if job_runner.run_jobs(process_step):
|
if job_runner.run_jobs(process_step, state_manager.get_item('halt_on_error')):
|
||||||
logger.info(wording.get('processing_jobs_succeed'), __name__)
|
logger.info(wording.get('processing_jobs_succeed'), __name__)
|
||||||
return 0
|
return 0
|
||||||
logger.info(wording.get('processing_jobs_failed'), __name__)
|
logger.info(wording.get('processing_jobs_failed'), __name__)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-retry':
|
if state_manager.get_item('command') == 'job-retry':
|
||||||
logger.info(wording.get('retrying_job').format(job_id = state_manager.get_item('job_id')), __name__)
|
logger.info(wording.get('retrying_job').format(job_id = state_manager.get_item('job_id')), __name__)
|
||||||
if job_runner.retry_job(state_manager.get_item('job_id'), process_step):
|
if job_runner.retry_job(state_manager.get_item('job_id'), process_step):
|
||||||
@@ -269,9 +263,10 @@ def route_job_runner() -> ErrorCode:
|
|||||||
return 0
|
return 0
|
||||||
logger.info(wording.get('processing_job_failed').format(job_id = state_manager.get_item('job_id')), __name__)
|
logger.info(wording.get('processing_job_failed').format(job_id = state_manager.get_item('job_id')), __name__)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if state_manager.get_item('command') == 'job-retry-all':
|
if state_manager.get_item('command') == 'job-retry-all':
|
||||||
logger.info(wording.get('retrying_jobs'), __name__)
|
logger.info(wording.get('retrying_jobs'), __name__)
|
||||||
if job_runner.retry_jobs(process_step):
|
if job_runner.retry_jobs(process_step, state_manager.get_item('halt_on_error')):
|
||||||
logger.info(wording.get('processing_jobs_succeed'), __name__)
|
logger.info(wording.get('processing_jobs_succeed'), __name__)
|
||||||
return 0
|
return 0
|
||||||
logger.info(wording.get('processing_jobs_failed'), __name__)
|
logger.info(wording.get('processing_jobs_failed'), __name__)
|
||||||
@@ -279,6 +274,44 @@ def route_job_runner() -> ErrorCode:
|
|||||||
return 2
|
return 2
|
||||||
|
|
||||||
|
|
||||||
|
def process_headless(args : Args) -> ErrorCode:
|
||||||
|
job_id = job_helper.suggest_job_id('headless')
|
||||||
|
step_args = reduce_step_args(args)
|
||||||
|
|
||||||
|
if job_manager.create_job(job_id) and job_manager.add_step(job_id, step_args) and job_manager.submit_job(job_id) and job_runner.run_job(job_id, process_step):
|
||||||
|
return 0
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
def process_batch(args : Args) -> ErrorCode:
|
||||||
|
job_id = job_helper.suggest_job_id('batch')
|
||||||
|
step_args = reduce_step_args(args)
|
||||||
|
job_args = reduce_job_args(args)
|
||||||
|
source_paths = resolve_file_pattern(job_args.get('source_pattern'))
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
def process_step(job_id : str, step_index : int, step_args : Args) -> bool:
|
def process_step(job_id : str, step_index : int, step_args : Args) -> bool:
|
||||||
clear_reference_faces()
|
clear_reference_faces()
|
||||||
step_total = job_manager.count_step_total(job_id)
|
step_total = job_manager.count_step_total(job_id)
|
||||||
@@ -292,25 +325,54 @@ def process_step(job_id : str, step_index : int, step_args : Args) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def process_headless(args : Args) -> ErrorCode:
|
def conditional_process() -> ErrorCode:
|
||||||
job_id = job_helper.suggest_job_id('headless')
|
start_time = time()
|
||||||
step_args = reduce_step_args(args)
|
|
||||||
|
|
||||||
if job_manager.create_job(job_id) and job_manager.add_step(job_id, step_args) and job_manager.submit_job(job_id) and job_runner.run_job(job_id, process_step):
|
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
||||||
return 0
|
if not processor_module.pre_process('output'):
|
||||||
return 1
|
return 2
|
||||||
|
|
||||||
|
conditional_append_reference_faces()
|
||||||
|
|
||||||
|
if is_image(state_manager.get_item('target_path')):
|
||||||
|
return process_image(start_time)
|
||||||
|
if is_video(state_manager.get_item('target_path')):
|
||||||
|
return process_video(start_time)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def conditional_append_reference_faces() -> None:
|
||||||
|
if 'reference' in state_manager.get_item('face_selector_mode') and not get_reference_faces():
|
||||||
|
source_frames = read_static_images(state_manager.get_item('source_paths'))
|
||||||
|
source_faces = get_many_faces(source_frames)
|
||||||
|
source_face = get_average_face(source_faces)
|
||||||
|
if is_video(state_manager.get_item('target_path')):
|
||||||
|
reference_frame = read_video_frame(state_manager.get_item('target_path'), state_manager.get_item('reference_frame_number'))
|
||||||
|
else:
|
||||||
|
reference_frame = read_image(state_manager.get_item('target_path'))
|
||||||
|
reference_faces = sort_and_filter_faces(get_many_faces([ reference_frame ]))
|
||||||
|
reference_face = get_one_face(reference_faces, state_manager.get_item('reference_face_position'))
|
||||||
|
append_reference_face('origin', reference_face)
|
||||||
|
|
||||||
|
if source_face and reference_face:
|
||||||
|
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
||||||
|
abstract_reference_frame = processor_module.get_reference_frame(source_face, reference_face, reference_frame)
|
||||||
|
if numpy.any(abstract_reference_frame):
|
||||||
|
abstract_reference_faces = sort_and_filter_faces(get_many_faces([ abstract_reference_frame ]))
|
||||||
|
abstract_reference_face = get_one_face(abstract_reference_faces, state_manager.get_item('reference_face_position'))
|
||||||
|
append_reference_face(processor_module.__name__, abstract_reference_face)
|
||||||
|
|
||||||
|
|
||||||
def process_image(start_time : float) -> ErrorCode:
|
def process_image(start_time : float) -> ErrorCode:
|
||||||
if analyse_image(state_manager.get_item('target_path')):
|
if analyse_image(state_manager.get_item('target_path')):
|
||||||
return 3
|
return 3
|
||||||
# clear temp
|
|
||||||
logger.debug(wording.get('clearing_temp'), __name__)
|
logger.debug(wording.get('clearing_temp'), __name__)
|
||||||
clear_temp_directory(state_manager.get_item('target_path'))
|
clear_temp_directory(state_manager.get_item('target_path'))
|
||||||
# create temp
|
|
||||||
logger.debug(wording.get('creating_temp'), __name__)
|
logger.debug(wording.get('creating_temp'), __name__)
|
||||||
create_temp_directory(state_manager.get_item('target_path'))
|
create_temp_directory(state_manager.get_item('target_path'))
|
||||||
# copy image
|
|
||||||
process_manager.start()
|
process_manager.start()
|
||||||
temp_image_resolution = pack_resolution(restrict_image_resolution(state_manager.get_item('target_path'), unpack_resolution(state_manager.get_item('output_image_resolution'))))
|
temp_image_resolution = pack_resolution(restrict_image_resolution(state_manager.get_item('target_path'), unpack_resolution(state_manager.get_item('output_image_resolution'))))
|
||||||
logger.info(wording.get('copying_image').format(resolution = temp_image_resolution), __name__)
|
logger.info(wording.get('copying_image').format(resolution = temp_image_resolution), __name__)
|
||||||
@@ -320,7 +382,7 @@ def process_image(start_time : float) -> ErrorCode:
|
|||||||
logger.error(wording.get('copying_image_failed'), __name__)
|
logger.error(wording.get('copying_image_failed'), __name__)
|
||||||
process_manager.end()
|
process_manager.end()
|
||||||
return 1
|
return 1
|
||||||
# process image
|
|
||||||
temp_file_path = get_temp_file_path(state_manager.get_item('target_path'))
|
temp_file_path = get_temp_file_path(state_manager.get_item('target_path'))
|
||||||
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
||||||
logger.info(wording.get('processing'), processor_module.__name__)
|
logger.info(wording.get('processing'), processor_module.__name__)
|
||||||
@@ -329,16 +391,16 @@ def process_image(start_time : float) -> ErrorCode:
|
|||||||
if is_process_stopping():
|
if is_process_stopping():
|
||||||
process_manager.end()
|
process_manager.end()
|
||||||
return 4
|
return 4
|
||||||
# finalize image
|
|
||||||
logger.info(wording.get('finalizing_image').format(resolution = state_manager.get_item('output_image_resolution')), __name__)
|
logger.info(wording.get('finalizing_image').format(resolution = state_manager.get_item('output_image_resolution')), __name__)
|
||||||
if finalize_image(state_manager.get_item('target_path'), state_manager.get_item('output_path'), state_manager.get_item('output_image_resolution')):
|
if finalize_image(state_manager.get_item('target_path'), state_manager.get_item('output_path'), state_manager.get_item('output_image_resolution')):
|
||||||
logger.debug(wording.get('finalizing_image_succeed'), __name__)
|
logger.debug(wording.get('finalizing_image_succeed'), __name__)
|
||||||
else:
|
else:
|
||||||
logger.warn(wording.get('finalizing_image_skipped'), __name__)
|
logger.warn(wording.get('finalizing_image_skipped'), __name__)
|
||||||
# clear temp
|
|
||||||
logger.debug(wording.get('clearing_temp'), __name__)
|
logger.debug(wording.get('clearing_temp'), __name__)
|
||||||
clear_temp_directory(state_manager.get_item('target_path'))
|
clear_temp_directory(state_manager.get_item('target_path'))
|
||||||
# validate image
|
|
||||||
if is_image(state_manager.get_item('output_path')):
|
if is_image(state_manager.get_item('output_path')):
|
||||||
seconds = '{:.2f}'.format((time() - start_time) % 60)
|
seconds = '{:.2f}'.format((time() - start_time) % 60)
|
||||||
logger.info(wording.get('processing_image_succeed').format(seconds = seconds), __name__)
|
logger.info(wording.get('processing_image_succeed').format(seconds = seconds), __name__)
|
||||||
@@ -352,20 +414,20 @@ def process_image(start_time : float) -> ErrorCode:
|
|||||||
|
|
||||||
|
|
||||||
def process_video(start_time : float) -> ErrorCode:
|
def process_video(start_time : float) -> ErrorCode:
|
||||||
if analyse_video(state_manager.get_item('target_path'), state_manager.get_item('trim_frame_start'), state_manager.get_item('trim_frame_end')):
|
trim_frame_start, trim_frame_end = restrict_trim_frame(state_manager.get_item('target_path'), state_manager.get_item('trim_frame_start'), state_manager.get_item('trim_frame_end'))
|
||||||
|
if analyse_video(state_manager.get_item('target_path'), trim_frame_start, trim_frame_end):
|
||||||
return 3
|
return 3
|
||||||
# clear temp
|
|
||||||
logger.debug(wording.get('clearing_temp'), __name__)
|
logger.debug(wording.get('clearing_temp'), __name__)
|
||||||
clear_temp_directory(state_manager.get_item('target_path'))
|
clear_temp_directory(state_manager.get_item('target_path'))
|
||||||
# create temp
|
|
||||||
logger.debug(wording.get('creating_temp'), __name__)
|
logger.debug(wording.get('creating_temp'), __name__)
|
||||||
create_temp_directory(state_manager.get_item('target_path'))
|
create_temp_directory(state_manager.get_item('target_path'))
|
||||||
# extract frames
|
|
||||||
process_manager.start()
|
process_manager.start()
|
||||||
temp_video_resolution = pack_resolution(restrict_video_resolution(state_manager.get_item('target_path'), unpack_resolution(state_manager.get_item('output_video_resolution'))))
|
temp_video_resolution = pack_resolution(restrict_video_resolution(state_manager.get_item('target_path'), unpack_resolution(state_manager.get_item('output_video_resolution'))))
|
||||||
temp_video_fps = restrict_video_fps(state_manager.get_item('target_path'), state_manager.get_item('output_video_fps'))
|
temp_video_fps = restrict_video_fps(state_manager.get_item('target_path'), state_manager.get_item('output_video_fps'))
|
||||||
logger.info(wording.get('extracting_frames').format(resolution = temp_video_resolution, fps = temp_video_fps), __name__)
|
logger.info(wording.get('extracting_frames').format(resolution = temp_video_resolution, fps = temp_video_fps), __name__)
|
||||||
if extract_frames(state_manager.get_item('target_path'), temp_video_resolution, temp_video_fps):
|
if extract_frames(state_manager.get_item('target_path'), temp_video_resolution, temp_video_fps, trim_frame_start, trim_frame_end):
|
||||||
logger.debug(wording.get('extracting_frames_succeed'), __name__)
|
logger.debug(wording.get('extracting_frames_succeed'), __name__)
|
||||||
else:
|
else:
|
||||||
if is_process_stopping():
|
if is_process_stopping():
|
||||||
@@ -374,8 +436,8 @@ def process_video(start_time : float) -> ErrorCode:
|
|||||||
logger.error(wording.get('extracting_frames_failed'), __name__)
|
logger.error(wording.get('extracting_frames_failed'), __name__)
|
||||||
process_manager.end()
|
process_manager.end()
|
||||||
return 1
|
return 1
|
||||||
# process frames
|
|
||||||
temp_frame_paths = get_temp_frame_paths(state_manager.get_item('target_path'))
|
temp_frame_paths = resolve_temp_frame_paths(state_manager.get_item('target_path'))
|
||||||
if temp_frame_paths:
|
if temp_frame_paths:
|
||||||
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
||||||
logger.info(wording.get('processing'), processor_module.__name__)
|
logger.info(wording.get('processing'), processor_module.__name__)
|
||||||
@@ -387,9 +449,9 @@ def process_video(start_time : float) -> ErrorCode:
|
|||||||
logger.error(wording.get('temp_frames_not_found'), __name__)
|
logger.error(wording.get('temp_frames_not_found'), __name__)
|
||||||
process_manager.end()
|
process_manager.end()
|
||||||
return 1
|
return 1
|
||||||
# merge video
|
|
||||||
logger.info(wording.get('merging_video').format(resolution = state_manager.get_item('output_video_resolution'), fps = state_manager.get_item('output_video_fps')), __name__)
|
logger.info(wording.get('merging_video').format(resolution = state_manager.get_item('output_video_resolution'), fps = state_manager.get_item('output_video_fps')), __name__)
|
||||||
if merge_video(state_manager.get_item('target_path'), state_manager.get_item('output_video_resolution'), state_manager.get_item('output_video_fps')):
|
if merge_video(state_manager.get_item('target_path'), temp_video_fps, state_manager.get_item('output_video_resolution'), state_manager.get_item('output_video_fps'), trim_frame_start, trim_frame_end):
|
||||||
logger.debug(wording.get('merging_video_succeed'), __name__)
|
logger.debug(wording.get('merging_video_succeed'), __name__)
|
||||||
else:
|
else:
|
||||||
if is_process_stopping():
|
if is_process_stopping():
|
||||||
@@ -398,8 +460,8 @@ def process_video(start_time : float) -> ErrorCode:
|
|||||||
logger.error(wording.get('merging_video_failed'), __name__)
|
logger.error(wording.get('merging_video_failed'), __name__)
|
||||||
process_manager.end()
|
process_manager.end()
|
||||||
return 1
|
return 1
|
||||||
# handle audio
|
|
||||||
if state_manager.get_item('skip_audio'):
|
if state_manager.get_item('output_audio_volume') == 0:
|
||||||
logger.info(wording.get('skipping_audio'), __name__)
|
logger.info(wording.get('skipping_audio'), __name__)
|
||||||
move_temp_file(state_manager.get_item('target_path'), state_manager.get_item('output_path'))
|
move_temp_file(state_manager.get_item('target_path'), state_manager.get_item('output_path'))
|
||||||
else:
|
else:
|
||||||
@@ -414,7 +476,7 @@ def process_video(start_time : float) -> ErrorCode:
|
|||||||
logger.warn(wording.get('replacing_audio_skipped'), __name__)
|
logger.warn(wording.get('replacing_audio_skipped'), __name__)
|
||||||
move_temp_file(state_manager.get_item('target_path'), state_manager.get_item('output_path'))
|
move_temp_file(state_manager.get_item('target_path'), state_manager.get_item('output_path'))
|
||||||
else:
|
else:
|
||||||
if restore_audio(state_manager.get_item('target_path'), state_manager.get_item('output_path'), state_manager.get_item('output_video_fps')):
|
if restore_audio(state_manager.get_item('target_path'), state_manager.get_item('output_path'), trim_frame_start, trim_frame_end):
|
||||||
logger.debug(wording.get('restoring_audio_succeed'), __name__)
|
logger.debug(wording.get('restoring_audio_succeed'), __name__)
|
||||||
else:
|
else:
|
||||||
if is_process_stopping():
|
if is_process_stopping():
|
||||||
@@ -422,10 +484,10 @@ def process_video(start_time : float) -> ErrorCode:
|
|||||||
return 4
|
return 4
|
||||||
logger.warn(wording.get('restoring_audio_skipped'), __name__)
|
logger.warn(wording.get('restoring_audio_skipped'), __name__)
|
||||||
move_temp_file(state_manager.get_item('target_path'), state_manager.get_item('output_path'))
|
move_temp_file(state_manager.get_item('target_path'), state_manager.get_item('output_path'))
|
||||||
# clear temp
|
|
||||||
logger.debug(wording.get('clearing_temp'), __name__)
|
logger.debug(wording.get('clearing_temp'), __name__)
|
||||||
clear_temp_directory(state_manager.get_item('target_path'))
|
clear_temp_directory(state_manager.get_item('target_path'))
|
||||||
# validate video
|
|
||||||
if is_video(state_manager.get_item('output_path')):
|
if is_video(state_manager.get_item('output_path')):
|
||||||
seconds = '{:.2f}'.format((time() - start_time))
|
seconds = '{:.2f}'.format((time() - start_time))
|
||||||
logger.info(wording.get('processing_video_succeed').format(seconds = seconds), __name__)
|
logger.info(wording.get('processing_video_succeed').format(seconds = seconds), __name__)
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import itertools
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from facefusion import metadata
|
||||||
|
from facefusion.types import Commands
|
||||||
|
|
||||||
|
|
||||||
|
def run(commands : Commands) -> Commands:
|
||||||
|
user_agent = metadata.get('name') + '/' + metadata.get('version')
|
||||||
|
|
||||||
|
return [ shutil.which('curl'), '--user-agent', user_agent, '--insecure', '--location', '--silent' ] + commands
|
||||||
|
|
||||||
|
|
||||||
|
def chain(*commands : Commands) -> Commands:
|
||||||
|
return list(itertools.chain(*commands))
|
||||||
|
|
||||||
|
|
||||||
|
def head(url : str) -> Commands:
|
||||||
|
return [ '-I', url ]
|
||||||
|
|
||||||
|
|
||||||
|
def download(url : str, download_file_path : str) -> Commands:
|
||||||
|
return [ '--create-dirs', '--continue-at', '-', '--output', download_file_path, url ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_timeout(timeout : int) -> Commands:
|
||||||
|
return [ '--connect-timeout', str(timeout) ]
|
||||||
+87
-44
@@ -1,22 +1,21 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import ssl
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import urllib.request
|
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from typing import List, Tuple
|
from typing import List, Optional, Tuple
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from facefusion import logger, process_manager, state_manager, wording
|
import facefusion.choices
|
||||||
from facefusion.common_helper import is_macos
|
from facefusion import curl_builder, logger, process_manager, state_manager, wording
|
||||||
from facefusion.filesystem import get_file_size, is_file, remove_file
|
from facefusion.filesystem import get_file_name, get_file_size, is_file, remove_file
|
||||||
from facefusion.hash_helper import validate_hash
|
from facefusion.hash_helper import validate_hash
|
||||||
from facefusion.typing import DownloadSet
|
from facefusion.types import Commands, DownloadProvider, DownloadSet
|
||||||
|
|
||||||
if is_macos():
|
|
||||||
ssl._create_default_https_context = ssl._create_unverified_context
|
def open_curl(commands : Commands) -> subprocess.Popen[bytes]:
|
||||||
|
commands = curl_builder.run(commands)
|
||||||
|
return subprocess.Popen(commands, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
|
||||||
|
|
||||||
|
|
||||||
def conditional_download(download_directory_path : str, urls : List[str]) -> None:
|
def conditional_download(download_directory_path : str, urls : List[str]) -> None:
|
||||||
@@ -24,14 +23,18 @@ def conditional_download(download_directory_path : str, urls : List[str]) -> Non
|
|||||||
download_file_name = os.path.basename(urlparse(url).path)
|
download_file_name = os.path.basename(urlparse(url).path)
|
||||||
download_file_path = os.path.join(download_directory_path, download_file_name)
|
download_file_path = os.path.join(download_directory_path, download_file_name)
|
||||||
initial_size = get_file_size(download_file_path)
|
initial_size = get_file_size(download_file_path)
|
||||||
download_size = get_download_size(url)
|
download_size = get_static_download_size(url)
|
||||||
|
|
||||||
if initial_size < download_size:
|
if initial_size < download_size:
|
||||||
with tqdm(total = download_size, initial = initial_size, desc = wording.get('downloading'), unit = 'B', unit_scale = True, unit_divisor = 1024, ascii = ' =', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress:
|
with tqdm(total = download_size, initial = initial_size, desc = wording.get('downloading'), unit = 'B', unit_scale = True, unit_divisor = 1024, ascii = ' =', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress:
|
||||||
subprocess.Popen([ shutil.which('curl'), '--create-dirs', '--silent', '--insecure', '--location', '--continue-at', '-', '--output', download_file_path, url ])
|
commands = curl_builder.chain(
|
||||||
|
curl_builder.download(url, download_file_path),
|
||||||
|
curl_builder.set_timeout(10)
|
||||||
|
)
|
||||||
|
open_curl(commands)
|
||||||
current_size = initial_size
|
current_size = initial_size
|
||||||
|
progress.set_postfix(download_providers = state_manager.get_item('download_providers'), file_name = download_file_name)
|
||||||
|
|
||||||
progress.set_postfix(file = download_file_name)
|
|
||||||
while current_size < download_size:
|
while current_size < download_size:
|
||||||
if is_file(download_file_path):
|
if is_file(download_file_path):
|
||||||
current_size = get_file_size(download_file_path)
|
current_size = get_file_size(download_file_path)
|
||||||
@@ -39,39 +42,54 @@ def conditional_download(download_directory_path : str, urls : List[str]) -> Non
|
|||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize = None)
|
@lru_cache(maxsize = None)
|
||||||
def get_download_size(url : str) -> int:
|
def get_static_download_size(url : str) -> int:
|
||||||
try:
|
commands = curl_builder.chain(
|
||||||
response = urllib.request.urlopen(url, timeout = 10)
|
curl_builder.head(url),
|
||||||
content_length = response.headers.get('Content-Length')
|
curl_builder.set_timeout(5)
|
||||||
return int(content_length)
|
)
|
||||||
except (OSError, TypeError, ValueError):
|
process = open_curl(commands)
|
||||||
return 0
|
lines = reversed(process.stdout.readlines())
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
__line__ = line.decode().lower()
|
||||||
|
if 'content-length:' in __line__:
|
||||||
|
_, content_length = __line__.split('content-length:')
|
||||||
|
return int(content_length)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def is_download_done(url : str, file_path : str) -> bool:
|
@lru_cache(maxsize = None)
|
||||||
if is_file(file_path):
|
def ping_static_url(url : str) -> bool:
|
||||||
return get_download_size(url) == get_file_size(file_path)
|
commands = curl_builder.chain(
|
||||||
return False
|
curl_builder.head(url),
|
||||||
|
curl_builder.set_timeout(5)
|
||||||
|
)
|
||||||
|
process = open_curl(commands)
|
||||||
|
process.communicate()
|
||||||
|
return process.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
def conditional_download_hashes(download_directory_path : str, hashes : DownloadSet) -> bool:
|
def conditional_download_hashes(hash_set : DownloadSet) -> bool:
|
||||||
hash_paths = [ hashes.get(hash_key).get('path') for hash_key in hashes.keys() ]
|
hash_paths = [ hash_set.get(hash_key).get('path') for hash_key in hash_set.keys() ]
|
||||||
|
|
||||||
process_manager.check()
|
process_manager.check()
|
||||||
if not state_manager.get_item('skip_download'):
|
_, invalid_hash_paths = validate_hash_paths(hash_paths)
|
||||||
_, invalid_hash_paths = validate_hash_paths(hash_paths)
|
if invalid_hash_paths:
|
||||||
if invalid_hash_paths:
|
for index in hash_set:
|
||||||
for index in hashes:
|
if hash_set.get(index).get('path') in invalid_hash_paths:
|
||||||
if hashes.get(index).get('path') in invalid_hash_paths:
|
invalid_hash_url = hash_set.get(index).get('url')
|
||||||
invalid_hash_url = hashes.get(index).get('url')
|
if invalid_hash_url:
|
||||||
|
download_directory_path = os.path.dirname(hash_set.get(index).get('path'))
|
||||||
conditional_download(download_directory_path, [ invalid_hash_url ])
|
conditional_download(download_directory_path, [ invalid_hash_url ])
|
||||||
|
|
||||||
valid_hash_paths, invalid_hash_paths = validate_hash_paths(hash_paths)
|
valid_hash_paths, invalid_hash_paths = validate_hash_paths(hash_paths)
|
||||||
|
|
||||||
for valid_hash_path in valid_hash_paths:
|
for valid_hash_path in valid_hash_paths:
|
||||||
valid_hash_file_name, _ = os.path.splitext(os.path.basename(valid_hash_path))
|
valid_hash_file_name = get_file_name(valid_hash_path)
|
||||||
logger.debug(wording.get('validating_hash_succeed').format(hash_file_name = valid_hash_file_name), __name__)
|
logger.debug(wording.get('validating_hash_succeed').format(hash_file_name = valid_hash_file_name), __name__)
|
||||||
for invalid_hash_path in invalid_hash_paths:
|
for invalid_hash_path in invalid_hash_paths:
|
||||||
invalid_hash_file_name, _ = os.path.splitext(os.path.basename(invalid_hash_path))
|
invalid_hash_file_name = get_file_name(invalid_hash_path)
|
||||||
logger.error(wording.get('validating_hash_failed').format(hash_file_name = invalid_hash_file_name), __name__)
|
logger.error(wording.get('validating_hash_failed').format(hash_file_name = invalid_hash_file_name), __name__)
|
||||||
|
|
||||||
if not invalid_hash_paths:
|
if not invalid_hash_paths:
|
||||||
@@ -79,24 +97,26 @@ def conditional_download_hashes(download_directory_path : str, hashes : Download
|
|||||||
return not invalid_hash_paths
|
return not invalid_hash_paths
|
||||||
|
|
||||||
|
|
||||||
def conditional_download_sources(download_directory_path : str, sources : DownloadSet) -> bool:
|
def conditional_download_sources(source_set : DownloadSet) -> bool:
|
||||||
source_paths = [ sources.get(source_key).get('path') for source_key in sources.keys() ]
|
source_paths = [ source_set.get(source_key).get('path') for source_key in source_set.keys() ]
|
||||||
|
|
||||||
process_manager.check()
|
process_manager.check()
|
||||||
if not state_manager.get_item('skip_download'):
|
_, invalid_source_paths = validate_source_paths(source_paths)
|
||||||
_, invalid_source_paths = validate_source_paths(source_paths)
|
if invalid_source_paths:
|
||||||
if invalid_source_paths:
|
for index in source_set:
|
||||||
for index in sources:
|
if source_set.get(index).get('path') in invalid_source_paths:
|
||||||
if sources.get(index).get('path') in invalid_source_paths:
|
invalid_source_url = source_set.get(index).get('url')
|
||||||
invalid_source_url = sources.get(index).get('url')
|
if invalid_source_url:
|
||||||
|
download_directory_path = os.path.dirname(source_set.get(index).get('path'))
|
||||||
conditional_download(download_directory_path, [ invalid_source_url ])
|
conditional_download(download_directory_path, [ invalid_source_url ])
|
||||||
|
|
||||||
valid_source_paths, invalid_source_paths = validate_source_paths(source_paths)
|
valid_source_paths, invalid_source_paths = validate_source_paths(source_paths)
|
||||||
|
|
||||||
for valid_source_path in valid_source_paths:
|
for valid_source_path in valid_source_paths:
|
||||||
valid_source_file_name, _ = os.path.splitext(os.path.basename(valid_source_path))
|
valid_source_file_name = get_file_name(valid_source_path)
|
||||||
logger.debug(wording.get('validating_source_succeed').format(source_file_name = valid_source_file_name), __name__)
|
logger.debug(wording.get('validating_source_succeed').format(source_file_name = valid_source_file_name), __name__)
|
||||||
for invalid_source_path in invalid_source_paths:
|
for invalid_source_path in invalid_source_paths:
|
||||||
invalid_source_file_name, _ = os.path.splitext(os.path.basename(invalid_source_path))
|
invalid_source_file_name = get_file_name(invalid_source_path)
|
||||||
logger.error(wording.get('validating_source_failed').format(source_file_name = invalid_source_file_name), __name__)
|
logger.error(wording.get('validating_source_failed').format(source_file_name = invalid_source_file_name), __name__)
|
||||||
|
|
||||||
if remove_file(invalid_source_path):
|
if remove_file(invalid_source_path):
|
||||||
@@ -116,6 +136,7 @@ def validate_hash_paths(hash_paths : List[str]) -> Tuple[List[str], List[str]]:
|
|||||||
valid_hash_paths.append(hash_path)
|
valid_hash_paths.append(hash_path)
|
||||||
else:
|
else:
|
||||||
invalid_hash_paths.append(hash_path)
|
invalid_hash_paths.append(hash_path)
|
||||||
|
|
||||||
return valid_hash_paths, invalid_hash_paths
|
return valid_hash_paths, invalid_hash_paths
|
||||||
|
|
||||||
|
|
||||||
@@ -128,4 +149,26 @@ def validate_source_paths(source_paths : List[str]) -> Tuple[List[str], List[str
|
|||||||
valid_source_paths.append(source_path)
|
valid_source_paths.append(source_path)
|
||||||
else:
|
else:
|
||||||
invalid_source_paths.append(source_path)
|
invalid_source_paths.append(source_path)
|
||||||
|
|
||||||
return valid_source_paths, invalid_source_paths
|
return valid_source_paths, invalid_source_paths
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_download_url(base_name : str, file_name : str) -> Optional[str]:
|
||||||
|
download_providers = state_manager.get_item('download_providers')
|
||||||
|
|
||||||
|
for download_provider in download_providers:
|
||||||
|
download_url = resolve_download_url_by_provider(download_provider, base_name, file_name)
|
||||||
|
if download_url:
|
||||||
|
return download_url
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_download_url_by_provider(download_provider : DownloadProvider, base_name : str, file_name : str) -> Optional[str]:
|
||||||
|
download_provider_value = facefusion.choices.download_provider_set.get(download_provider)
|
||||||
|
|
||||||
|
for download_provider_url in download_provider_value.get('urls'):
|
||||||
|
if ping_static_url(download_provider_url):
|
||||||
|
return download_provider_url + download_provider_value.get('path').format(base_name = base_name, file_name = file_name)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|||||||
+78
-56
@@ -1,46 +1,45 @@
|
|||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import xml.etree.ElementTree as ElementTree
|
import xml.etree.ElementTree as ElementTree
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from typing import Any, List
|
from typing import List, Optional
|
||||||
|
|
||||||
from onnxruntime import get_available_providers, set_default_logger_severity
|
from onnxruntime import get_available_providers, set_default_logger_severity
|
||||||
|
|
||||||
from facefusion.choices import execution_provider_set
|
import facefusion.choices
|
||||||
from facefusion.typing import ExecutionDevice, ExecutionProviderKey, ExecutionProviderSet, ValueAndUnit
|
from facefusion.types import ExecutionDevice, ExecutionProvider, InferenceSessionProvider, ValueAndUnit
|
||||||
|
|
||||||
set_default_logger_severity(3)
|
set_default_logger_severity(3)
|
||||||
|
|
||||||
|
|
||||||
def get_execution_provider_choices() -> List[ExecutionProviderKey]:
|
def has_execution_provider(execution_provider : ExecutionProvider) -> bool:
|
||||||
return list(get_available_execution_provider_set().keys())
|
return execution_provider in get_available_execution_providers()
|
||||||
|
|
||||||
|
|
||||||
def has_execution_provider(execution_provider_key : ExecutionProviderKey) -> bool:
|
def get_available_execution_providers() -> List[ExecutionProvider]:
|
||||||
return execution_provider_key in get_execution_provider_choices()
|
inference_session_providers = get_available_providers()
|
||||||
|
available_execution_providers : List[ExecutionProvider] = []
|
||||||
|
|
||||||
|
for execution_provider, execution_provider_value in facefusion.choices.execution_provider_set.items():
|
||||||
|
if execution_provider_value in inference_session_providers:
|
||||||
|
index = facefusion.choices.execution_providers.index(execution_provider)
|
||||||
|
available_execution_providers.insert(index, execution_provider)
|
||||||
|
|
||||||
|
return available_execution_providers
|
||||||
|
|
||||||
|
|
||||||
def get_available_execution_provider_set() -> ExecutionProviderSet:
|
def create_inference_session_providers(execution_device_id : str, execution_providers : List[ExecutionProvider]) -> List[InferenceSessionProvider]:
|
||||||
available_execution_providers = get_available_providers()
|
inference_session_providers : List[InferenceSessionProvider] = []
|
||||||
available_execution_provider_set : ExecutionProviderSet = {}
|
|
||||||
|
|
||||||
for execution_provider_key, execution_provider_value in execution_provider_set.items():
|
for execution_provider in execution_providers:
|
||||||
if execution_provider_value in available_execution_providers:
|
if execution_provider == 'cuda':
|
||||||
available_execution_provider_set[execution_provider_key] = execution_provider_value
|
inference_session_providers.append((facefusion.choices.execution_provider_set.get(execution_provider),
|
||||||
return available_execution_provider_set
|
|
||||||
|
|
||||||
|
|
||||||
def create_execution_providers(execution_device_id : str, execution_provider_keys : List[ExecutionProviderKey]) -> List[Any]:
|
|
||||||
execution_providers : List[Any] = []
|
|
||||||
|
|
||||||
for execution_provider_key in execution_provider_keys:
|
|
||||||
if execution_provider_key == 'cuda':
|
|
||||||
execution_providers.append((execution_provider_set.get(execution_provider_key),
|
|
||||||
{
|
{
|
||||||
'device_id': execution_device_id,
|
'device_id': execution_device_id,
|
||||||
'cudnn_conv_algo_search': 'EXHAUSTIVE' if use_exhaustive() else 'DEFAULT'
|
'cudnn_conv_algo_search': resolve_cudnn_conv_algo_search()
|
||||||
}))
|
}))
|
||||||
if execution_provider_key == 'tensorrt':
|
if execution_provider == 'tensorrt':
|
||||||
execution_providers.append((execution_provider_set.get(execution_provider_key),
|
inference_session_providers.append((facefusion.choices.execution_provider_set.get(execution_provider),
|
||||||
{
|
{
|
||||||
'device_id': execution_device_id,
|
'device_id': execution_device_id,
|
||||||
'trt_engine_cache_enable': True,
|
'trt_engine_cache_enable': True,
|
||||||
@@ -49,35 +48,51 @@ def create_execution_providers(execution_device_id : str, execution_provider_key
|
|||||||
'trt_timing_cache_path': '.caches',
|
'trt_timing_cache_path': '.caches',
|
||||||
'trt_builder_optimization_level': 5
|
'trt_builder_optimization_level': 5
|
||||||
}))
|
}))
|
||||||
if execution_provider_key == 'openvino':
|
if execution_provider in [ 'directml', 'rocm' ]:
|
||||||
execution_providers.append((execution_provider_set.get(execution_provider_key),
|
inference_session_providers.append((facefusion.choices.execution_provider_set.get(execution_provider),
|
||||||
{
|
|
||||||
'device_type': 'GPU.' + execution_device_id,
|
|
||||||
'precision': 'FP32'
|
|
||||||
}))
|
|
||||||
if execution_provider_key in [ 'directml', 'rocm' ]:
|
|
||||||
execution_providers.append((execution_provider_set.get(execution_provider_key),
|
|
||||||
{
|
{
|
||||||
'device_id': execution_device_id
|
'device_id': execution_device_id
|
||||||
}))
|
}))
|
||||||
if execution_provider_key == 'coreml':
|
if execution_provider == 'openvino':
|
||||||
execution_providers.append(execution_provider_set.get(execution_provider_key))
|
inference_session_providers.append((facefusion.choices.execution_provider_set.get(execution_provider),
|
||||||
|
{
|
||||||
|
'device_type': resolve_openvino_device_type(execution_device_id),
|
||||||
|
'precision': 'FP32'
|
||||||
|
}))
|
||||||
|
if execution_provider == 'coreml':
|
||||||
|
inference_session_providers.append((facefusion.choices.execution_provider_set.get(execution_provider),
|
||||||
|
{
|
||||||
|
'SpecializationStrategy': 'FastPrediction',
|
||||||
|
'ModelCacheDirectory': '.caches'
|
||||||
|
}))
|
||||||
|
|
||||||
if 'cpu' in execution_provider_keys:
|
if 'cpu' in execution_providers:
|
||||||
execution_providers.append(execution_provider_set.get('cpu'))
|
inference_session_providers.append(facefusion.choices.execution_provider_set.get('cpu'))
|
||||||
|
|
||||||
return execution_providers
|
return inference_session_providers
|
||||||
|
|
||||||
|
|
||||||
def use_exhaustive() -> bool:
|
def resolve_cudnn_conv_algo_search() -> str:
|
||||||
execution_devices = detect_static_execution_devices()
|
execution_devices = detect_static_execution_devices()
|
||||||
product_names = ('GeForce GTX 1630', 'GeForce GTX 1650', 'GeForce GTX 1660')
|
product_names = ('GeForce GTX 1630', 'GeForce GTX 1650', 'GeForce GTX 1660')
|
||||||
|
|
||||||
return any(execution_device.get('product').get('name').startswith(product_names) for execution_device in execution_devices)
|
for execution_device in execution_devices:
|
||||||
|
if execution_device.get('product').get('name').startswith(product_names):
|
||||||
|
return 'DEFAULT'
|
||||||
|
|
||||||
|
return 'EXHAUSTIVE'
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_openvino_device_type(execution_device_id : str) -> str:
|
||||||
|
if execution_device_id == '0':
|
||||||
|
return 'GPU'
|
||||||
|
if execution_device_id == '∞':
|
||||||
|
return 'MULTI:GPU'
|
||||||
|
return 'GPU.' + execution_device_id
|
||||||
|
|
||||||
|
|
||||||
def run_nvidia_smi() -> subprocess.Popen[bytes]:
|
def run_nvidia_smi() -> subprocess.Popen[bytes]:
|
||||||
commands = [ 'nvidia-smi', '--query', '--xml-format' ]
|
commands = [ shutil.which('nvidia-smi'), '--query', '--xml-format' ]
|
||||||
return subprocess.Popen(commands, stdout = subprocess.PIPE)
|
return subprocess.Popen(commands, stdout = subprocess.PIPE)
|
||||||
|
|
||||||
|
|
||||||
@@ -98,37 +113,44 @@ def detect_execution_devices() -> List[ExecutionDevice]:
|
|||||||
for gpu_element in root_element.findall('gpu'):
|
for gpu_element in root_element.findall('gpu'):
|
||||||
execution_devices.append(
|
execution_devices.append(
|
||||||
{
|
{
|
||||||
'driver_version': root_element.find('driver_version').text,
|
'driver_version': root_element.findtext('driver_version'),
|
||||||
'framework':
|
'framework':
|
||||||
{
|
{
|
||||||
'name': 'CUDA',
|
'name': 'CUDA',
|
||||||
'version': root_element.find('cuda_version').text
|
'version': root_element.findtext('cuda_version')
|
||||||
},
|
},
|
||||||
'product':
|
'product':
|
||||||
{
|
{
|
||||||
'vendor': 'NVIDIA',
|
'vendor': 'NVIDIA',
|
||||||
'name': gpu_element.find('product_name').text.replace('NVIDIA ', '')
|
'name': gpu_element.findtext('product_name').replace('NVIDIA', '').strip()
|
||||||
},
|
},
|
||||||
'video_memory':
|
'video_memory':
|
||||||
{
|
{
|
||||||
'total': create_value_and_unit(gpu_element.find('fb_memory_usage/total').text),
|
'total': create_value_and_unit(gpu_element.findtext('fb_memory_usage/total')),
|
||||||
'free': create_value_and_unit(gpu_element.find('fb_memory_usage/free').text)
|
'free': create_value_and_unit(gpu_element.findtext('fb_memory_usage/free'))
|
||||||
|
},
|
||||||
|
'temperature':
|
||||||
|
{
|
||||||
|
'gpu': create_value_and_unit(gpu_element.findtext('temperature/gpu_temp')),
|
||||||
|
'memory': create_value_and_unit(gpu_element.findtext('temperature/memory_temp'))
|
||||||
},
|
},
|
||||||
'utilization':
|
'utilization':
|
||||||
{
|
{
|
||||||
'gpu': create_value_and_unit(gpu_element.find('utilization/gpu_util').text),
|
'gpu': create_value_and_unit(gpu_element.findtext('utilization/gpu_util')),
|
||||||
'memory': create_value_and_unit(gpu_element.find('utilization/memory_util').text)
|
'memory': create_value_and_unit(gpu_element.findtext('utilization/memory_util'))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return execution_devices
|
return execution_devices
|
||||||
|
|
||||||
|
|
||||||
def create_value_and_unit(text : str) -> ValueAndUnit:
|
def create_value_and_unit(text : str) -> Optional[ValueAndUnit]:
|
||||||
value, unit = text.split()
|
if ' ' in text:
|
||||||
value_and_unit : ValueAndUnit =\
|
value, unit = text.split()
|
||||||
{
|
|
||||||
'value': int(value),
|
|
||||||
'unit': str(unit)
|
|
||||||
}
|
|
||||||
|
|
||||||
return value_and_unit
|
return\
|
||||||
|
{
|
||||||
|
'value': int(value),
|
||||||
|
'unit': str(unit)
|
||||||
|
}
|
||||||
|
return None
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
|
import signal
|
||||||
import sys
|
import sys
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from facefusion import process_manager, state_manager
|
from facefusion import process_manager, state_manager
|
||||||
from facefusion.temp_helper import clear_temp_directory
|
from facefusion.temp_helper import clear_temp_directory
|
||||||
from facefusion.typing import ErrorCode
|
from facefusion.types import ErrorCode
|
||||||
|
|
||||||
|
|
||||||
def hard_exit(error_code : ErrorCode) -> None:
|
def hard_exit(error_code : ErrorCode) -> None:
|
||||||
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||||
sys.exit(error_code)
|
sys.exit(error_code)
|
||||||
|
|
||||||
|
|
||||||
def conditional_exit(error_code : ErrorCode) -> None:
|
|
||||||
if state_manager.get_item('command') == 'headless-run':
|
|
||||||
hard_exit(error_code)
|
|
||||||
|
|
||||||
|
|
||||||
def graceful_exit(error_code : ErrorCode) -> None:
|
def graceful_exit(error_code : ErrorCode) -> None:
|
||||||
process_manager.stop()
|
process_manager.stop()
|
||||||
while process_manager.is_processing():
|
while process_manager.is_processing():
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ from facefusion.common_helper import get_first
|
|||||||
from facefusion.face_classifier import classify_face
|
from facefusion.face_classifier import classify_face
|
||||||
from facefusion.face_detector import detect_faces, detect_rotated_faces
|
from facefusion.face_detector import detect_faces, detect_rotated_faces
|
||||||
from facefusion.face_helper import apply_nms, convert_to_face_landmark_5, estimate_face_angle, get_nms_threshold
|
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_landmarks, estimate_face_landmark_68_5
|
from facefusion.face_landmarker import detect_face_landmark, estimate_face_landmark_68_5
|
||||||
from facefusion.face_recognizer import calc_embedding
|
from facefusion.face_recognizer import calc_embedding
|
||||||
from facefusion.face_store import get_static_faces, set_static_faces
|
from facefusion.face_store import get_static_faces, set_static_faces
|
||||||
from facefusion.typing import BoundingBox, Face, FaceLandmark5, FaceLandmarkSet, FaceScoreSet, Score, VisionFrame
|
from facefusion.types import BoundingBox, Face, FaceLandmark5, FaceLandmarkSet, FaceScoreSet, Score, VisionFrame
|
||||||
|
|
||||||
|
|
||||||
def create_faces(vision_frame : VisionFrame, bounding_boxes : List[BoundingBox], face_scores : List[Score], face_landmarks_5 : List[FaceLandmark5]) -> List[Face]:
|
def create_faces(vision_frame : VisionFrame, bounding_boxes : List[BoundingBox], face_scores : List[Score], face_landmarks_5 : List[FaceLandmark5]) -> List[Face]:
|
||||||
@@ -29,7 +29,7 @@ def create_faces(vision_frame : VisionFrame, bounding_boxes : List[BoundingBox],
|
|||||||
face_angle = estimate_face_angle(face_landmark_68_5)
|
face_angle = estimate_face_angle(face_landmark_68_5)
|
||||||
|
|
||||||
if state_manager.get_item('face_landmarker_score') > 0:
|
if state_manager.get_item('face_landmarker_score') > 0:
|
||||||
face_landmark_68, face_landmark_score_68 = detect_face_landmarks(vision_frame, bounding_box, face_angle)
|
face_landmark_68, face_landmark_score_68 = detect_face_landmark(vision_frame, bounding_box, face_angle)
|
||||||
if face_landmark_score_68 > state_manager.get_item('face_landmarker_score'):
|
if face_landmark_score_68 > state_manager.get_item('face_landmarker_score'):
|
||||||
face_landmark_5_68 = convert_to_face_landmark_5(face_landmark_68)
|
face_landmark_5_68 = convert_to_face_landmark_5(face_landmark_68)
|
||||||
|
|
||||||
|
|||||||
@@ -1,61 +1,67 @@
|
|||||||
|
from functools import lru_cache
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
from facefusion import inference_manager
|
from facefusion import inference_manager
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
from facefusion.face_helper import warp_face_by_face_landmark_5
|
from facefusion.face_helper import warp_face_by_face_landmark_5
|
||||||
from facefusion.filesystem import resolve_relative_path
|
from facefusion.filesystem import resolve_relative_path
|
||||||
from facefusion.thread_helper import conditional_thread_semaphore
|
from facefusion.thread_helper import conditional_thread_semaphore
|
||||||
from facefusion.typing import Age, FaceLandmark5, Gender, InferencePool, ModelOptions, ModelSet, Race, VisionFrame
|
from facefusion.types import Age, DownloadScope, FaceLandmark5, Gender, InferencePool, ModelOptions, ModelSet, Race, VisionFrame
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'fairface':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'fairface':
|
||||||
{
|
{
|
||||||
'face_classifier':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fairface.hash',
|
'face_classifier':
|
||||||
'path': resolve_relative_path('../.assets/models/fairface.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'fairface.hash'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/fairface.hash')
|
||||||
'sources':
|
}
|
||||||
{
|
},
|
||||||
'face_classifier':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fairface.onnx',
|
'face_classifier':
|
||||||
'path': resolve_relative_path('../.assets/models/fairface.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'fairface.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/fairface.onnx')
|
||||||
'template': 'arcface_112_v2',
|
}
|
||||||
'size': (224, 224),
|
},
|
||||||
'mean': [ 0.485, 0.456, 0.406 ],
|
'template': 'arcface_112_v2',
|
||||||
'standard_deviation': [ 0.229, 0.224, 0.225 ]
|
'size': (224, 224),
|
||||||
|
'mean': [ 0.485, 0.456, 0.406 ],
|
||||||
|
'standard_deviation': [ 0.229, 0.224, 0.225 ]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
model_sources = get_model_options().get('sources')
|
model_names = [ 'fairface' ]
|
||||||
return inference_manager.get_inference_pool(__name__, model_sources)
|
model_source_set = get_model_options().get('sources')
|
||||||
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
inference_manager.clear_inference_pool(__name__)
|
model_names = [ 'fairface' ]
|
||||||
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def get_model_options() -> ModelOptions:
|
def get_model_options() -> ModelOptions:
|
||||||
return MODEL_SET.get('fairface')
|
return create_static_model_set('full').get('fairface')
|
||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set = get_model_options().get('hashes')
|
||||||
model_hashes = get_model_options().get('hashes')
|
model_source_set = get_model_options().get('sources')
|
||||||
model_sources = get_model_options().get('sources')
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def classify_face(temp_vision_frame : VisionFrame, face_landmark_5 : FaceLandmark5) -> Tuple[Gender, Age, Race]:
|
def classify_face(temp_vision_frame : VisionFrame, face_landmark_5 : FaceLandmark5) -> Tuple[Gender, Age, Race]:
|
||||||
@@ -64,7 +70,7 @@ def classify_face(temp_vision_frame : VisionFrame, face_landmark_5 : FaceLandmar
|
|||||||
model_mean = get_model_options().get('mean')
|
model_mean = get_model_options().get('mean')
|
||||||
model_standard_deviation = get_model_options().get('standard_deviation')
|
model_standard_deviation = get_model_options().get('standard_deviation')
|
||||||
crop_vision_frame, _ = warp_face_by_face_landmark_5(temp_vision_frame, face_landmark_5, model_template, model_size)
|
crop_vision_frame, _ = warp_face_by_face_landmark_5(temp_vision_frame, face_landmark_5, model_template, model_size)
|
||||||
crop_vision_frame = crop_vision_frame.astype(numpy.float32)[:, :, ::-1] / 255
|
crop_vision_frame = crop_vision_frame.astype(numpy.float32)[:, :, ::-1] / 255.0
|
||||||
crop_vision_frame -= model_mean
|
crop_vision_frame -= model_mean
|
||||||
crop_vision_frame /= model_standard_deviation
|
crop_vision_frame /= model_standard_deviation
|
||||||
crop_vision_frame = crop_vision_frame.transpose(2, 0, 1)
|
crop_vision_frame = crop_vision_frame.transpose(2, 0, 1)
|
||||||
|
|||||||
+129
-115
@@ -1,110 +1,111 @@
|
|||||||
from typing import List, Tuple
|
from functools import lru_cache
|
||||||
|
from typing import List, Sequence, Tuple
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
from facefusion import inference_manager, state_manager
|
from facefusion import inference_manager, state_manager
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
from facefusion.face_helper import create_rotated_matrix_and_size, create_static_anchors, distance_to_bounding_box, distance_to_face_landmark_5, normalize_bounding_box, transform_bounding_box, transform_points
|
from facefusion.face_helper import create_rotated_matrix_and_size, create_static_anchors, distance_to_bounding_box, distance_to_face_landmark_5, normalize_bounding_box, transform_bounding_box, transform_points
|
||||||
from facefusion.filesystem import resolve_relative_path
|
from facefusion.filesystem import resolve_relative_path
|
||||||
from facefusion.thread_helper import thread_semaphore
|
from facefusion.thread_helper import thread_semaphore
|
||||||
from facefusion.typing import Angle, BoundingBox, Detection, DownloadSet, FaceLandmark5, InferencePool, ModelSet, Score, VisionFrame
|
from facefusion.types import Angle, BoundingBox, Detection, DownloadScope, DownloadSet, FaceLandmark5, InferencePool, ModelSet, Score, VisionFrame
|
||||||
from facefusion.vision import resize_frame_resolution, unpack_resolution
|
from facefusion.vision import restrict_frame, unpack_resolution
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'retinaface':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'retinaface':
|
||||||
{
|
{
|
||||||
'retinaface':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/retinaface_10g.hash',
|
'retinaface':
|
||||||
'path': resolve_relative_path('../.assets/models/retinaface_10g.hash')
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'retinaface_10g.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/retinaface_10g.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'retinaface':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'retinaface_10g.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/retinaface_10g.onnx')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'sources':
|
'scrfd':
|
||||||
{
|
{
|
||||||
'retinaface':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/retinaface_10g.onnx',
|
'scrfd':
|
||||||
'path': resolve_relative_path('../.assets/models/retinaface_10g.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'scrfd_2.5g.hash'),
|
||||||
}
|
'path': resolve_relative_path('../.assets/models/scrfd_2.5g.hash')
|
||||||
},
|
}
|
||||||
'scrfd':
|
},
|
||||||
{
|
'sources':
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'scrfd':
|
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/scrfd_2.5g.hash',
|
'scrfd':
|
||||||
'path': resolve_relative_path('../.assets/models/scrfd_2.5g.hash')
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'scrfd_2.5g.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/scrfd_2.5g.onnx')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'sources':
|
'yolo_face':
|
||||||
{
|
{
|
||||||
'scrfd':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/scrfd_2.5g.onnx',
|
'yolo_face':
|
||||||
'path': resolve_relative_path('../.assets/models/scrfd_2.5g.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'yoloface_8n.hash'),
|
||||||
}
|
'path': resolve_relative_path('../.assets/models/yoloface_8n.hash')
|
||||||
},
|
}
|
||||||
'yoloface':
|
},
|
||||||
{
|
'sources':
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'yoloface':
|
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/yoloface_8n.hash',
|
'yolo_face':
|
||||||
'path': resolve_relative_path('../.assets/models/yoloface_8n.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'yoloface_8n.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/yoloface_8n.onnx')
|
||||||
'sources':
|
}
|
||||||
{
|
|
||||||
'yoloface':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/yoloface_8n.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/yoloface_8n.onnx')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
_, model_sources = collect_model_downloads()
|
model_names = [ state_manager.get_item('face_detector_model') ]
|
||||||
model_context = __name__ + '.' + state_manager.get_item('face_detector_model')
|
_, model_source_set = collect_model_downloads()
|
||||||
return inference_manager.get_inference_pool(model_context, model_sources)
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
model_context = __name__ + '.' + state_manager.get_item('face_detector_model')
|
model_names = [ state_manager.get_item('face_detector_model') ]
|
||||||
inference_manager.clear_inference_pool(model_context)
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def collect_model_downloads() -> Tuple[DownloadSet, DownloadSet]:
|
def collect_model_downloads() -> Tuple[DownloadSet, DownloadSet]:
|
||||||
model_hashes = {}
|
model_set = create_static_model_set('full')
|
||||||
model_sources = {}
|
model_hash_set = {}
|
||||||
|
model_source_set = {}
|
||||||
|
|
||||||
if state_manager.get_item('face_detector_model') in [ 'many', 'retinaface' ]:
|
for face_detector_model in [ 'retinaface', 'scrfd', 'yolo_face' ]:
|
||||||
model_hashes['retinaface'] = MODEL_SET.get('retinaface').get('hashes').get('retinaface')
|
if state_manager.get_item('face_detector_model') in [ 'many', face_detector_model ]:
|
||||||
model_sources['retinaface'] = MODEL_SET.get('retinaface').get('sources').get('retinaface')
|
model_hash_set[face_detector_model] = model_set.get(face_detector_model).get('hashes').get(face_detector_model)
|
||||||
if state_manager.get_item('face_detector_model') in [ 'many', 'scrfd' ]:
|
model_source_set[face_detector_model] = model_set.get(face_detector_model).get('sources').get(face_detector_model)
|
||||||
model_hashes['scrfd'] = MODEL_SET.get('scrfd').get('hashes').get('scrfd')
|
|
||||||
model_sources['scrfd'] = MODEL_SET.get('scrfd').get('sources').get('scrfd')
|
return model_hash_set, model_source_set
|
||||||
if state_manager.get_item('face_detector_model') in [ 'many', 'yoloface' ]:
|
|
||||||
model_hashes['yoloface'] = MODEL_SET.get('yoloface').get('hashes').get('yoloface')
|
|
||||||
model_sources['yoloface'] = MODEL_SET.get('yoloface').get('sources').get('yoloface')
|
|
||||||
return model_hashes, model_sources
|
|
||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set, model_source_set = collect_model_downloads()
|
||||||
model_hashes, model_sources = collect_model_downloads()
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def detect_faces(vision_frame : VisionFrame) -> Tuple[List[BoundingBox], List[Score], List[FaceLandmark5]]:
|
def detect_faces(vision_frame : VisionFrame) -> Tuple[List[BoundingBox], List[Score], List[FaceLandmark5]]:
|
||||||
@@ -124,8 +125,8 @@ def detect_faces(vision_frame : VisionFrame) -> Tuple[List[BoundingBox], List[Sc
|
|||||||
all_face_scores.extend(face_scores)
|
all_face_scores.extend(face_scores)
|
||||||
all_face_landmarks_5.extend(face_landmarks_5)
|
all_face_landmarks_5.extend(face_landmarks_5)
|
||||||
|
|
||||||
if state_manager.get_item('face_detector_model') in [ 'many', 'yoloface' ]:
|
if state_manager.get_item('face_detector_model') in [ 'many', 'yolo_face' ]:
|
||||||
bounding_boxes, face_scores, face_landmarks_5 = detect_with_yoloface(vision_frame, state_manager.get_item('face_detector_size'))
|
bounding_boxes, face_scores, face_landmarks_5 = detect_with_yolo_face(vision_frame, state_manager.get_item('face_detector_size'))
|
||||||
all_bounding_boxes.extend(bounding_boxes)
|
all_bounding_boxes.extend(bounding_boxes)
|
||||||
all_face_scores.extend(face_scores)
|
all_face_scores.extend(face_scores)
|
||||||
all_face_landmarks_5.extend(face_landmarks_5)
|
all_face_landmarks_5.extend(face_landmarks_5)
|
||||||
@@ -151,37 +152,39 @@ def detect_with_retinaface(vision_frame : VisionFrame, face_detector_size : str)
|
|||||||
feature_strides = [ 8, 16, 32 ]
|
feature_strides = [ 8, 16, 32 ]
|
||||||
feature_map_channel = 3
|
feature_map_channel = 3
|
||||||
anchor_total = 2
|
anchor_total = 2
|
||||||
|
face_detector_score = state_manager.get_item('face_detector_score')
|
||||||
face_detector_width, face_detector_height = unpack_resolution(face_detector_size)
|
face_detector_width, face_detector_height = unpack_resolution(face_detector_size)
|
||||||
temp_vision_frame = resize_frame_resolution(vision_frame, (face_detector_width, face_detector_height))
|
temp_vision_frame = restrict_frame(vision_frame, (face_detector_width, face_detector_height))
|
||||||
ratio_height = vision_frame.shape[0] / temp_vision_frame.shape[0]
|
ratio_height = vision_frame.shape[0] / temp_vision_frame.shape[0]
|
||||||
ratio_width = vision_frame.shape[1] / temp_vision_frame.shape[1]
|
ratio_width = vision_frame.shape[1] / temp_vision_frame.shape[1]
|
||||||
detect_vision_frame = prepare_detect_frame(temp_vision_frame, face_detector_size)
|
detect_vision_frame = prepare_detect_frame(temp_vision_frame, face_detector_size)
|
||||||
|
detect_vision_frame = normalize_detect_frame(detect_vision_frame, [ -1, 1 ])
|
||||||
detection = forward_with_retinaface(detect_vision_frame)
|
detection = forward_with_retinaface(detect_vision_frame)
|
||||||
|
|
||||||
for index, feature_stride in enumerate(feature_strides):
|
for index, feature_stride in enumerate(feature_strides):
|
||||||
keep_indices = numpy.where(detection[index] >= state_manager.get_item('face_detector_score'))[0]
|
keep_indices = numpy.where(detection[index] >= face_detector_score)[0]
|
||||||
|
|
||||||
if numpy.any(keep_indices):
|
if numpy.any(keep_indices):
|
||||||
stride_height = face_detector_height // feature_stride
|
stride_height = face_detector_height // feature_stride
|
||||||
stride_width = face_detector_width // feature_stride
|
stride_width = face_detector_width // feature_stride
|
||||||
anchors = create_static_anchors(feature_stride, anchor_total, stride_height, stride_width)
|
anchors = create_static_anchors(feature_stride, anchor_total, stride_height, stride_width)
|
||||||
bounding_box_raw = detection[index + feature_map_channel] * feature_stride
|
bounding_boxes_raw = detection[index + feature_map_channel] * feature_stride
|
||||||
face_landmark_5_raw = detection[index + feature_map_channel * 2] * feature_stride
|
face_landmarks_5_raw = detection[index + feature_map_channel * 2] * feature_stride
|
||||||
|
|
||||||
for bounding_box in distance_to_bounding_box(anchors, bounding_box_raw)[keep_indices]:
|
for bounding_box_raw in distance_to_bounding_box(anchors, bounding_boxes_raw)[keep_indices]:
|
||||||
bounding_boxes.append(numpy.array(
|
bounding_boxes.append(numpy.array(
|
||||||
[
|
[
|
||||||
bounding_box[0] * ratio_width,
|
bounding_box_raw[0] * ratio_width,
|
||||||
bounding_box[1] * ratio_height,
|
bounding_box_raw[1] * ratio_height,
|
||||||
bounding_box[2] * ratio_width,
|
bounding_box_raw[2] * ratio_width,
|
||||||
bounding_box[3] * ratio_height,
|
bounding_box_raw[3] * ratio_height
|
||||||
]))
|
]))
|
||||||
|
|
||||||
for score in detection[index][keep_indices]:
|
for face_score_raw in detection[index][keep_indices]:
|
||||||
face_scores.append(score[0])
|
face_scores.append(face_score_raw[0])
|
||||||
|
|
||||||
for face_landmark_5 in distance_to_face_landmark_5(anchors, face_landmark_5_raw)[keep_indices]:
|
for face_landmark_raw_5 in distance_to_face_landmark_5(anchors, face_landmarks_5_raw)[keep_indices]:
|
||||||
face_landmarks_5.append(face_landmark_5 * [ ratio_width, ratio_height ])
|
face_landmarks_5.append(face_landmark_raw_5 * [ ratio_width, ratio_height ])
|
||||||
|
|
||||||
return bounding_boxes, face_scores, face_landmarks_5
|
return bounding_boxes, face_scores, face_landmarks_5
|
||||||
|
|
||||||
@@ -193,73 +196,77 @@ def detect_with_scrfd(vision_frame : VisionFrame, face_detector_size : str) -> T
|
|||||||
feature_strides = [ 8, 16, 32 ]
|
feature_strides = [ 8, 16, 32 ]
|
||||||
feature_map_channel = 3
|
feature_map_channel = 3
|
||||||
anchor_total = 2
|
anchor_total = 2
|
||||||
|
face_detector_score = state_manager.get_item('face_detector_score')
|
||||||
face_detector_width, face_detector_height = unpack_resolution(face_detector_size)
|
face_detector_width, face_detector_height = unpack_resolution(face_detector_size)
|
||||||
temp_vision_frame = resize_frame_resolution(vision_frame, (face_detector_width, face_detector_height))
|
temp_vision_frame = restrict_frame(vision_frame, (face_detector_width, face_detector_height))
|
||||||
ratio_height = vision_frame.shape[0] / temp_vision_frame.shape[0]
|
ratio_height = vision_frame.shape[0] / temp_vision_frame.shape[0]
|
||||||
ratio_width = vision_frame.shape[1] / temp_vision_frame.shape[1]
|
ratio_width = vision_frame.shape[1] / temp_vision_frame.shape[1]
|
||||||
detect_vision_frame = prepare_detect_frame(temp_vision_frame, face_detector_size)
|
detect_vision_frame = prepare_detect_frame(temp_vision_frame, face_detector_size)
|
||||||
|
detect_vision_frame = normalize_detect_frame(detect_vision_frame, [ -1, 1 ])
|
||||||
detection = forward_with_scrfd(detect_vision_frame)
|
detection = forward_with_scrfd(detect_vision_frame)
|
||||||
|
|
||||||
for index, feature_stride in enumerate(feature_strides):
|
for index, feature_stride in enumerate(feature_strides):
|
||||||
keep_indices = numpy.where(detection[index] >= state_manager.get_item('face_detector_score'))[0]
|
keep_indices = numpy.where(detection[index] >= face_detector_score)[0]
|
||||||
|
|
||||||
if numpy.any(keep_indices):
|
if numpy.any(keep_indices):
|
||||||
stride_height = face_detector_height // feature_stride
|
stride_height = face_detector_height // feature_stride
|
||||||
stride_width = face_detector_width // feature_stride
|
stride_width = face_detector_width // feature_stride
|
||||||
anchors = create_static_anchors(feature_stride, anchor_total, stride_height, stride_width)
|
anchors = create_static_anchors(feature_stride, anchor_total, stride_height, stride_width)
|
||||||
bounding_box_raw = detection[index + feature_map_channel] * feature_stride
|
bounding_boxes_raw = detection[index + feature_map_channel] * feature_stride
|
||||||
face_landmark_5_raw = detection[index + feature_map_channel * 2] * feature_stride
|
face_landmarks_5_raw = detection[index + feature_map_channel * 2] * feature_stride
|
||||||
|
|
||||||
for bounding_box in distance_to_bounding_box(anchors, bounding_box_raw)[keep_indices]:
|
for bounding_box_raw in distance_to_bounding_box(anchors, bounding_boxes_raw)[keep_indices]:
|
||||||
bounding_boxes.append(numpy.array(
|
bounding_boxes.append(numpy.array(
|
||||||
[
|
[
|
||||||
bounding_box[0] * ratio_width,
|
bounding_box_raw[0] * ratio_width,
|
||||||
bounding_box[1] * ratio_height,
|
bounding_box_raw[1] * ratio_height,
|
||||||
bounding_box[2] * ratio_width,
|
bounding_box_raw[2] * ratio_width,
|
||||||
bounding_box[3] * ratio_height,
|
bounding_box_raw[3] * ratio_height
|
||||||
]))
|
]))
|
||||||
|
|
||||||
for score in detection[index][keep_indices]:
|
for face_score_raw in detection[index][keep_indices]:
|
||||||
face_scores.append(score[0])
|
face_scores.append(face_score_raw[0])
|
||||||
|
|
||||||
for face_landmark_5 in distance_to_face_landmark_5(anchors, face_landmark_5_raw)[keep_indices]:
|
for face_landmark_raw_5 in distance_to_face_landmark_5(anchors, face_landmarks_5_raw)[keep_indices]:
|
||||||
face_landmarks_5.append(face_landmark_5 * [ ratio_width, ratio_height ])
|
face_landmarks_5.append(face_landmark_raw_5 * [ ratio_width, ratio_height ])
|
||||||
|
|
||||||
return bounding_boxes, face_scores, face_landmarks_5
|
return bounding_boxes, face_scores, face_landmarks_5
|
||||||
|
|
||||||
|
|
||||||
def detect_with_yoloface(vision_frame : VisionFrame, face_detector_size : str) -> Tuple[List[BoundingBox], List[Score], List[FaceLandmark5]]:
|
def detect_with_yolo_face(vision_frame : VisionFrame, face_detector_size : str) -> Tuple[List[BoundingBox], List[Score], List[FaceLandmark5]]:
|
||||||
bounding_boxes = []
|
bounding_boxes = []
|
||||||
face_scores = []
|
face_scores = []
|
||||||
face_landmarks_5 = []
|
face_landmarks_5 = []
|
||||||
|
face_detector_score = state_manager.get_item('face_detector_score')
|
||||||
face_detector_width, face_detector_height = unpack_resolution(face_detector_size)
|
face_detector_width, face_detector_height = unpack_resolution(face_detector_size)
|
||||||
temp_vision_frame = resize_frame_resolution(vision_frame, (face_detector_width, face_detector_height))
|
temp_vision_frame = restrict_frame(vision_frame, (face_detector_width, face_detector_height))
|
||||||
ratio_height = vision_frame.shape[0] / temp_vision_frame.shape[0]
|
ratio_height = vision_frame.shape[0] / temp_vision_frame.shape[0]
|
||||||
ratio_width = vision_frame.shape[1] / temp_vision_frame.shape[1]
|
ratio_width = vision_frame.shape[1] / temp_vision_frame.shape[1]
|
||||||
detect_vision_frame = prepare_detect_frame(temp_vision_frame, face_detector_size)
|
detect_vision_frame = prepare_detect_frame(temp_vision_frame, face_detector_size)
|
||||||
detection = forward_with_yoloface(detect_vision_frame)
|
detect_vision_frame = normalize_detect_frame(detect_vision_frame, [ 0, 1 ])
|
||||||
|
detection = forward_with_yolo_face(detect_vision_frame)
|
||||||
detection = numpy.squeeze(detection).T
|
detection = numpy.squeeze(detection).T
|
||||||
bounding_box_raw, score_raw, face_landmark_5_raw = numpy.split(detection, [ 4, 5 ], axis = 1)
|
bounding_boxes_raw, face_scores_raw, face_landmarks_5_raw = numpy.split(detection, [ 4, 5 ], axis = 1)
|
||||||
keep_indices = numpy.where(score_raw > state_manager.get_item('face_detector_score'))[0]
|
keep_indices = numpy.where(face_scores_raw > face_detector_score)[0]
|
||||||
|
|
||||||
if numpy.any(keep_indices):
|
if numpy.any(keep_indices):
|
||||||
bounding_box_raw, face_landmark_5_raw, score_raw = bounding_box_raw[keep_indices], face_landmark_5_raw[keep_indices], score_raw[keep_indices]
|
bounding_boxes_raw, face_scores_raw, face_landmarks_5_raw = bounding_boxes_raw[keep_indices], face_scores_raw[keep_indices], face_landmarks_5_raw[keep_indices]
|
||||||
|
|
||||||
for bounding_box in bounding_box_raw:
|
for bounding_box_raw in bounding_boxes_raw:
|
||||||
bounding_boxes.append(numpy.array(
|
bounding_boxes.append(numpy.array(
|
||||||
[
|
[
|
||||||
(bounding_box[0] - bounding_box[2] / 2) * ratio_width,
|
(bounding_box_raw[0] - bounding_box_raw[2] / 2) * ratio_width,
|
||||||
(bounding_box[1] - bounding_box[3] / 2) * ratio_height,
|
(bounding_box_raw[1] - bounding_box_raw[3] / 2) * ratio_height,
|
||||||
(bounding_box[0] + bounding_box[2] / 2) * ratio_width,
|
(bounding_box_raw[0] + bounding_box_raw[2] / 2) * ratio_width,
|
||||||
(bounding_box[1] + bounding_box[3] / 2) * ratio_height,
|
(bounding_box_raw[1] + bounding_box_raw[3] / 2) * ratio_height
|
||||||
]))
|
]))
|
||||||
|
|
||||||
face_scores = score_raw.ravel().tolist()
|
face_scores = face_scores_raw.ravel().tolist()
|
||||||
face_landmark_5_raw[:, 0::3] = (face_landmark_5_raw[:, 0::3]) * ratio_width
|
face_landmarks_5_raw[:, 0::3] = (face_landmarks_5_raw[:, 0::3]) * ratio_width
|
||||||
face_landmark_5_raw[:, 1::3] = (face_landmark_5_raw[:, 1::3]) * ratio_height
|
face_landmarks_5_raw[:, 1::3] = (face_landmarks_5_raw[:, 1::3]) * ratio_height
|
||||||
|
|
||||||
for face_landmark_5 in face_landmark_5_raw:
|
for face_landmark_raw_5 in face_landmarks_5_raw:
|
||||||
face_landmarks_5.append(numpy.array(face_landmark_5.reshape(-1, 3)[:, :2]))
|
face_landmarks_5.append(numpy.array(face_landmark_raw_5.reshape(-1, 3)[:, :2]))
|
||||||
|
|
||||||
return bounding_boxes, face_scores, face_landmarks_5
|
return bounding_boxes, face_scores, face_landmarks_5
|
||||||
|
|
||||||
@@ -288,8 +295,8 @@ def forward_with_scrfd(detect_vision_frame : VisionFrame) -> Detection:
|
|||||||
return detection
|
return detection
|
||||||
|
|
||||||
|
|
||||||
def forward_with_yoloface(detect_vision_frame : VisionFrame) -> Detection:
|
def forward_with_yolo_face(detect_vision_frame : VisionFrame) -> Detection:
|
||||||
face_detector = get_inference_pool().get('yoloface')
|
face_detector = get_inference_pool().get('yolo_face')
|
||||||
|
|
||||||
with thread_semaphore():
|
with thread_semaphore():
|
||||||
detection = face_detector.run(None,
|
detection = face_detector.run(None,
|
||||||
@@ -304,6 +311,13 @@ def prepare_detect_frame(temp_vision_frame : VisionFrame, face_detector_size : s
|
|||||||
face_detector_width, face_detector_height = unpack_resolution(face_detector_size)
|
face_detector_width, face_detector_height = unpack_resolution(face_detector_size)
|
||||||
detect_vision_frame = numpy.zeros((face_detector_height, face_detector_width, 3))
|
detect_vision_frame = numpy.zeros((face_detector_height, face_detector_width, 3))
|
||||||
detect_vision_frame[:temp_vision_frame.shape[0], :temp_vision_frame.shape[1], :] = temp_vision_frame
|
detect_vision_frame[:temp_vision_frame.shape[0], :temp_vision_frame.shape[1], :] = temp_vision_frame
|
||||||
detect_vision_frame = (detect_vision_frame - 127.5) / 128.0
|
|
||||||
detect_vision_frame = numpy.expand_dims(detect_vision_frame.transpose(2, 0, 1), axis = 0).astype(numpy.float32)
|
detect_vision_frame = numpy.expand_dims(detect_vision_frame.transpose(2, 0, 1), axis = 0).astype(numpy.float32)
|
||||||
return detect_vision_frame
|
return detect_vision_frame
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_detect_frame(detect_vision_frame : VisionFrame, normalize_range : Sequence[int]) -> VisionFrame:
|
||||||
|
if normalize_range == [ -1, 1 ]:
|
||||||
|
return (detect_vision_frame - 127.5) / 128.0
|
||||||
|
if normalize_range == [ 0, 1 ]:
|
||||||
|
return detect_vision_frame / 255.0
|
||||||
|
return detect_vision_frame
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import cv2
|
|||||||
import numpy
|
import numpy
|
||||||
from cv2.typing import Size
|
from cv2.typing import Size
|
||||||
|
|
||||||
from facefusion.typing import Anchors, Angle, BoundingBox, Distance, FaceDetectorModel, FaceLandmark5, FaceLandmark68, Mask, Matrix, Points, Scale, Score, Translation, VisionFrame, WarpTemplate, WarpTemplateSet
|
from facefusion.types import Anchors, Angle, BoundingBox, Distance, FaceDetectorModel, FaceLandmark5, FaceLandmark68, Mask, Matrix, Points, Scale, Score, Translation, VisionFrame, WarpTemplate, WarpTemplateSet
|
||||||
|
|
||||||
WARP_TEMPLATES : WarpTemplateSet =\
|
WARP_TEMPLATE_SET : WarpTemplateSet =\
|
||||||
{
|
{
|
||||||
'arcface_112_v1': numpy.array(
|
'arcface_112_v1': numpy.array(
|
||||||
[
|
[
|
||||||
@@ -25,7 +25,7 @@ WARP_TEMPLATES : WarpTemplateSet =\
|
|||||||
[ 0.37097589, 0.82469196 ],
|
[ 0.37097589, 0.82469196 ],
|
||||||
[ 0.63151696, 0.82325089 ]
|
[ 0.63151696, 0.82325089 ]
|
||||||
]),
|
]),
|
||||||
'arcface_128_v2': numpy.array(
|
'arcface_128': numpy.array(
|
||||||
[
|
[
|
||||||
[ 0.36167656, 0.40387734 ],
|
[ 0.36167656, 0.40387734 ],
|
||||||
[ 0.63696719, 0.40235469 ],
|
[ 0.63696719, 0.40235469 ],
|
||||||
@@ -33,6 +33,14 @@ WARP_TEMPLATES : WarpTemplateSet =\
|
|||||||
[ 0.38710391, 0.72160547 ],
|
[ 0.38710391, 0.72160547 ],
|
||||||
[ 0.61507734, 0.72034453 ]
|
[ 0.61507734, 0.72034453 ]
|
||||||
]),
|
]),
|
||||||
|
'dfl_whole_face': numpy.array(
|
||||||
|
[
|
||||||
|
[ 0.35342266, 0.39285716 ],
|
||||||
|
[ 0.62797622, 0.39285716 ],
|
||||||
|
[ 0.48660713, 0.54017860 ],
|
||||||
|
[ 0.38839287, 0.68750011 ],
|
||||||
|
[ 0.59821427, 0.68750011 ]
|
||||||
|
]),
|
||||||
'ffhq_512': numpy.array(
|
'ffhq_512': numpy.array(
|
||||||
[
|
[
|
||||||
[ 0.37691676, 0.46864664 ],
|
[ 0.37691676, 0.46864664 ],
|
||||||
@@ -40,12 +48,28 @@ WARP_TEMPLATES : WarpTemplateSet =\
|
|||||||
[ 0.50123859, 0.61331904 ],
|
[ 0.50123859, 0.61331904 ],
|
||||||
[ 0.39308822, 0.72541100 ],
|
[ 0.39308822, 0.72541100 ],
|
||||||
[ 0.61150205, 0.72490465 ]
|
[ 0.61150205, 0.72490465 ]
|
||||||
|
]),
|
||||||
|
'mtcnn_512': numpy.array(
|
||||||
|
[
|
||||||
|
[ 0.36562865, 0.46733799 ],
|
||||||
|
[ 0.63305391, 0.46585885 ],
|
||||||
|
[ 0.50019127, 0.61942959 ],
|
||||||
|
[ 0.39032951, 0.77598822 ],
|
||||||
|
[ 0.61178945, 0.77476328 ]
|
||||||
|
]),
|
||||||
|
'styleganex_384': numpy.array(
|
||||||
|
[
|
||||||
|
[ 0.42353745, 0.52289879 ],
|
||||||
|
[ 0.57725008, 0.52319972 ],
|
||||||
|
[ 0.50123859, 0.61331904 ],
|
||||||
|
[ 0.43364461, 0.68337652 ],
|
||||||
|
[ 0.57015325, 0.68306005 ]
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def estimate_matrix_by_face_landmark_5(face_landmark_5 : FaceLandmark5, warp_template : WarpTemplate, crop_size : Size) -> Matrix:
|
def estimate_matrix_by_face_landmark_5(face_landmark_5 : FaceLandmark5, warp_template : WarpTemplate, crop_size : Size) -> Matrix:
|
||||||
normed_warp_template = WARP_TEMPLATES.get(warp_template) * crop_size
|
normed_warp_template = WARP_TEMPLATE_SET.get(warp_template) * crop_size
|
||||||
affine_matrix = cv2.estimateAffinePartial2D(face_landmark_5, normed_warp_template, method = cv2.RANSAC, ransacReprojThreshold = 100)[0]
|
affine_matrix = cv2.estimateAffinePartial2D(face_landmark_5, normed_warp_template, method = cv2.RANSAC, ransacReprojThreshold = 100)[0]
|
||||||
return affine_matrix
|
return affine_matrix
|
||||||
|
|
||||||
@@ -184,9 +208,9 @@ def estimate_face_angle(face_landmark_68 : FaceLandmark68) -> Angle:
|
|||||||
return face_angle
|
return face_angle
|
||||||
|
|
||||||
|
|
||||||
def apply_nms(bounding_boxes : List[BoundingBox], face_scores : List[Score], score_threshold : float, nms_threshold : float) -> Sequence[int]:
|
def apply_nms(bounding_boxes : List[BoundingBox], scores : List[Score], score_threshold : float, nms_threshold : float) -> Sequence[int]:
|
||||||
normed_bounding_boxes = [ (x1, y1, x2 - x1, y2 - y1) for (x1, y1, x2, y2) in bounding_boxes ]
|
normed_bounding_boxes = [ (x1, y1, x2 - x1, y2 - y1) for (x1, y1, x2, y2) in bounding_boxes ]
|
||||||
keep_indices = cv2.dnn.NMSBoxes(normed_bounding_boxes, face_scores, score_threshold = score_threshold, nms_threshold = nms_threshold)
|
keep_indices = cv2.dnn.NMSBoxes(normed_bounding_boxes, scores, score_threshold = score_threshold, nms_threshold = nms_threshold)
|
||||||
return keep_indices
|
return keep_indices
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,117 +1,121 @@
|
|||||||
|
from functools import lru_cache
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
from facefusion import inference_manager, state_manager
|
from facefusion import inference_manager, state_manager
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
from facefusion.face_helper import create_rotated_matrix_and_size, estimate_matrix_by_face_landmark_5, transform_points, warp_face_by_translation
|
from facefusion.face_helper import create_rotated_matrix_and_size, estimate_matrix_by_face_landmark_5, transform_points, warp_face_by_translation
|
||||||
from facefusion.filesystem import resolve_relative_path
|
from facefusion.filesystem import resolve_relative_path
|
||||||
from facefusion.thread_helper import conditional_thread_semaphore
|
from facefusion.thread_helper import conditional_thread_semaphore
|
||||||
from facefusion.typing import Angle, BoundingBox, DownloadSet, FaceLandmark5, FaceLandmark68, InferencePool, ModelSet, Prediction, Score, VisionFrame
|
from facefusion.types import Angle, BoundingBox, DownloadScope, DownloadSet, FaceLandmark5, FaceLandmark68, InferencePool, ModelSet, Prediction, Score, VisionFrame
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'2dfan4':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'2dfan4':
|
||||||
{
|
{
|
||||||
'2dfan4':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/2dfan4.hash',
|
'2dfan4':
|
||||||
'path': resolve_relative_path('../.assets/models/2dfan4.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', '2dfan4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/2dfan4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'2dfan4':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', '2dfan4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/2dfan4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 256)
|
||||||
},
|
},
|
||||||
'sources':
|
'peppa_wutz':
|
||||||
{
|
{
|
||||||
'2dfan4':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/2dfan4.onnx',
|
'peppa_wutz':
|
||||||
'path': resolve_relative_path('../.assets/models/2dfan4.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'peppa_wutz.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/peppa_wutz.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'peppa_wutz':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'peppa_wutz.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/peppa_wutz.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 256)
|
||||||
},
|
},
|
||||||
'size': (256, 256)
|
'fan_68_5':
|
||||||
},
|
|
||||||
'peppa_wutz':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'peppa_wutz':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/peppa_wutz.hash',
|
'fan_68_5':
|
||||||
'path': resolve_relative_path('../.assets/models/peppa_wutz.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'fan_68_5.hash'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/fan_68_5.hash')
|
||||||
'sources':
|
}
|
||||||
{
|
},
|
||||||
'peppa_wutz':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/peppa_wutz.onnx',
|
'fan_68_5':
|
||||||
'path': resolve_relative_path('../.assets/models/peppa_wutz.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'fan_68_5.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/fan_68_5.onnx')
|
||||||
'size': (256, 256)
|
}
|
||||||
},
|
|
||||||
'fan_68_5':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'fan_68_5':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fan_68_5.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/fan_68_5.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'fan_68_5':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fan_68_5.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/fan_68_5.onnx')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
_, model_sources = collect_model_downloads()
|
model_names = [ state_manager.get_item('face_landmarker_model'), 'fan_68_5' ]
|
||||||
model_context = __name__ + '.' + state_manager.get_item('face_landmarker_model')
|
_, model_source_set = collect_model_downloads()
|
||||||
return inference_manager.get_inference_pool(model_context, model_sources)
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
model_context = __name__ + '.' + state_manager.get_item('face_landmarker_model')
|
model_names = [ state_manager.get_item('face_landmarker_model'), 'fan_68_5' ]
|
||||||
inference_manager.clear_inference_pool(model_context)
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def collect_model_downloads() -> Tuple[DownloadSet, DownloadSet]:
|
def collect_model_downloads() -> Tuple[DownloadSet, DownloadSet]:
|
||||||
model_hashes =\
|
model_set = create_static_model_set('full')
|
||||||
|
model_hash_set =\
|
||||||
{
|
{
|
||||||
'fan_68_5': MODEL_SET.get('fan_68_5').get('hashes').get('fan_68_5')
|
'fan_68_5': model_set.get('fan_68_5').get('hashes').get('fan_68_5')
|
||||||
}
|
}
|
||||||
model_sources =\
|
model_source_set =\
|
||||||
{
|
{
|
||||||
'fan_68_5': MODEL_SET.get('fan_68_5').get('sources').get('fan_68_5')
|
'fan_68_5': model_set.get('fan_68_5').get('sources').get('fan_68_5')
|
||||||
}
|
}
|
||||||
|
|
||||||
if state_manager.get_item('face_landmarker_model') in [ 'many', '2dfan4' ]:
|
for face_landmarker_model in [ '2dfan4', 'peppa_wutz' ]:
|
||||||
model_hashes['2dfan4'] = MODEL_SET.get('2dfan4').get('hashes').get('2dfan4')
|
if state_manager.get_item('face_landmarker_model') in [ 'many', face_landmarker_model ]:
|
||||||
model_sources['2dfan4'] = MODEL_SET.get('2dfan4').get('sources').get('2dfan4')
|
model_hash_set[face_landmarker_model] = model_set.get(face_landmarker_model).get('hashes').get(face_landmarker_model)
|
||||||
if state_manager.get_item('face_landmarker_model') in [ 'many', 'peppa_wutz' ]:
|
model_source_set[face_landmarker_model] = model_set.get(face_landmarker_model).get('sources').get(face_landmarker_model)
|
||||||
model_hashes['peppa_wutz'] = MODEL_SET.get('peppa_wutz').get('hashes').get('peppa_wutz')
|
|
||||||
model_sources['peppa_wutz'] = MODEL_SET.get('peppa_wutz').get('sources').get('peppa_wutz')
|
return model_hash_set, model_source_set
|
||||||
return model_hashes, model_sources
|
|
||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set, model_source_set = collect_model_downloads()
|
||||||
model_hashes, model_sources = collect_model_downloads()
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def detect_face_landmarks(vision_frame : VisionFrame, bounding_box : BoundingBox, face_angle : Angle) -> Tuple[FaceLandmark68, Score]:
|
def detect_face_landmark(vision_frame : VisionFrame, bounding_box : BoundingBox, face_angle : Angle) -> Tuple[FaceLandmark68, Score]:
|
||||||
face_landmark_2dfan4 = None
|
face_landmark_2dfan4 = None
|
||||||
face_landmark_peppa_wutz = None
|
face_landmark_peppa_wutz = None
|
||||||
face_landmark_score_2dfan4 = 0.0
|
face_landmark_score_2dfan4 = 0.0
|
||||||
@@ -119,6 +123,7 @@ def detect_face_landmarks(vision_frame : VisionFrame, bounding_box : BoundingBox
|
|||||||
|
|
||||||
if state_manager.get_item('face_landmarker_model') in [ 'many', '2dfan4' ]:
|
if state_manager.get_item('face_landmarker_model') in [ 'many', '2dfan4' ]:
|
||||||
face_landmark_2dfan4, face_landmark_score_2dfan4 = detect_with_2dfan4(vision_frame, bounding_box, face_angle)
|
face_landmark_2dfan4, face_landmark_score_2dfan4 = detect_with_2dfan4(vision_frame, bounding_box, face_angle)
|
||||||
|
|
||||||
if state_manager.get_item('face_landmarker_model') in [ 'many', 'peppa_wutz' ]:
|
if state_manager.get_item('face_landmarker_model') in [ 'many', 'peppa_wutz' ]:
|
||||||
face_landmark_peppa_wutz, face_landmark_score_peppa_wutz = detect_with_peppa_wutz(vision_frame, bounding_box, face_angle)
|
face_landmark_peppa_wutz, face_landmark_score_peppa_wutz = detect_with_peppa_wutz(vision_frame, bounding_box, face_angle)
|
||||||
|
|
||||||
@@ -128,7 +133,7 @@ def detect_face_landmarks(vision_frame : VisionFrame, bounding_box : BoundingBox
|
|||||||
|
|
||||||
|
|
||||||
def detect_with_2dfan4(temp_vision_frame: VisionFrame, bounding_box: BoundingBox, face_angle: Angle) -> Tuple[FaceLandmark68, Score]:
|
def detect_with_2dfan4(temp_vision_frame: VisionFrame, bounding_box: BoundingBox, face_angle: Angle) -> Tuple[FaceLandmark68, Score]:
|
||||||
model_size = MODEL_SET.get('2dfan4').get('size')
|
model_size = create_static_model_set('full').get('2dfan4').get('size')
|
||||||
scale = 195 / numpy.subtract(bounding_box[2:], bounding_box[:2]).max().clip(1, None)
|
scale = 195 / numpy.subtract(bounding_box[2:], bounding_box[:2]).max().clip(1, None)
|
||||||
translation = (model_size[0] - numpy.add(bounding_box[2:], bounding_box[:2]) * scale) * 0.5
|
translation = (model_size[0] - numpy.add(bounding_box[2:], bounding_box[:2]) * scale) * 0.5
|
||||||
rotated_matrix, rotated_size = create_rotated_matrix_and_size(face_angle, model_size)
|
rotated_matrix, rotated_size = create_rotated_matrix_and_size(face_angle, model_size)
|
||||||
@@ -147,7 +152,7 @@ def detect_with_2dfan4(temp_vision_frame: VisionFrame, bounding_box: BoundingBox
|
|||||||
|
|
||||||
|
|
||||||
def detect_with_peppa_wutz(temp_vision_frame : VisionFrame, bounding_box : BoundingBox, face_angle : Angle) -> Tuple[FaceLandmark68, Score]:
|
def detect_with_peppa_wutz(temp_vision_frame : VisionFrame, bounding_box : BoundingBox, face_angle : Angle) -> Tuple[FaceLandmark68, Score]:
|
||||||
model_size = MODEL_SET.get('peppa_wutz').get('size')
|
model_size = create_static_model_set('full').get('peppa_wutz').get('size')
|
||||||
scale = 195 / numpy.subtract(bounding_box[2:], bounding_box[:2]).max().clip(1, None)
|
scale = 195 / numpy.subtract(bounding_box[2:], bounding_box[:2]).max().clip(1, None)
|
||||||
translation = (model_size[0] - numpy.add(bounding_box[2:], bounding_box[:2]) * scale) * 0.5
|
translation = (model_size[0] - numpy.add(bounding_box[2:], bounding_box[:2]) * scale) * 0.5
|
||||||
rotated_matrix, rotated_size = create_rotated_matrix_and_size(face_angle, model_size)
|
rotated_matrix, rotated_size = create_rotated_matrix_and_size(face_angle, model_size)
|
||||||
@@ -167,7 +172,7 @@ def detect_with_peppa_wutz(temp_vision_frame : VisionFrame, bounding_box : Bound
|
|||||||
|
|
||||||
def conditional_optimize_contrast(crop_vision_frame : VisionFrame) -> VisionFrame:
|
def conditional_optimize_contrast(crop_vision_frame : VisionFrame) -> VisionFrame:
|
||||||
crop_vision_frame = cv2.cvtColor(crop_vision_frame, cv2.COLOR_RGB2Lab)
|
crop_vision_frame = cv2.cvtColor(crop_vision_frame, cv2.COLOR_RGB2Lab)
|
||||||
if numpy.mean(crop_vision_frame[:, :, 0]) < 30: # type:ignore[arg-type]
|
if numpy.mean(crop_vision_frame[:, :, 0]) < 30: #type:ignore[arg-type]
|
||||||
crop_vision_frame[:, :, 0] = cv2.createCLAHE(clipLimit = 2).apply(crop_vision_frame[:, :, 0])
|
crop_vision_frame[:, :, 0] = cv2.createCLAHE(clipLimit = 2).apply(crop_vision_frame[:, :, 0])
|
||||||
crop_vision_frame = cv2.cvtColor(crop_vision_frame, cv2.COLOR_Lab2RGB)
|
crop_vision_frame = cv2.cvtColor(crop_vision_frame, cv2.COLOR_Lab2RGB)
|
||||||
return crop_vision_frame
|
return crop_vision_frame
|
||||||
|
|||||||
+131
-70
@@ -1,102 +1,159 @@
|
|||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from typing import Dict, List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy
|
import numpy
|
||||||
from cv2.typing import Size
|
from cv2.typing import Size
|
||||||
|
|
||||||
from facefusion import inference_manager
|
import facefusion.choices
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion import inference_manager, state_manager
|
||||||
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
from facefusion.filesystem import resolve_relative_path
|
from facefusion.filesystem import resolve_relative_path
|
||||||
from facefusion.thread_helper import conditional_thread_semaphore
|
from facefusion.thread_helper import conditional_thread_semaphore
|
||||||
from facefusion.typing import DownloadSet, FaceLandmark68, FaceMaskRegion, InferencePool, Mask, ModelSet, Padding, VisionFrame
|
from facefusion.types import DownloadScope, DownloadSet, FaceLandmark68, FaceMaskRegion, InferencePool, Mask, ModelSet, Padding, VisionFrame
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'face_occluder':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'xseg_1':
|
||||||
{
|
{
|
||||||
'face_occluder':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/dfl_xseg.hash',
|
'face_occluder':
|
||||||
'path': resolve_relative_path('../.assets/models/dfl_xseg.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.1.0', 'xseg_1.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/xseg_1.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_occluder':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.1.0', 'xseg_1.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/xseg_1.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 256)
|
||||||
},
|
},
|
||||||
'sources':
|
'xseg_2':
|
||||||
{
|
{
|
||||||
'face_occluder':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/dfl_xseg.onnx',
|
'face_occluder':
|
||||||
'path': resolve_relative_path('../.assets/models/dfl_xseg.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.1.0', 'xseg_2.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/xseg_2.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_occluder':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.1.0', 'xseg_2.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/xseg_2.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 256)
|
||||||
},
|
},
|
||||||
'size': (256, 256)
|
'xseg_3':
|
||||||
},
|
|
||||||
'face_parser':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'face_parser':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/bisenet_resnet_34.hash',
|
'face_occluder':
|
||||||
'path': resolve_relative_path('../.assets/models/bisenet_resnet_34.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.2.0', 'xseg_3.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/xseg_3.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_occluder':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.2.0', 'xseg_3.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/xseg_3.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 256)
|
||||||
},
|
},
|
||||||
'sources':
|
'bisenet_resnet_18':
|
||||||
{
|
{
|
||||||
'face_parser':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/bisenet_resnet_34.onnx',
|
'face_parser':
|
||||||
'path': resolve_relative_path('../.assets/models/bisenet_resnet_34.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.1.0', 'bisenet_resnet_18.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/bisenet_resnet_18.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_parser':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.1.0', 'bisenet_resnet_18.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/bisenet_resnet_18.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (512, 512)
|
||||||
},
|
},
|
||||||
'size': (512, 512)
|
'bisenet_resnet_34':
|
||||||
|
{
|
||||||
|
'hashes':
|
||||||
|
{
|
||||||
|
'face_parser':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'bisenet_resnet_34.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/bisenet_resnet_34.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_parser':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'bisenet_resnet_34.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/bisenet_resnet_34.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (512, 512)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
FACE_MASK_REGIONS : Dict[FaceMaskRegion, int] =\
|
|
||||||
{
|
|
||||||
'skin': 1,
|
|
||||||
'left-eyebrow': 2,
|
|
||||||
'right-eyebrow': 3,
|
|
||||||
'left-eye': 4,
|
|
||||||
'right-eye': 5,
|
|
||||||
'glasses': 6,
|
|
||||||
'nose': 10,
|
|
||||||
'mouth': 11,
|
|
||||||
'upper-lip': 12,
|
|
||||||
'lower-lip': 13
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
_, model_sources = collect_model_downloads()
|
model_names = [state_manager.get_item('face_occluder_model'), state_manager.get_item('face_parser_model')]
|
||||||
return inference_manager.get_inference_pool(__name__, model_sources)
|
_, model_source_set = collect_model_downloads()
|
||||||
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
inference_manager.clear_inference_pool(__name__)
|
model_names = [ state_manager.get_item('face_occluder_model'), state_manager.get_item('face_parser_model') ]
|
||||||
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def collect_model_downloads() -> Tuple[DownloadSet, DownloadSet]:
|
def collect_model_downloads() -> Tuple[DownloadSet, DownloadSet]:
|
||||||
model_hashes =\
|
model_set = create_static_model_set('full')
|
||||||
{
|
model_hash_set = {}
|
||||||
'face_occluder': MODEL_SET.get('face_occluder').get('hashes').get('face_occluder'),
|
model_source_set = {}
|
||||||
'face_parser': MODEL_SET.get('face_parser').get('hashes').get('face_parser')
|
|
||||||
}
|
for face_occluder_model in [ 'xseg_1', 'xseg_2', 'xseg_3' ]:
|
||||||
model_sources =\
|
if state_manager.get_item('face_occluder_model') == face_occluder_model:
|
||||||
{
|
model_hash_set[face_occluder_model] = model_set.get(face_occluder_model).get('hashes').get('face_occluder')
|
||||||
'face_occluder': MODEL_SET.get('face_occluder').get('sources').get('face_occluder'),
|
model_source_set[face_occluder_model] = model_set.get(face_occluder_model).get('sources').get('face_occluder')
|
||||||
'face_parser': MODEL_SET.get('face_parser').get('sources').get('face_parser')
|
|
||||||
}
|
for face_parser_model in [ 'bisenet_resnet_18', 'bisenet_resnet_34' ]:
|
||||||
return model_hashes, model_sources
|
if state_manager.get_item('face_parser_model') == face_parser_model:
|
||||||
|
model_hash_set[face_parser_model] = model_set.get(face_parser_model).get('hashes').get('face_parser')
|
||||||
|
model_source_set[face_parser_model] = model_set.get(face_parser_model).get('sources').get('face_parser')
|
||||||
|
|
||||||
|
return model_hash_set, model_source_set
|
||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set, model_source_set = collect_model_downloads()
|
||||||
model_hashes, model_sources = collect_model_downloads()
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize = None)
|
@lru_cache(maxsize = None)
|
||||||
@@ -114,9 +171,10 @@ def create_static_box_mask(crop_size : Size, face_mask_blur : float, face_mask_p
|
|||||||
|
|
||||||
|
|
||||||
def create_occlusion_mask(crop_vision_frame : VisionFrame) -> Mask:
|
def create_occlusion_mask(crop_vision_frame : VisionFrame) -> Mask:
|
||||||
model_size = MODEL_SET.get('face_occluder').get('size')
|
model_name = state_manager.get_item('face_occluder_model')
|
||||||
|
model_size = create_static_model_set('full').get(model_name).get('size')
|
||||||
prepare_vision_frame = cv2.resize(crop_vision_frame, model_size)
|
prepare_vision_frame = cv2.resize(crop_vision_frame, model_size)
|
||||||
prepare_vision_frame = numpy.expand_dims(prepare_vision_frame, axis = 0).astype(numpy.float32) / 255
|
prepare_vision_frame = numpy.expand_dims(prepare_vision_frame, axis = 0).astype(numpy.float32) / 255.0
|
||||||
prepare_vision_frame = prepare_vision_frame.transpose(0, 1, 2, 3)
|
prepare_vision_frame = prepare_vision_frame.transpose(0, 1, 2, 3)
|
||||||
occlusion_mask = forward_occlude_face(prepare_vision_frame)
|
occlusion_mask = forward_occlude_face(prepare_vision_frame)
|
||||||
occlusion_mask = occlusion_mask.transpose(0, 1, 2).clip(0, 1).astype(numpy.float32)
|
occlusion_mask = occlusion_mask.transpose(0, 1, 2).clip(0, 1).astype(numpy.float32)
|
||||||
@@ -126,15 +184,16 @@ def create_occlusion_mask(crop_vision_frame : VisionFrame) -> Mask:
|
|||||||
|
|
||||||
|
|
||||||
def create_region_mask(crop_vision_frame : VisionFrame, face_mask_regions : List[FaceMaskRegion]) -> Mask:
|
def create_region_mask(crop_vision_frame : VisionFrame, face_mask_regions : List[FaceMaskRegion]) -> Mask:
|
||||||
model_size = MODEL_SET.get('face_parser').get('size')
|
model_name = state_manager.get_item('face_parser_model')
|
||||||
|
model_size = create_static_model_set('full').get(model_name).get('size')
|
||||||
prepare_vision_frame = cv2.resize(crop_vision_frame, model_size)
|
prepare_vision_frame = cv2.resize(crop_vision_frame, model_size)
|
||||||
prepare_vision_frame = prepare_vision_frame[:, :, ::-1].astype(numpy.float32) / 255
|
prepare_vision_frame = prepare_vision_frame[:, :, ::-1].astype(numpy.float32) / 255.0
|
||||||
prepare_vision_frame = numpy.subtract(prepare_vision_frame, numpy.array([ 0.485, 0.456, 0.406 ]).astype(numpy.float32))
|
prepare_vision_frame = numpy.subtract(prepare_vision_frame, numpy.array([ 0.485, 0.456, 0.406 ]).astype(numpy.float32))
|
||||||
prepare_vision_frame = numpy.divide(prepare_vision_frame, numpy.array([ 0.229, 0.224, 0.225 ]).astype(numpy.float32))
|
prepare_vision_frame = numpy.divide(prepare_vision_frame, numpy.array([ 0.229, 0.224, 0.225 ]).astype(numpy.float32))
|
||||||
prepare_vision_frame = numpy.expand_dims(prepare_vision_frame, axis = 0)
|
prepare_vision_frame = numpy.expand_dims(prepare_vision_frame, axis = 0)
|
||||||
prepare_vision_frame = prepare_vision_frame.transpose(0, 3, 1, 2)
|
prepare_vision_frame = prepare_vision_frame.transpose(0, 3, 1, 2)
|
||||||
region_mask = forward_parse_face(prepare_vision_frame)
|
region_mask = forward_parse_face(prepare_vision_frame)
|
||||||
region_mask = numpy.isin(region_mask.argmax(0), [ FACE_MASK_REGIONS[region] for region in face_mask_regions ])
|
region_mask = numpy.isin(region_mask.argmax(0), [ facefusion.choices.face_mask_region_set.get(face_mask_region) for face_mask_region in face_mask_regions ])
|
||||||
region_mask = cv2.resize(region_mask.astype(numpy.float32), crop_vision_frame.shape[:2][::-1])
|
region_mask = cv2.resize(region_mask.astype(numpy.float32), crop_vision_frame.shape[:2][::-1])
|
||||||
region_mask = (cv2.GaussianBlur(region_mask.clip(0, 1), (0, 0), 5).clip(0.5, 1) - 0.5) * 2
|
region_mask = (cv2.GaussianBlur(region_mask.clip(0, 1), (0, 0), 5).clip(0.5, 1) - 0.5) * 2
|
||||||
return region_mask
|
return region_mask
|
||||||
@@ -150,7 +209,8 @@ def create_mouth_mask(face_landmark_68 : FaceLandmark68) -> Mask:
|
|||||||
|
|
||||||
|
|
||||||
def forward_occlude_face(prepare_vision_frame : VisionFrame) -> Mask:
|
def forward_occlude_face(prepare_vision_frame : VisionFrame) -> Mask:
|
||||||
face_occluder = get_inference_pool().get('face_occluder')
|
model_name = state_manager.get_item('face_occluder_model')
|
||||||
|
face_occluder = get_inference_pool().get(model_name)
|
||||||
|
|
||||||
with conditional_thread_semaphore():
|
with conditional_thread_semaphore():
|
||||||
occlusion_mask : Mask = face_occluder.run(None,
|
occlusion_mask : Mask = face_occluder.run(None,
|
||||||
@@ -162,7 +222,8 @@ def forward_occlude_face(prepare_vision_frame : VisionFrame) -> Mask:
|
|||||||
|
|
||||||
|
|
||||||
def forward_parse_face(prepare_vision_frame : VisionFrame) -> Mask:
|
def forward_parse_face(prepare_vision_frame : VisionFrame) -> Mask:
|
||||||
face_parser = get_inference_pool().get('face_parser')
|
model_name = state_manager.get_item('face_parser_model')
|
||||||
|
face_parser = get_inference_pool().get(model_name)
|
||||||
|
|
||||||
with conditional_thread_semaphore():
|
with conditional_thread_semaphore():
|
||||||
region_mask : Mask = face_parser.run(None,
|
region_mask : Mask = face_parser.run(None,
|
||||||
|
|||||||
@@ -1,59 +1,65 @@
|
|||||||
|
from functools import lru_cache
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
from facefusion import inference_manager
|
from facefusion import inference_manager
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
from facefusion.face_helper import warp_face_by_face_landmark_5
|
from facefusion.face_helper import warp_face_by_face_landmark_5
|
||||||
from facefusion.filesystem import resolve_relative_path
|
from facefusion.filesystem import resolve_relative_path
|
||||||
from facefusion.thread_helper import conditional_thread_semaphore
|
from facefusion.thread_helper import conditional_thread_semaphore
|
||||||
from facefusion.typing import Embedding, FaceLandmark5, InferencePool, ModelOptions, ModelSet, VisionFrame
|
from facefusion.types import DownloadScope, Embedding, FaceLandmark5, InferencePool, ModelOptions, ModelSet, VisionFrame
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'arcface':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'arcface':
|
||||||
{
|
{
|
||||||
'face_recognizer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_w600k_r50.hash',
|
'face_recognizer':
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_w600k_r50.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'arcface_w600k_r50.hash'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/arcface_w600k_r50.hash')
|
||||||
'sources':
|
}
|
||||||
{
|
},
|
||||||
'face_recognizer':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_w600k_r50.onnx',
|
'face_recognizer':
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_w600k_r50.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'arcface_w600k_r50.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/arcface_w600k_r50.onnx')
|
||||||
'template': 'arcface_112_v2',
|
}
|
||||||
'size': (112, 112)
|
},
|
||||||
|
'template': 'arcface_112_v2',
|
||||||
|
'size': (112, 112)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
model_sources = get_model_options().get('sources')
|
model_names = [ 'arcface' ]
|
||||||
return inference_manager.get_inference_pool(__name__, model_sources)
|
model_source_set = get_model_options().get('sources')
|
||||||
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
inference_manager.clear_inference_pool(__name__)
|
model_names = [ 'arcface' ]
|
||||||
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def get_model_options() -> ModelOptions:
|
def get_model_options() -> ModelOptions:
|
||||||
return MODEL_SET.get('arcface')
|
return create_static_model_set('full').get('arcface')
|
||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set = get_model_options().get('hashes')
|
||||||
model_hashes = get_model_options().get('hashes')
|
model_source_set = get_model_options().get('sources')
|
||||||
model_sources = get_model_options().get('sources')
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def calc_embedding(temp_vision_frame : VisionFrame, face_landmark_5 : FaceLandmark5) -> Tuple[Embedding, Embedding]:
|
def calc_embedding(temp_vision_frame : VisionFrame, face_landmark_5 : FaceLandmark5) -> Tuple[Embedding, Embedding]:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from typing import List
|
|||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
from facefusion import state_manager
|
from facefusion import state_manager
|
||||||
from facefusion.typing import Face, FaceSelectorOrder, FaceSet, Gender, Race
|
from facefusion.types import Face, FaceSelectorOrder, FaceSet, Gender, Race
|
||||||
|
|
||||||
|
|
||||||
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]:
|
||||||
@@ -21,6 +21,7 @@ def find_similar_faces(faces : List[Face], reference_faces : FaceSet, face_dista
|
|||||||
|
|
||||||
def compare_faces(face : Face, reference_face : Face, face_distance : float) -> bool:
|
def compare_faces(face : Face, reference_face : Face, face_distance : float) -> bool:
|
||||||
current_face_distance = calc_face_distance(face, reference_face)
|
current_face_distance = calc_face_distance(face, reference_face)
|
||||||
|
current_face_distance = float(numpy.interp(current_face_distance, [ 0, 2 ], [ 0, 1 ]))
|
||||||
return current_face_distance < face_distance
|
return current_face_distance < face_distance
|
||||||
|
|
||||||
|
|
||||||
@@ -33,17 +34,17 @@ def calc_face_distance(face : Face, reference_face : Face) -> float:
|
|||||||
def sort_and_filter_faces(faces : List[Face]) -> List[Face]:
|
def sort_and_filter_faces(faces : List[Face]) -> List[Face]:
|
||||||
if faces:
|
if faces:
|
||||||
if state_manager.get_item('face_selector_order'):
|
if state_manager.get_item('face_selector_order'):
|
||||||
faces = sort_by_order(faces, state_manager.get_item('face_selector_order'))
|
faces = sort_faces_by_order(faces, state_manager.get_item('face_selector_order'))
|
||||||
if state_manager.get_item('face_selector_gender'):
|
if state_manager.get_item('face_selector_gender'):
|
||||||
faces = filter_by_gender(faces, state_manager.get_item('face_selector_gender'))
|
faces = filter_faces_by_gender(faces, state_manager.get_item('face_selector_gender'))
|
||||||
if state_manager.get_item('face_selector_race'):
|
if state_manager.get_item('face_selector_race'):
|
||||||
faces = filter_by_race(faces, state_manager.get_item('face_selector_race'))
|
faces = filter_faces_by_race(faces, state_manager.get_item('face_selector_race'))
|
||||||
if state_manager.get_item('face_selector_age_start') or state_manager.get_item('face_selector_age_end'):
|
if state_manager.get_item('face_selector_age_start') or state_manager.get_item('face_selector_age_end'):
|
||||||
faces = filter_by_age(faces, state_manager.get_item('face_selector_age_start'), state_manager.get_item('face_selector_age_end'))
|
faces = filter_faces_by_age(faces, state_manager.get_item('face_selector_age_start'), state_manager.get_item('face_selector_age_end'))
|
||||||
return faces
|
return faces
|
||||||
|
|
||||||
|
|
||||||
def sort_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 = lambda face: face.bounding_box[0])
|
||||||
if order == 'right-left':
|
if order == 'right-left':
|
||||||
@@ -63,7 +64,7 @@ def sort_by_order(faces : List[Face], order : FaceSelectorOrder) -> List[Face]:
|
|||||||
return faces
|
return faces
|
||||||
|
|
||||||
|
|
||||||
def filter_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 = []
|
||||||
|
|
||||||
for face in faces:
|
for face in faces:
|
||||||
@@ -72,7 +73,7 @@ def filter_by_gender(faces : List[Face], gender : Gender) -> List[Face]:
|
|||||||
return filter_faces
|
return filter_faces
|
||||||
|
|
||||||
|
|
||||||
def filter_by_age(faces : List[Face], face_selector_age_start : int, face_selector_age_end : int) -> List[Face]:
|
def filter_faces_by_age(faces : List[Face], face_selector_age_start : int, face_selector_age_end : int) -> List[Face]:
|
||||||
filter_faces = []
|
filter_faces = []
|
||||||
age = range(face_selector_age_start, face_selector_age_end)
|
age = range(face_selector_age_start, face_selector_age_end)
|
||||||
|
|
||||||
@@ -82,7 +83,7 @@ def filter_by_age(faces : List[Face], face_selector_age_start : int, face_select
|
|||||||
return filter_faces
|
return filter_faces
|
||||||
|
|
||||||
|
|
||||||
def filter_by_race(faces : List[Face], race : Race) -> List[Face]:
|
def filter_faces_by_race(faces : List[Face], race : Race) -> List[Face]:
|
||||||
filter_faces = []
|
filter_faces = []
|
||||||
|
|
||||||
for face in faces:
|
for face in faces:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from typing import List, Optional
|
|||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
from facefusion.typing import Face, FaceSet, FaceStore, VisionFrame
|
from facefusion.types import Face, FaceSet, FaceStore, VisionFrame
|
||||||
|
|
||||||
FACE_STORE : FaceStore =\
|
FACE_STORE : FaceStore =\
|
||||||
{
|
{
|
||||||
@@ -34,7 +34,10 @@ def clear_static_faces() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def create_frame_hash(vision_frame : VisionFrame) -> Optional[str]:
|
def create_frame_hash(vision_frame : VisionFrame) -> Optional[str]:
|
||||||
return hashlib.sha1(vision_frame.tobytes()).hexdigest() if numpy.any(vision_frame) else None
|
if numpy.any(vision_frame):
|
||||||
|
frame_hash = hashlib.blake2b(vision_frame.tobytes(), digest_size = 16).hexdigest()
|
||||||
|
return frame_hash
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_reference_faces() -> Optional[FaceSet]:
|
def get_reference_faces() -> Optional[FaceSet]:
|
||||||
|
|||||||
+197
-119
@@ -1,26 +1,34 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
import filetype
|
from tqdm import tqdm
|
||||||
|
|
||||||
from facefusion import logger, process_manager, state_manager
|
import facefusion.choices
|
||||||
from facefusion.filesystem import remove_file
|
from facefusion import ffmpeg_builder, logger, process_manager, state_manager, wording
|
||||||
|
from facefusion.filesystem import get_file_format, remove_file
|
||||||
from facefusion.temp_helper import get_temp_file_path, get_temp_frames_pattern
|
from facefusion.temp_helper import get_temp_file_path, get_temp_frames_pattern
|
||||||
from facefusion.typing import AudioBuffer, Fps, OutputVideoPreset
|
from facefusion.types import AudioBuffer, Commands, EncoderSet, Fps, UpdateProgress
|
||||||
from facefusion.vision import restrict_video_fps
|
from facefusion.vision import detect_video_duration, detect_video_fps, predict_video_frame_total
|
||||||
|
|
||||||
|
|
||||||
def run_ffmpeg(args : List[str]) -> subprocess.Popen[bytes]:
|
def run_ffmpeg_with_progress(commands : Commands, update_progress : UpdateProgress) -> subprocess.Popen[bytes]:
|
||||||
commands = [ shutil.which('ffmpeg'), '-hide_banner', '-loglevel', 'error' ]
|
log_level = state_manager.get_item('log_level')
|
||||||
commands.extend(args)
|
commands.extend(ffmpeg_builder.set_progress())
|
||||||
|
commands.extend(ffmpeg_builder.cast_stream())
|
||||||
|
commands = ffmpeg_builder.run(commands)
|
||||||
process = subprocess.Popen(commands, stderr = subprocess.PIPE, stdout = subprocess.PIPE)
|
process = subprocess.Popen(commands, stderr = subprocess.PIPE, stdout = subprocess.PIPE)
|
||||||
|
|
||||||
while process_manager.is_processing():
|
while process_manager.is_processing():
|
||||||
try:
|
try:
|
||||||
if state_manager.get_item('log_level') == 'debug':
|
|
||||||
|
while __line__ := process.stdout.readline().decode().lower():
|
||||||
|
if 'frame=' in __line__:
|
||||||
|
_, frame_number = __line__.split('frame=')
|
||||||
|
update_progress(int(frame_number))
|
||||||
|
|
||||||
|
if log_level == 'debug':
|
||||||
log_debug(process)
|
log_debug(process)
|
||||||
process.wait(timeout = 0.5)
|
process.wait(timeout = 0.5)
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
@@ -32,9 +40,27 @@ def run_ffmpeg(args : List[str]) -> subprocess.Popen[bytes]:
|
|||||||
return process
|
return process
|
||||||
|
|
||||||
|
|
||||||
def open_ffmpeg(args : List[str]) -> subprocess.Popen[bytes]:
|
def run_ffmpeg(commands : Commands) -> subprocess.Popen[bytes]:
|
||||||
commands = [ shutil.which('ffmpeg'), '-hide_banner', '-loglevel', 'quiet' ]
|
log_level = state_manager.get_item('log_level')
|
||||||
commands.extend(args)
|
commands = ffmpeg_builder.run(commands)
|
||||||
|
process = subprocess.Popen(commands, stderr = subprocess.PIPE, stdout = subprocess.PIPE)
|
||||||
|
|
||||||
|
while process_manager.is_processing():
|
||||||
|
try:
|
||||||
|
if log_level == 'debug':
|
||||||
|
log_debug(process)
|
||||||
|
process.wait(timeout = 0.5)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
continue
|
||||||
|
return process
|
||||||
|
|
||||||
|
if process_manager.is_stopping():
|
||||||
|
process.terminate()
|
||||||
|
return process
|
||||||
|
|
||||||
|
|
||||||
|
def open_ffmpeg(commands : Commands) -> subprocess.Popen[bytes]:
|
||||||
|
commands = ffmpeg_builder.run(commands)
|
||||||
return subprocess.Popen(commands, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
|
return subprocess.Popen(commands, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
|
||||||
|
|
||||||
|
|
||||||
@@ -47,46 +73,162 @@ def log_debug(process : subprocess.Popen[bytes]) -> None:
|
|||||||
logger.debug(error.strip(), __name__)
|
logger.debug(error.strip(), __name__)
|
||||||
|
|
||||||
|
|
||||||
def extract_frames(target_path : str, temp_video_resolution : str, temp_video_fps : Fps) -> bool:
|
def get_available_encoder_set() -> EncoderSet:
|
||||||
trim_frame_start = state_manager.get_item('trim_frame_start')
|
available_encoder_set : EncoderSet =\
|
||||||
trim_frame_end = state_manager.get_item('trim_frame_end')
|
{
|
||||||
temp_frames_pattern = get_temp_frames_pattern(target_path, '%08d')
|
'audio': [],
|
||||||
commands = [ '-i', target_path, '-s', str(temp_video_resolution), '-q:v', '0' ]
|
'video': []
|
||||||
|
}
|
||||||
|
commands = ffmpeg_builder.chain(
|
||||||
|
ffmpeg_builder.get_encoders()
|
||||||
|
)
|
||||||
|
process = run_ffmpeg(commands)
|
||||||
|
|
||||||
if isinstance(trim_frame_start, int) and isinstance(trim_frame_end, int):
|
while line := process.stdout.readline().decode().lower():
|
||||||
commands.extend([ '-vf', 'trim=start_frame=' + str(trim_frame_start) + ':end_frame=' + str(trim_frame_end) + ',fps=' + str(temp_video_fps) ])
|
if line.startswith(' a'):
|
||||||
elif isinstance(trim_frame_start, int):
|
audio_encoder = line.split()[1]
|
||||||
commands.extend([ '-vf', 'trim=start_frame=' + str(trim_frame_start) + ',fps=' + str(temp_video_fps) ])
|
|
||||||
elif isinstance(trim_frame_end, int):
|
if audio_encoder in facefusion.choices.output_audio_encoders:
|
||||||
commands.extend([ '-vf', 'trim=end_frame=' + str(trim_frame_end) + ',fps=' + str(temp_video_fps) ])
|
index = facefusion.choices.output_audio_encoders.index(audio_encoder) #type:ignore[arg-type]
|
||||||
else:
|
available_encoder_set['audio'].insert(index, audio_encoder) #type:ignore[arg-type]
|
||||||
commands.extend([ '-vf', 'fps=' + str(temp_video_fps) ])
|
if line.startswith(' v'):
|
||||||
commands.extend([ '-vsync', '0', temp_frames_pattern ])
|
video_encoder = line.split()[1]
|
||||||
|
|
||||||
|
if video_encoder in facefusion.choices.output_video_encoders:
|
||||||
|
index = facefusion.choices.output_video_encoders.index(video_encoder) #type:ignore[arg-type]
|
||||||
|
available_encoder_set['video'].insert(index, video_encoder) #type:ignore[arg-type]
|
||||||
|
|
||||||
|
return available_encoder_set
|
||||||
|
|
||||||
|
|
||||||
|
def extract_frames(target_path : str, temp_video_resolution : str, temp_video_fps : Fps, trim_frame_start : int, trim_frame_end : int) -> bool:
|
||||||
|
extract_frame_total = predict_video_frame_total(target_path, temp_video_fps, trim_frame_start, trim_frame_end)
|
||||||
|
temp_frames_pattern = get_temp_frames_pattern(target_path, '%08d')
|
||||||
|
commands = ffmpeg_builder.chain(
|
||||||
|
ffmpeg_builder.set_input(target_path),
|
||||||
|
ffmpeg_builder.set_media_resolution(temp_video_resolution),
|
||||||
|
ffmpeg_builder.set_frame_quality(0),
|
||||||
|
ffmpeg_builder.select_frame_range(trim_frame_start, trim_frame_end, temp_video_fps),
|
||||||
|
ffmpeg_builder.prevent_frame_drop(),
|
||||||
|
ffmpeg_builder.set_output(temp_frames_pattern)
|
||||||
|
)
|
||||||
|
|
||||||
|
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))
|
||||||
|
return process.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
|
def copy_image(target_path : str, temp_image_resolution : str) -> bool:
|
||||||
|
temp_file_path = get_temp_file_path(target_path)
|
||||||
|
commands = ffmpeg_builder.chain(
|
||||||
|
ffmpeg_builder.set_input(target_path),
|
||||||
|
ffmpeg_builder.set_media_resolution(temp_image_resolution),
|
||||||
|
ffmpeg_builder.set_image_quality(target_path, 100),
|
||||||
|
ffmpeg_builder.force_output(temp_file_path)
|
||||||
|
)
|
||||||
return run_ffmpeg(commands).returncode == 0
|
return run_ffmpeg(commands).returncode == 0
|
||||||
|
|
||||||
|
|
||||||
def merge_video(target_path : str, output_video_resolution : str, output_video_fps : Fps) -> bool:
|
def finalize_image(target_path : str, output_path : str, output_image_resolution : str) -> bool:
|
||||||
temp_video_fps = restrict_video_fps(target_path, output_video_fps)
|
output_image_quality = state_manager.get_item('output_image_quality')
|
||||||
|
temp_file_path = get_temp_file_path(target_path)
|
||||||
|
commands = ffmpeg_builder.chain(
|
||||||
|
ffmpeg_builder.set_input(temp_file_path),
|
||||||
|
ffmpeg_builder.set_media_resolution(output_image_resolution),
|
||||||
|
ffmpeg_builder.set_image_quality(target_path, output_image_quality),
|
||||||
|
ffmpeg_builder.force_output(output_path)
|
||||||
|
)
|
||||||
|
return run_ffmpeg(commands).returncode == 0
|
||||||
|
|
||||||
|
|
||||||
|
def read_audio_buffer(target_path : str, audio_sample_rate : int, audio_sample_size : int, audio_channel_total : int) -> Optional[AudioBuffer]:
|
||||||
|
commands = ffmpeg_builder.chain(
|
||||||
|
ffmpeg_builder.set_input(target_path),
|
||||||
|
ffmpeg_builder.ignore_video_stream(),
|
||||||
|
ffmpeg_builder.set_audio_sample_rate(audio_sample_rate),
|
||||||
|
ffmpeg_builder.set_audio_sample_size(audio_sample_size),
|
||||||
|
ffmpeg_builder.set_audio_channel_total(audio_channel_total),
|
||||||
|
ffmpeg_builder.cast_stream()
|
||||||
|
)
|
||||||
|
|
||||||
|
process = open_ffmpeg(commands)
|
||||||
|
audio_buffer, _ = process.communicate()
|
||||||
|
if process.returncode == 0:
|
||||||
|
return audio_buffer
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def restore_audio(target_path : str, output_path : str, trim_frame_start : int, trim_frame_end : int) -> bool:
|
||||||
|
output_audio_encoder = state_manager.get_item('output_audio_encoder')
|
||||||
|
output_audio_quality = state_manager.get_item('output_audio_quality')
|
||||||
|
output_audio_volume = state_manager.get_item('output_audio_volume')
|
||||||
|
target_video_fps = detect_video_fps(target_path)
|
||||||
|
temp_file_path = get_temp_file_path(target_path)
|
||||||
|
temp_video_duration = detect_video_duration(temp_file_path)
|
||||||
|
|
||||||
|
commands = ffmpeg_builder.chain(
|
||||||
|
ffmpeg_builder.set_input(temp_file_path),
|
||||||
|
ffmpeg_builder.select_media_range(trim_frame_start, trim_frame_end, target_video_fps),
|
||||||
|
ffmpeg_builder.set_input(target_path),
|
||||||
|
ffmpeg_builder.copy_video_encoder(),
|
||||||
|
ffmpeg_builder.set_audio_encoder(output_audio_encoder),
|
||||||
|
ffmpeg_builder.set_audio_quality(output_audio_encoder, output_audio_quality),
|
||||||
|
ffmpeg_builder.set_audio_volume(output_audio_volume),
|
||||||
|
ffmpeg_builder.select_media_stream('0:v:0'),
|
||||||
|
ffmpeg_builder.select_media_stream('1:a:0'),
|
||||||
|
ffmpeg_builder.set_video_duration(temp_video_duration),
|
||||||
|
ffmpeg_builder.force_output(output_path)
|
||||||
|
)
|
||||||
|
return run_ffmpeg(commands).returncode == 0
|
||||||
|
|
||||||
|
|
||||||
|
def replace_audio(target_path : str, audio_path : str, output_path : str) -> bool:
|
||||||
|
output_audio_encoder = state_manager.get_item('output_audio_encoder')
|
||||||
|
output_audio_quality = state_manager.get_item('output_audio_quality')
|
||||||
|
output_audio_volume = state_manager.get_item('output_audio_volume')
|
||||||
|
temp_file_path = get_temp_file_path(target_path)
|
||||||
|
temp_video_duration = detect_video_duration(temp_file_path)
|
||||||
|
|
||||||
|
commands = ffmpeg_builder.chain(
|
||||||
|
ffmpeg_builder.set_input(temp_file_path),
|
||||||
|
ffmpeg_builder.set_input(audio_path),
|
||||||
|
ffmpeg_builder.copy_video_encoder(),
|
||||||
|
ffmpeg_builder.set_audio_encoder(output_audio_encoder),
|
||||||
|
ffmpeg_builder.set_audio_quality(output_audio_encoder, output_audio_quality),
|
||||||
|
ffmpeg_builder.set_audio_volume(output_audio_volume),
|
||||||
|
ffmpeg_builder.set_video_duration(temp_video_duration),
|
||||||
|
ffmpeg_builder.force_output(output_path)
|
||||||
|
)
|
||||||
|
return run_ffmpeg(commands).returncode == 0
|
||||||
|
|
||||||
|
|
||||||
|
def merge_video(target_path : str, temp_video_fps : Fps, output_video_resolution : str, output_video_fps : Fps, trim_frame_start : int, trim_frame_end : int) -> bool:
|
||||||
|
output_video_encoder = state_manager.get_item('output_video_encoder')
|
||||||
|
output_video_quality = state_manager.get_item('output_video_quality')
|
||||||
|
output_video_preset = state_manager.get_item('output_video_preset')
|
||||||
|
merge_frame_total = predict_video_frame_total(target_path, output_video_fps, trim_frame_start, trim_frame_end)
|
||||||
temp_file_path = get_temp_file_path(target_path)
|
temp_file_path = get_temp_file_path(target_path)
|
||||||
temp_frames_pattern = get_temp_frames_pattern(target_path, '%08d')
|
temp_frames_pattern = get_temp_frames_pattern(target_path, '%08d')
|
||||||
commands = [ '-r', str(temp_video_fps), '-i', temp_frames_pattern, '-s', str(output_video_resolution), '-c:v', state_manager.get_item('output_video_encoder') ]
|
|
||||||
|
|
||||||
if state_manager.get_item('output_video_encoder') in [ 'libx264', 'libx265' ]:
|
if get_file_format(target_path) == 'webm':
|
||||||
output_video_compression = round(51 - (state_manager.get_item('output_video_quality') * 0.51))
|
output_video_encoder = 'libvpx-vp9'
|
||||||
commands.extend([ '-crf', str(output_video_compression), '-preset', state_manager.get_item('output_video_preset') ])
|
|
||||||
if state_manager.get_item('output_video_encoder') in [ 'libvpx-vp9' ]:
|
commands = ffmpeg_builder.chain(
|
||||||
output_video_compression = round(63 - (state_manager.get_item('output_video_quality') * 0.63))
|
ffmpeg_builder.set_conditional_fps(temp_video_fps),
|
||||||
commands.extend([ '-crf', str(output_video_compression) ])
|
ffmpeg_builder.set_input(temp_frames_pattern),
|
||||||
if state_manager.get_item('output_video_encoder') in [ 'h264_nvenc', 'hevc_nvenc' ]:
|
ffmpeg_builder.set_media_resolution(output_video_resolution),
|
||||||
output_video_compression = round(51 - (state_manager.get_item('output_video_quality') * 0.51))
|
ffmpeg_builder.set_video_encoder(output_video_encoder),
|
||||||
commands.extend([ '-cq', str(output_video_compression), '-preset', map_nvenc_preset(state_manager.get_item('output_video_preset')) ])
|
ffmpeg_builder.set_video_quality(output_video_encoder, output_video_quality),
|
||||||
if state_manager.get_item('output_video_encoder') in [ 'h264_amf', 'hevc_amf' ]:
|
ffmpeg_builder.set_video_preset(output_video_encoder, output_video_preset),
|
||||||
output_video_compression = round(51 - (state_manager.get_item('output_video_quality') * 0.51))
|
ffmpeg_builder.set_video_fps(output_video_fps),
|
||||||
commands.extend([ '-qp_i', str(output_video_compression), '-qp_p', str(output_video_compression), '-quality', map_amf_preset(state_manager.get_item('output_video_preset')) ])
|
ffmpeg_builder.set_pixel_format(output_video_encoder),
|
||||||
if state_manager.get_item('output_video_encoder') in [ 'h264_videotoolbox', 'hevc_videotoolbox' ]:
|
ffmpeg_builder.set_video_colorspace('bt709'),
|
||||||
commands.extend([ '-q:v', str(state_manager.get_item('output_video_quality')) ])
|
ffmpeg_builder.force_output(temp_file_path)
|
||||||
commands.extend([ '-vf', 'framerate=fps=' + str(output_video_fps), '-pix_fmt', 'yuv420p', '-colorspace', 'bt709', '-y', temp_file_path ])
|
)
|
||||||
return run_ffmpeg(commands).returncode == 0
|
|
||||||
|
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))
|
||||||
|
return process.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
def concat_video(output_path : str, temp_output_paths : List[str]) -> bool:
|
def concat_video(output_path : str, temp_output_paths : List[str]) -> bool:
|
||||||
@@ -97,80 +239,16 @@ def concat_video(output_path : str, temp_output_paths : List[str]) -> bool:
|
|||||||
concat_video_file.write('file \'' + os.path.abspath(temp_output_path) + '\'' + os.linesep)
|
concat_video_file.write('file \'' + os.path.abspath(temp_output_path) + '\'' + os.linesep)
|
||||||
concat_video_file.flush()
|
concat_video_file.flush()
|
||||||
concat_video_file.close()
|
concat_video_file.close()
|
||||||
commands = [ '-f', 'concat', '-safe', '0', '-i', concat_video_file.name, '-c:v', 'copy', '-c:a', state_manager.get_item('output_audio_encoder'), '-y', os.path.abspath(output_path) ]
|
|
||||||
|
output_path = os.path.abspath(output_path)
|
||||||
|
commands = ffmpeg_builder.chain(
|
||||||
|
ffmpeg_builder.unsafe_concat(),
|
||||||
|
ffmpeg_builder.set_input(concat_video_file.name),
|
||||||
|
ffmpeg_builder.copy_video_encoder(),
|
||||||
|
ffmpeg_builder.copy_audio_encoder(),
|
||||||
|
ffmpeg_builder.force_output(output_path)
|
||||||
|
)
|
||||||
process = run_ffmpeg(commands)
|
process = run_ffmpeg(commands)
|
||||||
process.communicate()
|
process.communicate()
|
||||||
remove_file(concat_video_path)
|
remove_file(concat_video_path)
|
||||||
return process.returncode == 0
|
return process.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
def copy_image(target_path : str, temp_image_resolution : str) -> bool:
|
|
||||||
temp_file_path = get_temp_file_path(target_path)
|
|
||||||
temp_image_compression = calc_image_compression(target_path, 100)
|
|
||||||
commands = [ '-i', target_path, '-s', str(temp_image_resolution), '-q:v', str(temp_image_compression), '-y', temp_file_path ]
|
|
||||||
return run_ffmpeg(commands).returncode == 0
|
|
||||||
|
|
||||||
|
|
||||||
def finalize_image(target_path : str, output_path : str, output_image_resolution : str) -> bool:
|
|
||||||
temp_file_path = get_temp_file_path(target_path)
|
|
||||||
output_image_compression = calc_image_compression(target_path, state_manager.get_item('output_image_quality'))
|
|
||||||
commands = [ '-i', temp_file_path, '-s', str(output_image_resolution), '-q:v', str(output_image_compression), '-y', output_path ]
|
|
||||||
return run_ffmpeg(commands).returncode == 0
|
|
||||||
|
|
||||||
|
|
||||||
def calc_image_compression(image_path : str, image_quality : int) -> int:
|
|
||||||
is_webp = filetype.guess_mime(image_path) == 'image/webp'
|
|
||||||
if is_webp:
|
|
||||||
image_quality = 100 - image_quality
|
|
||||||
return round(31 - (image_quality * 0.31))
|
|
||||||
|
|
||||||
|
|
||||||
def read_audio_buffer(target_path : str, sample_rate : int, channel_total : int) -> Optional[AudioBuffer]:
|
|
||||||
commands = [ '-i', target_path, '-vn', '-f', 's16le', '-acodec', 'pcm_s16le', '-ar', str(sample_rate), '-ac', str(channel_total), '-' ]
|
|
||||||
process = open_ffmpeg(commands)
|
|
||||||
audio_buffer, _ = process.communicate()
|
|
||||||
if process.returncode == 0:
|
|
||||||
return audio_buffer
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def restore_audio(target_path : str, output_path : str, output_video_fps : Fps) -> bool:
|
|
||||||
trim_frame_start = state_manager.get_item('trim_frame_start')
|
|
||||||
trim_frame_end = state_manager.get_item('trim_frame_end')
|
|
||||||
temp_file_path = get_temp_file_path(target_path)
|
|
||||||
commands = [ '-i', temp_file_path ]
|
|
||||||
|
|
||||||
if isinstance(trim_frame_start, int):
|
|
||||||
start_time = trim_frame_start / output_video_fps
|
|
||||||
commands.extend([ '-ss', str(start_time) ])
|
|
||||||
if isinstance(trim_frame_end, int):
|
|
||||||
end_time = trim_frame_end / output_video_fps
|
|
||||||
commands.extend([ '-to', str(end_time) ])
|
|
||||||
commands.extend([ '-i', target_path, '-c:v', 'copy', '-c:a', state_manager.get_item('output_audio_encoder'), '-map', '0:v:0', '-map', '1:a:0', '-shortest', '-y', output_path ])
|
|
||||||
return run_ffmpeg(commands).returncode == 0
|
|
||||||
|
|
||||||
|
|
||||||
def replace_audio(target_path : str, audio_path : str, output_path : str) -> bool:
|
|
||||||
temp_file_path = get_temp_file_path(target_path)
|
|
||||||
commands = [ '-i', temp_file_path, '-i', audio_path, '-c:a', state_manager.get_item('output_audio_encoder'), '-af', 'apad', '-shortest', '-y', output_path ]
|
|
||||||
return run_ffmpeg(commands).returncode == 0
|
|
||||||
|
|
||||||
|
|
||||||
def map_nvenc_preset(output_video_preset : OutputVideoPreset) -> Optional[str]:
|
|
||||||
if output_video_preset in [ 'ultrafast', 'superfast', 'veryfast', 'faster', 'fast' ]:
|
|
||||||
return 'fast'
|
|
||||||
if output_video_preset == 'medium':
|
|
||||||
return 'medium'
|
|
||||||
if output_video_preset in [ 'slow', 'slower', 'veryslow' ]:
|
|
||||||
return 'slow'
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def map_amf_preset(output_video_preset : OutputVideoPreset) -> Optional[str]:
|
|
||||||
if output_video_preset in [ 'ultrafast', 'superfast', 'veryfast' ]:
|
|
||||||
return 'speed'
|
|
||||||
if output_video_preset in [ 'faster', 'fast', 'medium' ]:
|
|
||||||
return 'balanced'
|
|
||||||
if output_video_preset in [ 'slow', 'slower', 'veryslow' ]:
|
|
||||||
return 'quality'
|
|
||||||
return None
|
|
||||||
|
|||||||
@@ -0,0 +1,240 @@
|
|||||||
|
import itertools
|
||||||
|
import shutil
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
import numpy
|
||||||
|
|
||||||
|
from facefusion.filesystem import get_file_format
|
||||||
|
from facefusion.types import AudioEncoder, Commands, Duration, Fps, StreamMode, VideoEncoder, VideoPreset
|
||||||
|
|
||||||
|
|
||||||
|
def run(commands : Commands) -> Commands:
|
||||||
|
return [ shutil.which('ffmpeg'), '-loglevel', 'error' ] + commands
|
||||||
|
|
||||||
|
|
||||||
|
def chain(*commands : Commands) -> Commands:
|
||||||
|
return list(itertools.chain(*commands))
|
||||||
|
|
||||||
|
|
||||||
|
def get_encoders() -> Commands:
|
||||||
|
return [ '-encoders' ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_progress() -> Commands:
|
||||||
|
return [ '-progress' ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_input(input_path : str) -> Commands:
|
||||||
|
return [ '-i', input_path ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_conditional_fps(conditional_fps : Fps) -> Commands:
|
||||||
|
return [ '-r', str(conditional_fps) ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_output(output_path : str) -> Commands:
|
||||||
|
return [ output_path ]
|
||||||
|
|
||||||
|
|
||||||
|
def force_output(output_path : str) -> Commands:
|
||||||
|
return [ '-y', output_path ]
|
||||||
|
|
||||||
|
|
||||||
|
def cast_stream() -> Commands:
|
||||||
|
return [ '-' ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_stream_mode(stream_mode : StreamMode) -> Commands:
|
||||||
|
if stream_mode == 'udp':
|
||||||
|
return [ '-f', 'mpegts' ]
|
||||||
|
if stream_mode == 'v4l2':
|
||||||
|
return [ '-f', 'v4l2' ]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def unsafe_concat() -> Commands:
|
||||||
|
return [ '-f', 'concat', '-safe', '0' ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_pixel_format(video_encoder : VideoEncoder) -> Commands:
|
||||||
|
if video_encoder == 'rawvideo':
|
||||||
|
return [ '-pix_fmt', 'rgb24' ]
|
||||||
|
return [ '-pix_fmt', 'yuv420p' ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_frame_quality(frame_quality : int) -> Commands:
|
||||||
|
return [ '-q:v', str(frame_quality) ]
|
||||||
|
|
||||||
|
|
||||||
|
def select_frame_range(frame_start : int, frame_end : int, video_fps : Fps) -> Commands:
|
||||||
|
if isinstance(frame_start, int) and isinstance(frame_end, int):
|
||||||
|
return [ '-vf', 'trim=start_frame=' + str(frame_start) + ':end_frame=' + str(frame_end) + ',fps=' + str(video_fps) ]
|
||||||
|
if isinstance(frame_start, int):
|
||||||
|
return [ '-vf', 'trim=start_frame=' + str(frame_start) + ',fps=' + str(video_fps) ]
|
||||||
|
if isinstance(frame_end, int):
|
||||||
|
return [ '-vf', 'trim=end_frame=' + str(frame_end) + ',fps=' + str(video_fps) ]
|
||||||
|
return [ '-vf', 'fps=' + str(video_fps) ]
|
||||||
|
|
||||||
|
|
||||||
|
def prevent_frame_drop() -> Commands:
|
||||||
|
return [ '-vsync', '0' ]
|
||||||
|
|
||||||
|
|
||||||
|
def select_media_range(frame_start : int, frame_end : int, media_fps : Fps) -> Commands:
|
||||||
|
commands = []
|
||||||
|
|
||||||
|
if isinstance(frame_start, int):
|
||||||
|
commands.extend([ '-ss', str(frame_start / media_fps) ])
|
||||||
|
if isinstance(frame_end, int):
|
||||||
|
commands.extend([ '-to', str(frame_end / media_fps) ])
|
||||||
|
return commands
|
||||||
|
|
||||||
|
|
||||||
|
def select_media_stream(media_stream : str) -> Commands:
|
||||||
|
return [ '-map', media_stream ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_media_resolution(video_resolution : str) -> Commands:
|
||||||
|
return [ '-s', video_resolution ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_image_quality(image_path : str, image_quality : int) -> Commands:
|
||||||
|
if get_file_format(image_path) == 'webp':
|
||||||
|
image_compression = image_quality
|
||||||
|
else:
|
||||||
|
image_compression = round(31 - (image_quality * 0.31))
|
||||||
|
return [ '-q:v', str(image_compression) ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_audio_encoder(audio_codec : str) -> Commands:
|
||||||
|
return [ '-c:a', audio_codec ]
|
||||||
|
|
||||||
|
|
||||||
|
def copy_audio_encoder() -> Commands:
|
||||||
|
return set_audio_encoder('copy')
|
||||||
|
|
||||||
|
|
||||||
|
def set_audio_sample_rate(audio_sample_rate : int) -> Commands:
|
||||||
|
return [ '-ar', str(audio_sample_rate) ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_audio_sample_size(audio_sample_size : int) -> Commands:
|
||||||
|
if audio_sample_size == 16:
|
||||||
|
return [ '-f', 's16le' ]
|
||||||
|
if audio_sample_size == 32:
|
||||||
|
return [ '-f', 's32le' ]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def set_audio_channel_total(audio_channel_total : int) -> Commands:
|
||||||
|
return [ '-ac', str(audio_channel_total) ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_audio_quality(audio_encoder : AudioEncoder, audio_quality : int) -> Commands:
|
||||||
|
if audio_encoder == 'aac':
|
||||||
|
audio_compression = round(numpy.interp(audio_quality, [ 0, 100 ], [ 0.1, 2.0 ]), 1)
|
||||||
|
return [ '-q:a', str(audio_compression) ]
|
||||||
|
if audio_encoder == 'libmp3lame':
|
||||||
|
audio_compression = round(numpy.interp(audio_quality, [ 0, 100 ], [ 9, 0 ]))
|
||||||
|
return [ '-q:a', str(audio_compression) ]
|
||||||
|
if audio_encoder == 'libopus':
|
||||||
|
audio_bit_rate = round(numpy.interp(audio_quality, [ 0, 100 ], [ 64, 320 ]))
|
||||||
|
return [ '-b:a', str(audio_bit_rate) + 'k' ]
|
||||||
|
if audio_encoder == 'libvorbis':
|
||||||
|
audio_compression = round(numpy.interp(audio_quality, [ 0, 100 ], [ -1, 10 ]), 1)
|
||||||
|
return [ '-q:a', str(audio_compression) ]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def set_audio_volume(audio_volume : int) -> Commands:
|
||||||
|
return [ '-filter:a', 'volume=' + str(audio_volume / 100) ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_video_encoder(video_encoder : str) -> Commands:
|
||||||
|
return [ '-c:v', video_encoder ]
|
||||||
|
|
||||||
|
|
||||||
|
def copy_video_encoder() -> Commands:
|
||||||
|
return set_video_encoder('copy')
|
||||||
|
|
||||||
|
|
||||||
|
def set_video_quality(video_encoder : VideoEncoder, video_quality : int) -> Commands:
|
||||||
|
if video_encoder in [ 'libx264', 'libx265' ]:
|
||||||
|
video_compression = round(numpy.interp(video_quality, [ 0, 100 ], [ 51, 0 ]))
|
||||||
|
return [ '-crf', str(video_compression) ]
|
||||||
|
if video_encoder == 'libvpx-vp9':
|
||||||
|
video_compression = round(numpy.interp(video_quality, [ 0, 100 ], [ 63, 0 ]))
|
||||||
|
return [ '-crf', str(video_compression) ]
|
||||||
|
if video_encoder in [ 'h264_nvenc', 'hevc_nvenc' ]:
|
||||||
|
video_compression = round(numpy.interp(video_quality, [ 0, 100 ], [ 51, 0 ]))
|
||||||
|
return [ '-cq', str(video_compression) ]
|
||||||
|
if video_encoder in [ 'h264_amf', 'hevc_amf' ]:
|
||||||
|
video_compression = round(numpy.interp(video_quality, [ 0, 100 ], [ 51, 0 ]))
|
||||||
|
return [ '-qp_i', str(video_compression), '-qp_p', str(video_compression), '-qp_b', str(video_compression) ]
|
||||||
|
if video_encoder in [ 'h264_qsv', 'hevc_qsv' ]:
|
||||||
|
video_compression = round(numpy.interp(video_quality, [ 0, 100 ], [ 51, 0 ]))
|
||||||
|
return [ '-qp', str(video_compression) ]
|
||||||
|
if video_encoder in [ 'h264_videotoolbox', 'hevc_videotoolbox' ]:
|
||||||
|
video_bit_rate = round(numpy.interp(video_quality, [ 0, 100 ], [ 1024, 50512 ]))
|
||||||
|
return [ '-b:v', str(video_bit_rate) + 'k' ]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def set_video_preset(video_encoder : VideoEncoder, video_preset : VideoPreset) -> Commands:
|
||||||
|
if video_encoder in [ 'libx264', 'libx265' ]:
|
||||||
|
return [ '-preset', video_preset ]
|
||||||
|
if video_encoder in [ 'h264_nvenc', 'hevc_nvenc' ]:
|
||||||
|
return [ '-preset', map_nvenc_preset(video_preset) ]
|
||||||
|
if video_encoder in [ 'h264_amf', 'hevc_amf' ]:
|
||||||
|
return [ '-quality', map_amf_preset(video_preset) ]
|
||||||
|
if video_encoder in [ 'h264_qsv', 'hevc_qsv' ]:
|
||||||
|
return [ '-preset', map_qsv_preset(video_preset) ]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def set_video_colorspace(video_colorspace : str) -> Commands:
|
||||||
|
return [ '-colorspace', video_colorspace ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_video_fps(video_fps : Fps) -> Commands:
|
||||||
|
return [ '-vf', 'framerate=fps=' + str(video_fps) ]
|
||||||
|
|
||||||
|
|
||||||
|
def set_video_duration(video_duration : Duration) -> Commands:
|
||||||
|
return [ '-t', str(video_duration) ]
|
||||||
|
|
||||||
|
|
||||||
|
def capture_video() -> Commands:
|
||||||
|
return [ '-f', 'rawvideo' ]
|
||||||
|
|
||||||
|
|
||||||
|
def ignore_video_stream() -> Commands:
|
||||||
|
return [ '-vn' ]
|
||||||
|
|
||||||
|
|
||||||
|
def map_nvenc_preset(video_preset : VideoPreset) -> Optional[str]:
|
||||||
|
if video_preset in [ 'ultrafast', 'superfast', 'veryfast', 'faster', 'fast' ]:
|
||||||
|
return 'fast'
|
||||||
|
if video_preset == 'medium':
|
||||||
|
return 'medium'
|
||||||
|
if video_preset in [ 'slow', 'slower', 'veryslow' ]:
|
||||||
|
return 'slow'
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def map_amf_preset(video_preset : VideoPreset) -> Optional[str]:
|
||||||
|
if video_preset in [ 'ultrafast', 'superfast', 'veryfast' ]:
|
||||||
|
return 'speed'
|
||||||
|
if video_preset in [ 'faster', 'fast', 'medium' ]:
|
||||||
|
return 'balanced'
|
||||||
|
if video_preset in [ 'slow', 'slower', 'veryslow' ]:
|
||||||
|
return 'quality'
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def map_qsv_preset(video_preset : VideoPreset) -> Optional[str]:
|
||||||
|
if video_preset in [ 'ultrafast', 'superfast', 'veryfast' ]:
|
||||||
|
return 'veryfast'
|
||||||
|
if video_preset in [ 'faster', 'fast', 'medium', 'slow', 'slower', 'veryslow' ]:
|
||||||
|
return video_preset
|
||||||
|
return None
|
||||||
+106
-58
@@ -1,14 +1,9 @@
|
|||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
import filetype
|
import facefusion.choices
|
||||||
|
|
||||||
from facefusion.common_helper import is_windows
|
|
||||||
|
|
||||||
if is_windows():
|
|
||||||
import ctypes
|
|
||||||
|
|
||||||
|
|
||||||
def get_file_size(file_path : str) -> int:
|
def get_file_size(file_path : str) -> int:
|
||||||
@@ -17,54 +12,95 @@ def get_file_size(file_path : str) -> int:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def same_file_extension(file_paths : List[str]) -> bool:
|
def get_file_name(file_path : str) -> Optional[str]:
|
||||||
file_extensions : List[str] = []
|
file_name, _ = os.path.splitext(os.path.basename(file_path))
|
||||||
|
|
||||||
for file_path in file_paths:
|
if file_name:
|
||||||
_, file_extension = os.path.splitext(file_path.lower())
|
return file_name
|
||||||
|
return None
|
||||||
|
|
||||||
if file_extensions and file_extension not in file_extensions:
|
|
||||||
return False
|
def get_file_extension(file_path : str) -> Optional[str]:
|
||||||
file_extensions.append(file_extension)
|
_, file_extension = os.path.splitext(file_path)
|
||||||
return True
|
|
||||||
|
if file_extension:
|
||||||
|
return file_extension.lower()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_file_format(file_path : str) -> Optional[str]:
|
||||||
|
file_extension = get_file_extension(file_path)
|
||||||
|
|
||||||
|
if file_extension:
|
||||||
|
if file_extension == '.jpg':
|
||||||
|
return 'jpeg'
|
||||||
|
if file_extension == '.tif':
|
||||||
|
return 'tiff'
|
||||||
|
return file_extension.lstrip('.')
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def same_file_extension(first_file_path : str, second_file_path : str) -> bool:
|
||||||
|
first_file_extension = get_file_extension(first_file_path)
|
||||||
|
second_file_extension = get_file_extension(second_file_path)
|
||||||
|
|
||||||
|
if first_file_extension and second_file_extension:
|
||||||
|
return get_file_extension(first_file_path) == get_file_extension(second_file_path)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_file(file_path : str) -> bool:
|
def is_file(file_path : str) -> bool:
|
||||||
return bool(file_path and os.path.isfile(file_path))
|
if file_path:
|
||||||
|
return os.path.isfile(file_path)
|
||||||
|
|
||||||
def is_directory(directory_path : str) -> bool:
|
|
||||||
return bool(directory_path and os.path.isdir(directory_path))
|
|
||||||
|
|
||||||
|
|
||||||
def in_directory(file_path : str) -> bool:
|
|
||||||
if file_path and not is_directory(file_path):
|
|
||||||
return is_directory(os.path.dirname(file_path))
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_audio(audio_path : str) -> bool:
|
def is_audio(audio_path : str) -> bool:
|
||||||
return is_file(audio_path) and filetype.helpers.is_audio(audio_path)
|
return is_file(audio_path) and get_file_format(audio_path) in facefusion.choices.audio_formats
|
||||||
|
|
||||||
|
|
||||||
def has_audio(audio_paths : List[str]) -> bool:
|
def has_audio(audio_paths : List[str]) -> bool:
|
||||||
if audio_paths:
|
if audio_paths:
|
||||||
return any(is_audio(audio_path) for audio_path in audio_paths)
|
return any(map(is_audio, audio_paths))
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def are_audios(audio_paths : List[str]) -> bool:
|
||||||
|
if audio_paths:
|
||||||
|
return all(map(is_audio, audio_paths))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_image(image_path : str) -> bool:
|
def is_image(image_path : str) -> bool:
|
||||||
return is_file(image_path) and filetype.helpers.is_image(image_path)
|
return is_file(image_path) and get_file_format(image_path) in facefusion.choices.image_formats
|
||||||
|
|
||||||
|
|
||||||
def has_image(image_paths: List[str]) -> bool:
|
def has_image(image_paths : List[str]) -> bool:
|
||||||
if image_paths:
|
if image_paths:
|
||||||
return any(is_image(image_path) for image_path in image_paths)
|
return any(is_image(image_path) for image_path in image_paths)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def are_images(image_paths : List[str]) -> bool:
|
||||||
|
if image_paths:
|
||||||
|
return all(map(is_image, image_paths))
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_video(video_path : str) -> bool:
|
def is_video(video_path : str) -> bool:
|
||||||
return is_file(video_path) and filetype.helpers.is_video(video_path)
|
return is_file(video_path) and get_file_format(video_path) in facefusion.choices.video_formats
|
||||||
|
|
||||||
|
|
||||||
|
def has_video(video_paths : List[str]) -> bool:
|
||||||
|
if video_paths:
|
||||||
|
return any(map(is_video, video_paths))
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def are_videos(video_paths : List[str]) -> bool:
|
||||||
|
if video_paths:
|
||||||
|
return any(map(is_video, video_paths))
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def filter_audio_paths(paths : List[str]) -> List[str]:
|
def filter_audio_paths(paths : List[str]) -> List[str]:
|
||||||
@@ -79,24 +115,6 @@ def filter_image_paths(paths : List[str]) -> List[str]:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def resolve_relative_path(path : str) -> str:
|
|
||||||
return os.path.abspath(os.path.join(os.path.dirname(__file__), path))
|
|
||||||
|
|
||||||
|
|
||||||
def sanitize_path_for_windows(full_path : str) -> Optional[str]:
|
|
||||||
buffer_size = 0
|
|
||||||
|
|
||||||
while True:
|
|
||||||
unicode_buffer = ctypes.create_unicode_buffer(buffer_size)
|
|
||||||
buffer_limit = ctypes.windll.kernel32.GetShortPathNameW(full_path, unicode_buffer, buffer_size) #type:ignore[attr-defined]
|
|
||||||
|
|
||||||
if buffer_size > buffer_limit:
|
|
||||||
return unicode_buffer.value
|
|
||||||
if buffer_limit == 0:
|
|
||||||
return None
|
|
||||||
buffer_size = buffer_limit
|
|
||||||
|
|
||||||
|
|
||||||
def copy_file(file_path : str, move_path : str) -> bool:
|
def copy_file(file_path : str, move_path : str) -> bool:
|
||||||
if is_file(file_path):
|
if is_file(file_path):
|
||||||
shutil.copy(file_path, move_path)
|
shutil.copy(file_path, move_path)
|
||||||
@@ -118,19 +136,45 @@ def remove_file(file_path : str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def create_directory(directory_path : str) -> bool:
|
def resolve_file_paths(directory_path : str) -> List[str]:
|
||||||
if directory_path and not is_file(directory_path):
|
file_paths : List[str] = []
|
||||||
Path(directory_path).mkdir(parents = True, exist_ok = True)
|
|
||||||
return is_directory(directory_path)
|
if is_directory(directory_path):
|
||||||
|
file_names_and_extensions = sorted(os.listdir(directory_path))
|
||||||
|
|
||||||
|
for file_name_and_extension in file_names_and_extensions:
|
||||||
|
if not file_name_and_extension.startswith(('.', '__')):
|
||||||
|
file_path = os.path.join(directory_path, file_name_and_extension)
|
||||||
|
file_paths.append(file_path)
|
||||||
|
|
||||||
|
return file_paths
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_file_pattern(file_pattern : str) -> List[str]:
|
||||||
|
if in_directory(file_pattern):
|
||||||
|
return sorted(glob.glob(file_pattern))
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def is_directory(directory_path : str) -> bool:
|
||||||
|
if directory_path:
|
||||||
|
return os.path.isdir(directory_path)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def list_directory(directory_path : str) -> Optional[List[str]]:
|
def in_directory(file_path : str) -> bool:
|
||||||
if is_directory(directory_path):
|
if file_path:
|
||||||
files = os.listdir(directory_path)
|
directory_path = os.path.dirname(file_path)
|
||||||
files = [ Path(file).stem for file in files if not Path(file).stem.startswith(('.', '__')) ]
|
if directory_path:
|
||||||
return sorted(files)
|
return not is_directory(file_path) and is_directory(directory_path)
|
||||||
return None
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def create_directory(directory_path : str) -> bool:
|
||||||
|
if directory_path and not is_file(directory_path):
|
||||||
|
os.makedirs(directory_path, exist_ok = True)
|
||||||
|
return is_directory(directory_path)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def remove_directory(directory_path : str) -> bool:
|
def remove_directory(directory_path : str) -> bool:
|
||||||
@@ -138,3 +182,7 @@ def remove_directory(directory_path : str) -> bool:
|
|||||||
shutil.rmtree(directory_path, ignore_errors = True)
|
shutil.rmtree(directory_path, ignore_errors = True)
|
||||||
return not is_directory(directory_path)
|
return not is_directory(directory_path)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_relative_path(path : str) -> str:
|
||||||
|
return os.path.abspath(os.path.join(os.path.dirname(__file__), path))
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import os
|
|||||||
import zlib
|
import zlib
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from facefusion.filesystem import is_file
|
from facefusion.filesystem import get_file_name, is_file
|
||||||
|
|
||||||
|
|
||||||
def create_hash(content : bytes) -> str:
|
def create_hash(content : bytes) -> str:
|
||||||
@@ -13,8 +13,8 @@ def validate_hash(validate_path : str) -> bool:
|
|||||||
hash_path = get_hash_path(validate_path)
|
hash_path = get_hash_path(validate_path)
|
||||||
|
|
||||||
if is_file(hash_path):
|
if is_file(hash_path):
|
||||||
with open(hash_path, 'r') as hash_file:
|
with open(hash_path) as hash_file:
|
||||||
hash_content = hash_file.read().strip()
|
hash_content = hash_file.read()
|
||||||
|
|
||||||
with open(validate_path, 'rb') as validate_file:
|
with open(validate_path, 'rb') as validate_file:
|
||||||
validate_content = validate_file.read()
|
validate_content = validate_file.read()
|
||||||
@@ -25,8 +25,8 @@ def validate_hash(validate_path : str) -> bool:
|
|||||||
|
|
||||||
def get_hash_path(validate_path : str) -> Optional[str]:
|
def get_hash_path(validate_path : str) -> Optional[str]:
|
||||||
if is_file(validate_path):
|
if is_file(validate_path):
|
||||||
validate_directory_path, _ = os.path.split(validate_path)
|
validate_directory_path, file_name_and_extension = os.path.split(validate_path)
|
||||||
validate_file_name, _ = os.path.splitext(_)
|
validate_file_name = get_file_name(file_name_and_extension)
|
||||||
|
|
||||||
return os.path.join(validate_directory_path, validate_file_name + '.hash')
|
return os.path.join(validate_directory_path, validate_file_name + '.hash')
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -1,79 +1,74 @@
|
|||||||
from functools import lru_cache
|
import importlib
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import onnx
|
|
||||||
from onnxruntime import InferenceSession
|
from onnxruntime import InferenceSession
|
||||||
|
|
||||||
from facefusion import process_manager, state_manager
|
from facefusion import process_manager, state_manager
|
||||||
from facefusion.app_context import detect_app_context
|
from facefusion.app_context import detect_app_context
|
||||||
from facefusion.execution import create_execution_providers, has_execution_provider
|
from facefusion.execution import create_inference_session_providers
|
||||||
from facefusion.thread_helper import thread_lock
|
from facefusion.filesystem import is_file
|
||||||
from facefusion.typing import DownloadSet, ExecutionProviderKey, InferencePool, InferencePoolSet, ModelInitializer
|
from facefusion.types import DownloadSet, ExecutionProvider, InferencePool, InferencePoolSet
|
||||||
|
|
||||||
INFERENCE_POOLS : InferencePoolSet =\
|
INFERENCE_POOL_SET : InferencePoolSet =\
|
||||||
{
|
{
|
||||||
'cli': {}, # type:ignore[typeddict-item]
|
'cli': {},
|
||||||
'ui': {} # type:ignore[typeddict-item]
|
'ui': {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool(model_context : str, model_sources : DownloadSet) -> InferencePool:
|
def get_inference_pool(module_name : str, model_names : List[str], model_source_set : DownloadSet) -> InferencePool:
|
||||||
global INFERENCE_POOLS
|
while process_manager.is_checking():
|
||||||
|
sleep(0.5)
|
||||||
|
execution_device_id = state_manager.get_item('execution_device_id')
|
||||||
|
execution_providers = resolve_execution_providers(module_name)
|
||||||
|
app_context = detect_app_context()
|
||||||
|
inference_context = get_inference_context(module_name, model_names, execution_device_id, execution_providers)
|
||||||
|
|
||||||
with thread_lock():
|
if app_context == 'cli' and INFERENCE_POOL_SET.get('ui').get(inference_context):
|
||||||
while process_manager.is_checking():
|
INFERENCE_POOL_SET['cli'][inference_context] = INFERENCE_POOL_SET.get('ui').get(inference_context)
|
||||||
sleep(0.5)
|
if app_context == 'ui' and INFERENCE_POOL_SET.get('cli').get(inference_context):
|
||||||
app_context = detect_app_context()
|
INFERENCE_POOL_SET['ui'][inference_context] = INFERENCE_POOL_SET.get('cli').get(inference_context)
|
||||||
inference_context = get_inference_context(model_context)
|
if not INFERENCE_POOL_SET.get(app_context).get(inference_context):
|
||||||
|
INFERENCE_POOL_SET[app_context][inference_context] = create_inference_pool(model_source_set, execution_device_id, execution_providers)
|
||||||
|
|
||||||
if app_context == 'cli' and INFERENCE_POOLS.get('ui').get(inference_context):
|
return INFERENCE_POOL_SET.get(app_context).get(inference_context)
|
||||||
INFERENCE_POOLS['cli'][inference_context] = INFERENCE_POOLS.get('ui').get(inference_context)
|
|
||||||
if app_context == 'ui' and INFERENCE_POOLS.get('cli').get(inference_context):
|
|
||||||
INFERENCE_POOLS['ui'][inference_context] = INFERENCE_POOLS.get('cli').get(inference_context)
|
|
||||||
if not INFERENCE_POOLS.get(app_context).get(inference_context):
|
|
||||||
execution_provider_keys = resolve_execution_provider_keys(model_context)
|
|
||||||
INFERENCE_POOLS[app_context][inference_context] = create_inference_pool(model_sources, state_manager.get_item('execution_device_id'), execution_provider_keys)
|
|
||||||
|
|
||||||
return INFERENCE_POOLS.get(app_context).get(inference_context)
|
|
||||||
|
|
||||||
|
|
||||||
def create_inference_pool(model_sources : DownloadSet, execution_device_id : str, execution_provider_keys : List[ExecutionProviderKey]) -> InferencePool:
|
def create_inference_pool(model_source_set : DownloadSet, execution_device_id : str, execution_providers : List[ExecutionProvider]) -> InferencePool:
|
||||||
inference_pool : InferencePool = {}
|
inference_pool : InferencePool = {}
|
||||||
|
|
||||||
for model_name in model_sources.keys():
|
for model_name in model_source_set.keys():
|
||||||
inference_pool[model_name] = create_inference_session(model_sources.get(model_name).get('path'), execution_device_id, execution_provider_keys)
|
model_path = model_source_set.get(model_name).get('path')
|
||||||
|
if is_file(model_path):
|
||||||
|
inference_pool[model_name] = create_inference_session(model_path, execution_device_id, execution_providers)
|
||||||
|
|
||||||
return inference_pool
|
return inference_pool
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool(model_context : str) -> None:
|
def clear_inference_pool(module_name : str, model_names : List[str]) -> None:
|
||||||
global INFERENCE_POOLS
|
execution_device_id = state_manager.get_item('execution_device_id')
|
||||||
|
execution_providers = resolve_execution_providers(module_name)
|
||||||
app_context = detect_app_context()
|
app_context = detect_app_context()
|
||||||
inference_context = get_inference_context(model_context)
|
inference_context = get_inference_context(module_name, model_names, execution_device_id, execution_providers)
|
||||||
|
|
||||||
if INFERENCE_POOLS.get(app_context).get(inference_context):
|
if INFERENCE_POOL_SET.get(app_context).get(inference_context):
|
||||||
del INFERENCE_POOLS[app_context][inference_context]
|
del INFERENCE_POOL_SET[app_context][inference_context]
|
||||||
|
|
||||||
|
|
||||||
def create_inference_session(model_path : str, execution_device_id : str, execution_provider_keys : List[ExecutionProviderKey]) -> InferenceSession:
|
def create_inference_session(model_path : str, execution_device_id : str, execution_providers : List[ExecutionProvider]) -> InferenceSession:
|
||||||
execution_providers = create_execution_providers(execution_device_id, execution_provider_keys)
|
inference_session_providers = create_inference_session_providers(execution_device_id, execution_providers)
|
||||||
return InferenceSession(model_path, providers = execution_providers)
|
return InferenceSession(model_path, providers = inference_session_providers)
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize = None)
|
def get_inference_context(module_name : str, model_names : List[str], execution_device_id : str, execution_providers : List[ExecutionProvider]) -> str:
|
||||||
def get_static_model_initializer(model_path : str) -> ModelInitializer:
|
inference_context = '.'.join([ module_name ] + model_names + [ execution_device_id ] + list(execution_providers))
|
||||||
model = onnx.load(model_path)
|
|
||||||
return onnx.numpy_helper.to_array(model.graph.initializer[-1])
|
|
||||||
|
|
||||||
|
|
||||||
def resolve_execution_provider_keys(model_context : str) -> List[ExecutionProviderKey]:
|
|
||||||
if has_execution_provider('coreml') and (model_context.startswith('facefusion.processors.modules.age_modifier') or model_context.startswith('facefusion.processors.modules.frame_colorizer')):
|
|
||||||
return [ 'cpu' ]
|
|
||||||
return state_manager.get_item('execution_providers')
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_context(model_context : str) -> str:
|
|
||||||
execution_provider_keys = resolve_execution_provider_keys(model_context)
|
|
||||||
inference_context = model_context + '.' + '_'.join(execution_provider_keys)
|
|
||||||
return inference_context
|
return inference_context
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_execution_providers(module_name : str) -> List[ExecutionProvider]:
|
||||||
|
module = importlib.import_module(module_name)
|
||||||
|
|
||||||
|
if hasattr(module, 'resolve_execution_providers'):
|
||||||
|
return getattr(module, 'resolve_execution_providers')()
|
||||||
|
return state_manager.get_item('execution_providers')
|
||||||
|
|||||||
+26
-30
@@ -3,31 +3,28 @@ import shutil
|
|||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
from argparse import ArgumentParser, HelpFormatter
|
from argparse import ArgumentParser, HelpFormatter
|
||||||
from typing import Dict, Tuple
|
|
||||||
|
|
||||||
from facefusion import metadata, wording
|
from facefusion import metadata, wording
|
||||||
from facefusion.common_helper import is_linux, is_macos, is_windows
|
from facefusion.common_helper import is_linux, is_windows
|
||||||
|
|
||||||
ONNXRUNTIMES : Dict[str, Tuple[str, str]] = {}
|
ONNXRUNTIME_SET =\
|
||||||
|
{
|
||||||
if is_macos():
|
'default': ('onnxruntime', '1.21.1')
|
||||||
ONNXRUNTIMES['default'] = ('onnxruntime', '1.19.2')
|
}
|
||||||
else:
|
if is_windows() or is_linux():
|
||||||
ONNXRUNTIMES['default'] = ('onnxruntime', '1.19.2')
|
ONNXRUNTIME_SET['cuda'] = ('onnxruntime-gpu', '1.21.1')
|
||||||
ONNXRUNTIMES['cuda'] = ('onnxruntime-gpu', '1.19.2')
|
ONNXRUNTIME_SET['openvino'] = ('onnxruntime-openvino', '1.21.0')
|
||||||
ONNXRUNTIMES['openvino'] = ('onnxruntime-openvino', '1.19.0')
|
|
||||||
if is_linux():
|
|
||||||
ONNXRUNTIMES['rocm'] = ('onnxruntime-rocm', '1.18.0')
|
|
||||||
if is_windows():
|
if is_windows():
|
||||||
ONNXRUNTIMES['directml'] = ('onnxruntime-directml', '1.17.3')
|
ONNXRUNTIME_SET['directml'] = ('onnxruntime-directml', '1.17.3')
|
||||||
|
if is_linux():
|
||||||
|
ONNXRUNTIME_SET['rocm'] = ('onnxruntime-rocm', '1.21.0')
|
||||||
|
|
||||||
|
|
||||||
def cli() -> None:
|
def cli() -> None:
|
||||||
signal.signal(signal.SIGINT, lambda signal_number, frame: sys.exit(0))
|
signal.signal(signal.SIGINT, lambda signal_number, frame: sys.exit(0))
|
||||||
program = ArgumentParser(formatter_class = lambda prog: HelpFormatter(prog, max_help_position = 50))
|
program = ArgumentParser(formatter_class = lambda prog: HelpFormatter(prog, max_help_position = 50))
|
||||||
program.add_argument('--onnxruntime', help = wording.get('help.install_dependency').format(dependency = 'onnxruntime'), choices = ONNXRUNTIMES.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')
|
||||||
run(program)
|
run(program)
|
||||||
@@ -36,27 +33,27 @@ def cli() -> None:
|
|||||||
def run(program : ArgumentParser) -> None:
|
def run(program : ArgumentParser) -> None:
|
||||||
args = program.parse_args()
|
args = program.parse_args()
|
||||||
has_conda = 'CONDA_PREFIX' in os.environ
|
has_conda = 'CONDA_PREFIX' in os.environ
|
||||||
onnxruntime_name, onnxruntime_version = ONNXRUNTIMES.get(args.onnxruntime)
|
onnxruntime_name, onnxruntime_version = ONNXRUNTIME_SET.get(args.onnxruntime)
|
||||||
|
|
||||||
if not args.skip_conda and not has_conda:
|
if not args.skip_conda and not has_conda:
|
||||||
sys.stdout.write(wording.get('conda_not_activated') + os.linesep)
|
sys.stdout.write(wording.get('conda_not_activated') + os.linesep)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
subprocess.call([ shutil.which('pip'), 'install', '-r', 'requirements.txt', '--force-reinstall' ])
|
with open('requirements.txt') as file:
|
||||||
|
|
||||||
|
for line in file.readlines():
|
||||||
|
__line__ = line.strip()
|
||||||
|
if not __line__.startswith('onnxruntime'):
|
||||||
|
subprocess.call([ shutil.which('pip'), 'install', line, '--force-reinstall' ])
|
||||||
|
|
||||||
if args.onnxruntime == 'rocm':
|
if args.onnxruntime == 'rocm':
|
||||||
python_id = 'cp' + str(sys.version_info.major) + str(sys.version_info.minor)
|
python_id = 'cp' + str(sys.version_info.major) + str(sys.version_info.minor)
|
||||||
|
|
||||||
if python_id == 'cp310':
|
if python_id in [ 'cp310', 'cp312' ]:
|
||||||
wheel_name = 'onnxruntime_rocm-' + onnxruntime_version +'-' + python_id + '-' + python_id + '-linux_x86_64.whl'
|
wheel_name = 'onnxruntime_rocm-' + onnxruntime_version + '-' + python_id + '-' + python_id + '-linux_x86_64.whl'
|
||||||
wheel_path = os.path.join(tempfile.gettempdir(), wheel_name)
|
wheel_url = 'https://repo.radeon.com/rocm/manylinux/rocm-rel-6.4/' + wheel_name
|
||||||
wheel_url = 'https://repo.radeon.com/rocm/manylinux/rocm-rel-6.2/' + wheel_name
|
subprocess.call([ shutil.which('pip'), 'install', wheel_url, '--force-reinstall' ])
|
||||||
subprocess.call([ shutil.which('curl'), '--silent', '--location', '--continue-at', '-', '--output', wheel_path, wheel_url ])
|
|
||||||
subprocess.call([ shutil.which('pip'), 'uninstall', 'onnxruntime', wheel_path, '-y', '-q' ])
|
|
||||||
subprocess.call([ shutil.which('pip'), 'install', wheel_path, '--force-reinstall' ])
|
|
||||||
os.remove(wheel_path)
|
|
||||||
else:
|
else:
|
||||||
subprocess.call([ shutil.which('pip'), 'uninstall', 'onnxruntime', onnxruntime_name, '-y', '-q' ])
|
|
||||||
subprocess.call([ shutil.which('pip'), 'install', onnxruntime_name + '==' + onnxruntime_version, '--force-reinstall' ])
|
subprocess.call([ shutil.which('pip'), 'install', onnxruntime_name + '==' + onnxruntime_version, '--force-reinstall' ])
|
||||||
|
|
||||||
if args.onnxruntime == 'cuda' and has_conda:
|
if args.onnxruntime == 'cuda' and has_conda:
|
||||||
@@ -72,7 +69,7 @@ def run(program : ArgumentParser) -> None:
|
|||||||
os.path.join(os.getenv('CONDA_PREFIX'), 'lib'),
|
os.path.join(os.getenv('CONDA_PREFIX'), 'lib'),
|
||||||
os.path.join(os.getenv('CONDA_PREFIX'), 'lib', python_id, 'site-packages', 'tensorrt_libs')
|
os.path.join(os.getenv('CONDA_PREFIX'), 'lib', python_id, 'site-packages', 'tensorrt_libs')
|
||||||
])
|
])
|
||||||
library_paths = [ library_path for library_path in library_paths if os.path.exists(library_path) ]
|
library_paths = list(dict.fromkeys([ library_path for library_path in library_paths if os.path.exists(library_path) ]))
|
||||||
|
|
||||||
subprocess.call([ shutil.which('conda'), 'env', 'config', 'vars', 'set', 'LD_LIBRARY_PATH=' + os.pathsep.join(library_paths) ])
|
subprocess.call([ shutil.which('conda'), 'env', 'config', 'vars', 'set', 'LD_LIBRARY_PATH=' + os.pathsep.join(library_paths) ])
|
||||||
|
|
||||||
@@ -85,10 +82,9 @@ def run(program : ArgumentParser) -> None:
|
|||||||
os.path.join(os.getenv('CONDA_PREFIX'), 'Lib'),
|
os.path.join(os.getenv('CONDA_PREFIX'), 'Lib'),
|
||||||
os.path.join(os.getenv('CONDA_PREFIX'), 'Lib', 'site-packages', 'tensorrt_libs')
|
os.path.join(os.getenv('CONDA_PREFIX'), 'Lib', 'site-packages', 'tensorrt_libs')
|
||||||
])
|
])
|
||||||
library_paths = [ library_path for library_path in library_paths if os.path.exists(library_path) ]
|
library_paths = list(dict.fromkeys([ library_path for library_path in library_paths if os.path.exists(library_path) ]))
|
||||||
|
|
||||||
subprocess.call([ shutil.which('conda'), 'env', 'config', 'vars', 'set', 'PATH=' + os.pathsep.join(library_paths) ])
|
subprocess.call([ shutil.which('conda'), 'env', 'config', 'vars', 'set', 'PATH=' + os.pathsep.join(library_paths) ])
|
||||||
|
|
||||||
if onnxruntime_version < '1.19.0':
|
if args.onnxruntime == 'directml':
|
||||||
subprocess.call([ shutil.which('pip'), 'install', 'numpy==1.26.4', '--force-reinstall' ])
|
subprocess.call([ shutil.which('pip'), 'install', 'numpy==1.26.4', '--force-reinstall' ])
|
||||||
subprocess.call([ shutil.which('pip'), 'install', 'python-multipart==0.0.12', '--force-reinstall' ])
|
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ import os
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from facefusion.filesystem import get_file_extension, get_file_name
|
||||||
|
|
||||||
|
|
||||||
def get_step_output_path(job_id : str, step_index : int, output_path : str) -> Optional[str]:
|
def get_step_output_path(job_id : str, step_index : int, output_path : str) -> Optional[str]:
|
||||||
if output_path:
|
if output_path:
|
||||||
output_directory_path, _ = os.path.split(output_path)
|
output_directory_path, _ = os.path.split(output_path)
|
||||||
output_file_name, output_file_extension = os.path.splitext(_)
|
output_file_name = get_file_name(_)
|
||||||
|
output_file_extension = get_file_extension(_)
|
||||||
return os.path.join(output_directory_path, output_file_name + '-' + job_id + '-' + str(step_index) + output_file_extension)
|
return os.path.join(output_directory_path, output_file_name + '-' + job_id + '-' + str(step_index) + output_file_extension)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from typing import Optional, Tuple
|
|||||||
|
|
||||||
from facefusion.date_helper import describe_time_ago
|
from facefusion.date_helper import describe_time_ago
|
||||||
from facefusion.jobs import job_manager
|
from facefusion.jobs import job_manager
|
||||||
from facefusion.typing import JobStatus, TableContents, TableHeaders
|
from facefusion.types import JobStatus, TableContents, TableHeaders
|
||||||
|
|
||||||
|
|
||||||
def compose_job_list(job_status : JobStatus) -> Tuple[TableHeaders, TableContents]:
|
def compose_job_list(job_status : JobStatus) -> Tuple[TableHeaders, TableContents]:
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
import glob
|
|
||||||
import os
|
import os
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from facefusion.choices import job_statuses
|
import facefusion.choices
|
||||||
from facefusion.date_helper import get_current_date_time
|
from facefusion.date_helper import get_current_date_time
|
||||||
from facefusion.filesystem import create_directory, is_directory, is_file, move_file, remove_directory, remove_file
|
from facefusion.filesystem import create_directory, get_file_name, is_directory, is_file, move_file, remove_directory, remove_file, resolve_file_pattern
|
||||||
from facefusion.jobs.job_helper import get_step_output_path
|
from facefusion.jobs.job_helper import get_step_output_path
|
||||||
from facefusion.json import read_json, write_json
|
from facefusion.json import read_json, write_json
|
||||||
from facefusion.temp_helper import create_base_directory
|
from facefusion.types import Args, Job, JobSet, JobStatus, JobStep, JobStepStatus
|
||||||
from facefusion.typing import Args, Job, JobSet, JobStatus, JobStep, JobStepStatus
|
|
||||||
|
|
||||||
JOBS_PATH : Optional[str] = None
|
JOBS_PATH : Optional[str] = None
|
||||||
|
|
||||||
@@ -18,9 +16,8 @@ def init_jobs(jobs_path : str) -> bool:
|
|||||||
global JOBS_PATH
|
global JOBS_PATH
|
||||||
|
|
||||||
JOBS_PATH = jobs_path
|
JOBS_PATH = jobs_path
|
||||||
job_status_paths = [ os.path.join(JOBS_PATH, job_status) for job_status in job_statuses ]
|
job_status_paths = [ os.path.join(JOBS_PATH, job_status) for job_status in facefusion.choices.job_statuses ]
|
||||||
|
|
||||||
create_base_directory()
|
|
||||||
for job_status_path in job_status_paths:
|
for job_status_path in job_status_paths:
|
||||||
create_directory(job_status_path)
|
create_directory(job_status_path)
|
||||||
return all(is_directory(status_path) for status_path in job_status_paths)
|
return all(is_directory(status_path) for status_path in job_status_paths)
|
||||||
@@ -51,14 +48,17 @@ def submit_job(job_id : str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def submit_jobs() -> bool:
|
def submit_jobs(halt_on_error : bool) -> bool:
|
||||||
drafted_job_ids = find_job_ids('drafted')
|
drafted_job_ids = find_job_ids('drafted')
|
||||||
|
has_error = False
|
||||||
|
|
||||||
if drafted_job_ids:
|
if drafted_job_ids:
|
||||||
for job_id in drafted_job_ids:
|
for job_id in drafted_job_ids:
|
||||||
if not submit_job(job_id):
|
if not submit_job(job_id):
|
||||||
return False
|
has_error = True
|
||||||
return True
|
if halt_on_error:
|
||||||
|
return False
|
||||||
|
return not has_error
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -66,34 +66,37 @@ def delete_job(job_id : str) -> bool:
|
|||||||
return delete_job_file(job_id)
|
return delete_job_file(job_id)
|
||||||
|
|
||||||
|
|
||||||
def delete_jobs() -> bool:
|
def delete_jobs(halt_on_error : bool) -> bool:
|
||||||
job_ids = find_job_ids('drafted') + find_job_ids('queued') + find_job_ids('failed') + find_job_ids('completed')
|
job_ids = find_job_ids('drafted') + find_job_ids('queued') + find_job_ids('failed') + find_job_ids('completed')
|
||||||
|
has_error = False
|
||||||
|
|
||||||
if job_ids:
|
if job_ids:
|
||||||
for job_id in job_ids:
|
for job_id in job_ids:
|
||||||
if not delete_job(job_id):
|
if not delete_job(job_id):
|
||||||
return False
|
has_error = True
|
||||||
return True
|
if halt_on_error:
|
||||||
|
return False
|
||||||
|
return not has_error
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def find_jobs(job_status : JobStatus) -> JobSet:
|
def find_jobs(job_status : JobStatus) -> JobSet:
|
||||||
job_ids = find_job_ids(job_status)
|
job_ids = find_job_ids(job_status)
|
||||||
jobs : JobSet = {}
|
job_set : JobSet = {}
|
||||||
|
|
||||||
for job_id in job_ids:
|
for job_id in job_ids:
|
||||||
jobs[job_id] = read_job_file(job_id)
|
job_set[job_id] = read_job_file(job_id)
|
||||||
return jobs
|
return job_set
|
||||||
|
|
||||||
|
|
||||||
def find_job_ids(job_status : JobStatus) -> List[str]:
|
def find_job_ids(job_status : JobStatus) -> List[str]:
|
||||||
job_pattern = os.path.join(JOBS_PATH, job_status, '*.json')
|
job_pattern = os.path.join(JOBS_PATH, job_status, '*.json')
|
||||||
job_files = glob.glob(job_pattern)
|
job_paths = resolve_file_pattern(job_pattern)
|
||||||
job_files.sort(key = os.path.getmtime)
|
job_paths.sort(key = os.path.getmtime)
|
||||||
job_ids = []
|
job_ids = []
|
||||||
|
|
||||||
for job_file in job_files:
|
for job_path in job_paths:
|
||||||
job_id, _ = os.path.splitext(os.path.basename(job_file))
|
job_id = get_file_name(job_path)
|
||||||
job_ids.append(job_id)
|
job_ids.append(job_id)
|
||||||
return job_ids
|
return job_ids
|
||||||
|
|
||||||
@@ -185,7 +188,6 @@ def set_step_status(job_id : str, step_index : int, step_status : JobStepStatus)
|
|||||||
|
|
||||||
if job:
|
if job:
|
||||||
steps = job.get('steps')
|
steps = job.get('steps')
|
||||||
|
|
||||||
if has_step(job_id, step_index):
|
if has_step(job_id, step_index):
|
||||||
steps[step_index]['status'] = step_status
|
steps[step_index]['status'] = step_status
|
||||||
return update_job_file(job_id, job)
|
return update_job_file(job_id, job)
|
||||||
@@ -248,9 +250,9 @@ def find_job_path(job_id : str) -> Optional[str]:
|
|||||||
job_file_name = get_job_file_name(job_id)
|
job_file_name = get_job_file_name(job_id)
|
||||||
|
|
||||||
if job_file_name:
|
if job_file_name:
|
||||||
for job_status in job_statuses:
|
for job_status in facefusion.choices.job_statuses:
|
||||||
job_pattern = os.path.join(JOBS_PATH, job_status, job_file_name)
|
job_pattern = os.path.join(JOBS_PATH, job_status, job_file_name)
|
||||||
job_paths = glob.glob(job_pattern)
|
job_paths = resolve_file_pattern(job_pattern)
|
||||||
|
|
||||||
for job_path in job_paths:
|
for job_path in job_paths:
|
||||||
return job_path
|
return job_path
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from facefusion.ffmpeg import concat_video
|
from facefusion.ffmpeg import concat_video
|
||||||
from facefusion.filesystem import is_image, is_video, move_file, remove_file
|
from facefusion.filesystem import are_images, are_videos, move_file, remove_file
|
||||||
from facefusion.jobs import job_helper, job_manager
|
from facefusion.jobs import job_helper, job_manager
|
||||||
from facefusion.typing import JobOutputSet, JobStep, ProcessStep
|
from facefusion.types import JobOutputSet, JobStep, ProcessStep
|
||||||
|
|
||||||
|
|
||||||
def run_job(job_id : str, process_step : ProcessStep) -> bool:
|
def run_job(job_id : str, process_step : ProcessStep) -> bool:
|
||||||
@@ -16,14 +16,17 @@ def run_job(job_id : str, process_step : ProcessStep) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def run_jobs(process_step : ProcessStep) -> bool:
|
def run_jobs(process_step : ProcessStep, halt_on_error : bool) -> bool:
|
||||||
queued_job_ids = job_manager.find_job_ids('queued')
|
queued_job_ids = job_manager.find_job_ids('queued')
|
||||||
|
has_error = False
|
||||||
|
|
||||||
if queued_job_ids:
|
if queued_job_ids:
|
||||||
for job_id in queued_job_ids:
|
for job_id in queued_job_ids:
|
||||||
if not run_job(job_id, process_step):
|
if not run_job(job_id, process_step):
|
||||||
return False
|
has_error = True
|
||||||
return True
|
if halt_on_error:
|
||||||
|
return False
|
||||||
|
return not has_error
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -35,14 +38,17 @@ def retry_job(job_id : str, process_step : ProcessStep) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def retry_jobs(process_step : ProcessStep) -> bool:
|
def retry_jobs(process_step : ProcessStep, halt_on_error : bool) -> bool:
|
||||||
failed_job_ids = job_manager.find_job_ids('failed')
|
failed_job_ids = job_manager.find_job_ids('failed')
|
||||||
|
has_error = False
|
||||||
|
|
||||||
if failed_job_ids:
|
if failed_job_ids:
|
||||||
for job_id in failed_job_ids:
|
for job_id in failed_job_ids:
|
||||||
if not retry_job(job_id, process_step):
|
if not retry_job(job_id, process_step):
|
||||||
return False
|
has_error = True
|
||||||
return True
|
if halt_on_error:
|
||||||
|
return False
|
||||||
|
return not has_error
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -73,10 +79,10 @@ def finalize_steps(job_id : str) -> bool:
|
|||||||
output_set = collect_output_set(job_id)
|
output_set = collect_output_set(job_id)
|
||||||
|
|
||||||
for output_path, temp_output_paths in output_set.items():
|
for output_path, temp_output_paths in output_set.items():
|
||||||
if all(map(is_video, temp_output_paths)):
|
if are_videos(temp_output_paths):
|
||||||
if not concat_video(output_path, temp_output_paths):
|
if not concat_video(output_path, temp_output_paths):
|
||||||
return False
|
return False
|
||||||
if any(map(is_image, temp_output_paths)):
|
if are_images(temp_output_paths):
|
||||||
for temp_output_path in temp_output_paths:
|
for temp_output_path in temp_output_paths:
|
||||||
if not move_file(temp_output_path, output_path):
|
if not move_file(temp_output_path, output_path):
|
||||||
return False
|
return False
|
||||||
@@ -95,12 +101,12 @@ def clean_steps(job_id: str) -> bool:
|
|||||||
|
|
||||||
def collect_output_set(job_id : str) -> JobOutputSet:
|
def collect_output_set(job_id : str) -> JobOutputSet:
|
||||||
steps = job_manager.get_steps(job_id)
|
steps = job_manager.get_steps(job_id)
|
||||||
output_set : JobOutputSet = {}
|
job_output_set : JobOutputSet = {}
|
||||||
|
|
||||||
for index, step in enumerate(steps):
|
for index, step in enumerate(steps):
|
||||||
output_path = step.get('args').get('output_path')
|
output_path = step.get('args').get('output_path')
|
||||||
|
|
||||||
if output_path:
|
if output_path:
|
||||||
step_output_path = job_manager.get_step_output_path(job_id, index, output_path)
|
step_output_path = job_manager.get_step_output_path(job_id, index, output_path)
|
||||||
output_set.setdefault(output_path, []).append(step_output_path)
|
job_output_set.setdefault(output_path, []).append(step_output_path)
|
||||||
return output_set
|
return job_output_set
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from facefusion.typing import JobStore
|
from facefusion.types import JobStore
|
||||||
|
|
||||||
JOB_STORE : JobStore =\
|
JOB_STORE : JobStore =\
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -3,13 +3,13 @@ from json import JSONDecodeError
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from facefusion.filesystem import is_file
|
from facefusion.filesystem import is_file
|
||||||
from facefusion.typing import Content
|
from facefusion.types import Content
|
||||||
|
|
||||||
|
|
||||||
def read_json(json_path : str) -> Optional[Content]:
|
def read_json(json_path : str) -> Optional[Content]:
|
||||||
if is_file(json_path):
|
if is_file(json_path):
|
||||||
try:
|
try:
|
||||||
with open(json_path, 'r') as json_file:
|
with open(json_path) as json_file:
|
||||||
return json.load(json_file)
|
return json.load(json_file)
|
||||||
except JSONDecodeError:
|
except JSONDecodeError:
|
||||||
pass
|
pass
|
||||||
|
|||||||
+8
-40
@@ -1,14 +1,13 @@
|
|||||||
from logging import Logger, basicConfig, getLogger
|
from logging import Logger, basicConfig, getLogger
|
||||||
from typing import Tuple
|
|
||||||
|
|
||||||
from facefusion.choices import log_level_set
|
import facefusion.choices
|
||||||
from facefusion.common_helper import get_first, get_last
|
from facefusion.common_helper import get_first, get_last
|
||||||
from facefusion.typing import LogLevel, TableContents, TableHeaders
|
from facefusion.types import LogLevel
|
||||||
|
|
||||||
|
|
||||||
def init(log_level : LogLevel) -> None:
|
def init(log_level : LogLevel) -> None:
|
||||||
basicConfig(format = '%(message)s')
|
basicConfig(format = '%(message)s')
|
||||||
get_package_logger().setLevel(log_level_set.get(log_level))
|
get_package_logger().setLevel(facefusion.choices.log_level_set.get(log_level))
|
||||||
|
|
||||||
|
|
||||||
def get_package_logger() -> Logger:
|
def get_package_logger() -> Logger:
|
||||||
@@ -32,46 +31,15 @@ def error(message : str, module_name : str) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def create_message(message : str, module_name : str) -> str:
|
def create_message(message : str, module_name : str) -> str:
|
||||||
scopes = module_name.split('.')
|
module_names = module_name.split('.')
|
||||||
first_scope = get_first(scopes)
|
first_module_name = get_first(module_names)
|
||||||
last_scope = get_last(scopes)
|
last_module_name = get_last(module_names)
|
||||||
|
|
||||||
if first_scope and last_scope:
|
if first_module_name and last_module_name:
|
||||||
return '[' + first_scope.upper() + '.' + last_scope.upper() + '] ' + message
|
return '[' + first_module_name.upper() + '.' + last_module_name.upper() + '] ' + message
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
def table(headers : TableHeaders, contents : TableContents) -> None:
|
|
||||||
package_logger = get_package_logger()
|
|
||||||
table_column, table_separator = create_table_parts(headers, contents)
|
|
||||||
|
|
||||||
package_logger.info(table_separator)
|
|
||||||
package_logger.info(table_column.format(*headers))
|
|
||||||
package_logger.info(table_separator)
|
|
||||||
|
|
||||||
for content in contents:
|
|
||||||
content = [ value if value else '' for value in content ]
|
|
||||||
package_logger.info(table_column.format(*content))
|
|
||||||
|
|
||||||
package_logger.info(table_separator)
|
|
||||||
|
|
||||||
|
|
||||||
def create_table_parts(headers : TableHeaders, contents : TableContents) -> Tuple[str, str]:
|
|
||||||
column_parts = []
|
|
||||||
separator_parts = []
|
|
||||||
widths = [ len(header) for header in headers ]
|
|
||||||
|
|
||||||
for content in contents:
|
|
||||||
for index, value in enumerate(content):
|
|
||||||
widths[index] = max(widths[index], len(str(value)))
|
|
||||||
|
|
||||||
for width in widths:
|
|
||||||
column_parts.append('{:<' + str(width) + '}')
|
|
||||||
separator_parts.append('-' * width)
|
|
||||||
|
|
||||||
return '| ' + ' | '.join(column_parts) + ' |', '+-' + '-+-'.join(separator_parts) + '-+'
|
|
||||||
|
|
||||||
|
|
||||||
def enable() -> None:
|
def enable() -> None:
|
||||||
get_package_logger().disabled = False
|
get_package_logger().disabled = False
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ METADATA =\
|
|||||||
{
|
{
|
||||||
'name': 'FaceFusion',
|
'name': 'FaceFusion',
|
||||||
'description': 'Industry leading face manipulation platform',
|
'description': 'Industry leading face manipulation platform',
|
||||||
'version': '3.0.1',
|
'version': '3.2.0',
|
||||||
'license': 'MIT',
|
'license': 'OpenRAIL-AS',
|
||||||
'author': 'Henry Ruhs',
|
'author': 'Henry Ruhs',
|
||||||
'url': 'https://facefusion.io'
|
'url': 'https://facefusion.io'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
|
import onnx
|
||||||
|
|
||||||
|
from facefusion.types import ModelInitializer
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize = None)
|
||||||
|
def get_static_model_initializer(model_path : str) -> ModelInitializer:
|
||||||
|
model = onnx.load(model_path)
|
||||||
|
return onnx.numpy_helper.to_array(model.graph.initializer[-1])
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from facefusion.typing import Fps, Padding
|
from facefusion.types import Fps, Padding
|
||||||
|
|
||||||
|
|
||||||
def normalize_padding(padding : Optional[List[int]]) -> Optional[Padding]:
|
def normalize_padding(padding : Optional[List[int]]) -> Optional[Padding]:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from typing import Generator, List
|
from typing import Generator, List
|
||||||
|
|
||||||
from facefusion.typing import ProcessState, QueuePayload
|
from facefusion.types import ProcessState, QueuePayload
|
||||||
|
|
||||||
PROCESS_STATE : ProcessState = 'pending'
|
PROCESS_STATE : ProcessState = 'pending'
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,171 @@
|
|||||||
from typing import List, Sequence
|
from typing import List, Sequence
|
||||||
|
|
||||||
from facefusion.common_helper import create_float_range, create_int_range
|
from facefusion.common_helper import create_float_range, create_int_range
|
||||||
from facefusion.processors.typing import AgeModifierModel, ExpressionRestorerModel, FaceDebuggerItem, FaceEditorModel, FaceEnhancerModel, FaceSwapperSet, FrameColorizerModel, FrameEnhancerModel, LipSyncerModel
|
from facefusion.filesystem import get_file_name, resolve_file_paths, resolve_relative_path
|
||||||
|
from facefusion.processors.types import AgeModifierModel, DeepSwapperModel, ExpressionRestorerModel, FaceDebuggerItem, FaceEditorModel, FaceEnhancerModel, FaceSwapperModel, FaceSwapperSet, FrameColorizerModel, FrameEnhancerModel, LipSyncerModel
|
||||||
|
|
||||||
age_modifier_models : List[AgeModifierModel] = [ 'styleganex_age' ]
|
age_modifier_models : List[AgeModifierModel] = [ 'styleganex_age' ]
|
||||||
|
deep_swapper_models : List[DeepSwapperModel] =\
|
||||||
|
[
|
||||||
|
'druuzil/adrianne_palicki_384',
|
||||||
|
'druuzil/agnetha_falskog_224',
|
||||||
|
'druuzil/alan_ritchson_320',
|
||||||
|
'druuzil/alicia_vikander_320',
|
||||||
|
'druuzil/amber_midthunder_320',
|
||||||
|
'druuzil/andras_arato_384',
|
||||||
|
'druuzil/andrew_tate_320',
|
||||||
|
'druuzil/anne_hathaway_320',
|
||||||
|
'druuzil/anya_chalotra_320',
|
||||||
|
'druuzil/arnold_schwarzenegger_320',
|
||||||
|
'druuzil/benjamin_affleck_320',
|
||||||
|
'druuzil/benjamin_stiller_384',
|
||||||
|
'druuzil/bradley_pitt_224',
|
||||||
|
'druuzil/brie_larson_384',
|
||||||
|
'druuzil/bryan_cranston_320',
|
||||||
|
'druuzil/catherine_blanchett_352',
|
||||||
|
'druuzil/christian_bale_320',
|
||||||
|
'druuzil/christopher_hemsworth_320',
|
||||||
|
'druuzil/christoph_waltz_384',
|
||||||
|
'druuzil/cillian_murphy_320',
|
||||||
|
'druuzil/cobie_smulders_256',
|
||||||
|
'druuzil/dwayne_johnson_384',
|
||||||
|
'druuzil/edward_norton_320',
|
||||||
|
'druuzil/elisabeth_shue_320',
|
||||||
|
'druuzil/elizabeth_olsen_384',
|
||||||
|
'druuzil/elon_musk_320',
|
||||||
|
'druuzil/emily_blunt_320',
|
||||||
|
'druuzil/emma_stone_384',
|
||||||
|
'druuzil/emma_watson_320',
|
||||||
|
'druuzil/erin_moriarty_384',
|
||||||
|
'druuzil/eva_green_320',
|
||||||
|
'druuzil/ewan_mcgregor_320',
|
||||||
|
'druuzil/florence_pugh_320',
|
||||||
|
'druuzil/freya_allan_320',
|
||||||
|
'druuzil/gary_cole_224',
|
||||||
|
'druuzil/gigi_hadid_224',
|
||||||
|
'druuzil/harrison_ford_384',
|
||||||
|
'druuzil/hayden_christensen_320',
|
||||||
|
'druuzil/heath_ledger_320',
|
||||||
|
'druuzil/henry_cavill_448',
|
||||||
|
'druuzil/hugh_jackman_384',
|
||||||
|
'druuzil/idris_elba_320',
|
||||||
|
'druuzil/jack_nicholson_320',
|
||||||
|
'druuzil/james_mcavoy_320',
|
||||||
|
'druuzil/james_varney_320',
|
||||||
|
'druuzil/jason_momoa_320',
|
||||||
|
'druuzil/jason_statham_320',
|
||||||
|
'druuzil/jennifer_connelly_384',
|
||||||
|
'druuzil/jimmy_donaldson_320',
|
||||||
|
'druuzil/jordan_peterson_384',
|
||||||
|
'druuzil/karl_urban_224',
|
||||||
|
'druuzil/kate_beckinsale_384',
|
||||||
|
'druuzil/laurence_fishburne_384',
|
||||||
|
'druuzil/lili_reinhart_320',
|
||||||
|
'druuzil/mads_mikkelsen_384',
|
||||||
|
'druuzil/mary_winstead_320',
|
||||||
|
'druuzil/margaret_qualley_384',
|
||||||
|
'druuzil/melina_juergens_320',
|
||||||
|
'druuzil/michael_fassbender_320',
|
||||||
|
'druuzil/michael_fox_320',
|
||||||
|
'druuzil/millie_bobby_brown_320',
|
||||||
|
'druuzil/morgan_freeman_320',
|
||||||
|
'druuzil/patrick_stewart_320',
|
||||||
|
'druuzil/rebecca_ferguson_320',
|
||||||
|
'druuzil/scarlett_johansson_320',
|
||||||
|
'druuzil/seth_macfarlane_384',
|
||||||
|
'druuzil/thomas_cruise_320',
|
||||||
|
'druuzil/thomas_hanks_384',
|
||||||
|
'druuzil/william_murray_384',
|
||||||
|
'edel/emma_roberts_224',
|
||||||
|
'edel/ivanka_trump_224',
|
||||||
|
'edel/lize_dzjabrailova_224',
|
||||||
|
'edel/sidney_sweeney_224',
|
||||||
|
'edel/winona_ryder_224',
|
||||||
|
'iperov/alexandra_daddario_224',
|
||||||
|
'iperov/alexei_navalny_224',
|
||||||
|
'iperov/amber_heard_224',
|
||||||
|
'iperov/dilraba_dilmurat_224',
|
||||||
|
'iperov/elon_musk_224',
|
||||||
|
'iperov/emilia_clarke_224',
|
||||||
|
'iperov/emma_watson_224',
|
||||||
|
'iperov/erin_moriarty_224',
|
||||||
|
'iperov/jackie_chan_224',
|
||||||
|
'iperov/james_carrey_224',
|
||||||
|
'iperov/jason_statham_320',
|
||||||
|
'iperov/keanu_reeves_320',
|
||||||
|
'iperov/margot_robbie_224',
|
||||||
|
'iperov/natalie_dormer_224',
|
||||||
|
'iperov/nicolas_coppola_224',
|
||||||
|
'iperov/robert_downey_224',
|
||||||
|
'iperov/rowan_atkinson_224',
|
||||||
|
'iperov/ryan_reynolds_224',
|
||||||
|
'iperov/scarlett_johansson_224',
|
||||||
|
'iperov/sylvester_stallone_224',
|
||||||
|
'iperov/thomas_cruise_224',
|
||||||
|
'iperov/thomas_holland_224',
|
||||||
|
'iperov/vin_diesel_224',
|
||||||
|
'iperov/vladimir_putin_224',
|
||||||
|
'jen/angelica_trae_288',
|
||||||
|
'jen/ella_freya_224',
|
||||||
|
'jen/emma_myers_320',
|
||||||
|
'jen/evie_pickerill_224',
|
||||||
|
'jen/kang_hyewon_320',
|
||||||
|
'jen/maddie_mead_224',
|
||||||
|
'jen/nicole_turnbull_288',
|
||||||
|
'mats/alica_schmidt_320',
|
||||||
|
'mats/ashley_alexiss_224',
|
||||||
|
'mats/billie_eilish_224',
|
||||||
|
'mats/brie_larson_224',
|
||||||
|
'mats/cara_delevingne_224',
|
||||||
|
'mats/carolin_kebekus_224',
|
||||||
|
'mats/chelsea_clinton_224',
|
||||||
|
'mats/claire_boucher_224',
|
||||||
|
'mats/corinna_kopf_224',
|
||||||
|
'mats/florence_pugh_224',
|
||||||
|
'mats/hillary_clinton_224',
|
||||||
|
'mats/jenna_fischer_224',
|
||||||
|
'mats/kim_jisoo_320',
|
||||||
|
'mats/mica_suarez_320',
|
||||||
|
'mats/shailene_woodley_224',
|
||||||
|
'mats/shraddha_kapoor_320',
|
||||||
|
'mats/yu_jimin_352',
|
||||||
|
'rumateus/alison_brie_224',
|
||||||
|
'rumateus/amber_heard_224',
|
||||||
|
'rumateus/angelina_jolie_224',
|
||||||
|
'rumateus/aubrey_plaza_224',
|
||||||
|
'rumateus/bridget_regan_224',
|
||||||
|
'rumateus/cobie_smulders_224',
|
||||||
|
'rumateus/deborah_woll_224',
|
||||||
|
'rumateus/dua_lipa_224',
|
||||||
|
'rumateus/emma_stone_224',
|
||||||
|
'rumateus/hailee_steinfeld_224',
|
||||||
|
'rumateus/hilary_duff_224',
|
||||||
|
'rumateus/jessica_alba_224',
|
||||||
|
'rumateus/jessica_biel_224',
|
||||||
|
'rumateus/john_cena_224',
|
||||||
|
'rumateus/kim_kardashian_224',
|
||||||
|
'rumateus/kristen_bell_224',
|
||||||
|
'rumateus/lucy_liu_224',
|
||||||
|
'rumateus/margot_robbie_224',
|
||||||
|
'rumateus/megan_fox_224',
|
||||||
|
'rumateus/meghan_markle_224',
|
||||||
|
'rumateus/millie_bobby_brown_224',
|
||||||
|
'rumateus/natalie_portman_224',
|
||||||
|
'rumateus/nicki_minaj_224',
|
||||||
|
'rumateus/olivia_wilde_224',
|
||||||
|
'rumateus/shay_mitchell_224',
|
||||||
|
'rumateus/sophie_turner_224',
|
||||||
|
'rumateus/taylor_swift_224'
|
||||||
|
]
|
||||||
|
|
||||||
|
custom_model_file_paths = resolve_file_paths(resolve_relative_path('../.assets/models/custom'))
|
||||||
|
|
||||||
|
if custom_model_file_paths:
|
||||||
|
|
||||||
|
for model_file_path in custom_model_file_paths:
|
||||||
|
model_id = '/'.join([ 'custom', get_file_name(model_file_path) ])
|
||||||
|
deep_swapper_models.append(model_id)
|
||||||
|
|
||||||
expression_restorer_models : List[ExpressionRestorerModel] = [ 'live_portrait' ]
|
expression_restorer_models : List[ExpressionRestorerModel] = [ 'live_portrait' ]
|
||||||
face_debugger_items : List[FaceDebuggerItem] = [ 'bounding-box', 'face-landmark-5', 'face-landmark-5/68', 'face-landmark-68', 'face-landmark-68/5', 'face-mask', 'face-detector-score', 'face-landmarker-score', 'age', 'gender', 'race' ]
|
face_debugger_items : List[FaceDebuggerItem] = [ 'bounding-box', 'face-landmark-5', 'face-landmark-5/68', 'face-landmark-68', 'face-landmark-68/5', 'face-mask', 'face-detector-score', 'face-landmarker-score', 'age', 'gender', 'race' ]
|
||||||
face_editor_models : List[FaceEditorModel] = [ 'live_portrait' ]
|
face_editor_models : List[FaceEditorModel] = [ 'live_portrait' ]
|
||||||
@@ -14,18 +176,21 @@ face_swapper_set : FaceSwapperSet =\
|
|||||||
'ghost_1_256': [ '256x256', '512x512', '768x768', '1024x1024' ],
|
'ghost_1_256': [ '256x256', '512x512', '768x768', '1024x1024' ],
|
||||||
'ghost_2_256': [ '256x256', '512x512', '768x768', '1024x1024' ],
|
'ghost_2_256': [ '256x256', '512x512', '768x768', '1024x1024' ],
|
||||||
'ghost_3_256': [ '256x256', '512x512', '768x768', '1024x1024' ],
|
'ghost_3_256': [ '256x256', '512x512', '768x768', '1024x1024' ],
|
||||||
|
'hififace_unofficial_256': [ '256x256', '512x512', '768x768', '1024x1024' ],
|
||||||
'inswapper_128': [ '128x128', '256x256', '384x384', '512x512', '768x768', '1024x1024' ],
|
'inswapper_128': [ '128x128', '256x256', '384x384', '512x512', '768x768', '1024x1024' ],
|
||||||
'inswapper_128_fp16': [ '128x128', '256x256', '384x384', '512x512', '768x768', '1024x1024' ],
|
'inswapper_128_fp16': [ '128x128', '256x256', '384x384', '512x512', '768x768', '1024x1024' ],
|
||||||
'simswap_256': [ '256x256', '512x512', '768x768', '1024x1024' ],
|
'simswap_256': [ '256x256', '512x512', '768x768', '1024x1024' ],
|
||||||
'simswap_unofficial_512': [ '512x512', '768x768', '1024x1024' ],
|
'simswap_unofficial_512': [ '512x512', '768x768', '1024x1024' ],
|
||||||
'uniface_256': [ '256x256', '512x512', '768x768', '1024x1024' ]
|
'uniface_256': [ '256x256', '512x512', '768x768', '1024x1024' ]
|
||||||
}
|
}
|
||||||
|
face_swapper_models : List[FaceSwapperModel] = list(face_swapper_set.keys())
|
||||||
frame_colorizer_models : List[FrameColorizerModel] = [ 'ddcolor', 'ddcolor_artistic', 'deoldify', 'deoldify_artistic', 'deoldify_stable' ]
|
frame_colorizer_models : List[FrameColorizerModel] = [ 'ddcolor', 'ddcolor_artistic', 'deoldify', 'deoldify_artistic', 'deoldify_stable' ]
|
||||||
frame_colorizer_sizes : List[str] = [ '192x192', '256x256', '384x384', '512x512' ]
|
frame_colorizer_sizes : List[str] = [ '192x192', '256x256', '384x384', '512x512' ]
|
||||||
frame_enhancer_models : List[FrameEnhancerModel] = [ 'clear_reality_x4', 'lsdir_x4', 'nomos8k_sc_x4', 'real_esrgan_x2', 'real_esrgan_x2_fp16', 'real_esrgan_x4', 'real_esrgan_x4_fp16', 'real_esrgan_x8', 'real_esrgan_x8_fp16', 'real_hatgan_x4', 'span_kendata_x4', 'ultra_sharp_x4' ]
|
frame_enhancer_models : List[FrameEnhancerModel] = [ 'clear_reality_x4', 'lsdir_x4', 'nomos8k_sc_x4', 'real_esrgan_x2', 'real_esrgan_x2_fp16', 'real_esrgan_x4', 'real_esrgan_x4_fp16', 'real_esrgan_x8', 'real_esrgan_x8_fp16', 'real_hatgan_x4', 'real_web_photo_x4', 'realistic_rescaler_x4', 'remacri_x4', 'siax_x4', 'span_kendata_x4', 'swin2_sr_x4', 'ultra_sharp_x4' ]
|
||||||
lip_syncer_models : List[LipSyncerModel] = [ 'wav2lip_96', 'wav2lip_gan_96' ]
|
lip_syncer_models : List[LipSyncerModel] = [ 'wav2lip_96', 'wav2lip_gan_96' ]
|
||||||
|
|
||||||
age_modifier_direction_range : Sequence[int] = create_int_range(-100, 100, 1)
|
age_modifier_direction_range : Sequence[int] = create_int_range(-100, 100, 1)
|
||||||
|
deep_swapper_morph_range : Sequence[int] = create_int_range(0, 100, 1)
|
||||||
expression_restorer_factor_range : Sequence[int] = create_int_range(0, 100, 1)
|
expression_restorer_factor_range : Sequence[int] = create_int_range(0, 100, 1)
|
||||||
face_editor_eyebrow_direction_range : Sequence[float] = create_float_range(-1.0, 1.0, 0.05)
|
face_editor_eyebrow_direction_range : Sequence[float] = create_float_range(-1.0, 1.0, 0.05)
|
||||||
face_editor_eye_gaze_horizontal_range : Sequence[float] = create_float_range(-1.0, 1.0, 0.05)
|
face_editor_eye_gaze_horizontal_range : Sequence[float] = create_float_range(-1.0, 1.0, 0.05)
|
||||||
@@ -42,5 +207,6 @@ face_editor_head_pitch_range : Sequence[float] = create_float_range(-1.0, 1.0, 0
|
|||||||
face_editor_head_yaw_range : Sequence[float] = create_float_range(-1.0, 1.0, 0.05)
|
face_editor_head_yaw_range : Sequence[float] = create_float_range(-1.0, 1.0, 0.05)
|
||||||
face_editor_head_roll_range : Sequence[float] = create_float_range(-1.0, 1.0, 0.05)
|
face_editor_head_roll_range : Sequence[float] = create_float_range(-1.0, 1.0, 0.05)
|
||||||
face_enhancer_blend_range : Sequence[int] = create_int_range(0, 100, 1)
|
face_enhancer_blend_range : Sequence[int] = create_int_range(0, 100, 1)
|
||||||
|
face_enhancer_weight_range : Sequence[float] = create_float_range(0.0, 1.0, 0.05)
|
||||||
frame_colorizer_blend_range : Sequence[int] = create_int_range(0, 100, 1)
|
frame_colorizer_blend_range : Sequence[int] = create_int_range(0, 100, 1)
|
||||||
frame_enhancer_blend_range : Sequence[int] = create_int_range(0, 100, 1)
|
frame_enhancer_blend_range : Sequence[int] = create_int_range(0, 100, 1)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from tqdm import tqdm
|
|||||||
|
|
||||||
from facefusion import logger, state_manager, wording
|
from facefusion import logger, state_manager, wording
|
||||||
from facefusion.exit_helper import hard_exit
|
from facefusion.exit_helper import hard_exit
|
||||||
from facefusion.typing import ProcessFrames, QueuePayload
|
from facefusion.types import ProcessFrames, QueuePayload
|
||||||
|
|
||||||
PROCESSORS_METHODS =\
|
PROCESSORS_METHODS =\
|
||||||
[
|
[
|
||||||
@@ -53,21 +53,10 @@ def get_processors_modules(processors : List[str]) -> List[ModuleType]:
|
|||||||
return processor_modules
|
return processor_modules
|
||||||
|
|
||||||
|
|
||||||
def clear_processors_modules(processors : List[str]) -> None:
|
|
||||||
for processor in processors:
|
|
||||||
processor_module = load_processor_module(processor)
|
|
||||||
processor_module.clear_inference_pool()
|
|
||||||
|
|
||||||
|
|
||||||
def multi_process_frames(source_paths : List[str], temp_frame_paths : List[str], process_frames : ProcessFrames) -> None:
|
def multi_process_frames(source_paths : List[str], temp_frame_paths : List[str], process_frames : ProcessFrames) -> None:
|
||||||
queue_payloads = create_queue_payloads(temp_frame_paths)
|
queue_payloads = create_queue_payloads(temp_frame_paths)
|
||||||
with tqdm(total = len(queue_payloads), desc = wording.get('processing'), unit = 'frame', ascii = ' =', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress:
|
with tqdm(total = len(queue_payloads), desc = wording.get('processing'), unit = 'frame', ascii = ' =', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress:
|
||||||
progress.set_postfix(
|
progress.set_postfix(execution_providers = state_manager.get_item('execution_providers'))
|
||||||
{
|
|
||||||
'execution_providers': state_manager.get_item('execution_providers'),
|
|
||||||
'execution_thread_count': state_manager.get_item('execution_thread_count'),
|
|
||||||
'execution_queue_count': state_manager.get_item('execution_queue_count')
|
|
||||||
})
|
|
||||||
with ThreadPoolExecutor(max_workers = state_manager.get_item('execution_thread_count')) as executor:
|
with ThreadPoolExecutor(max_workers = state_manager.get_item('execution_thread_count')) as executor:
|
||||||
futures = []
|
futures = []
|
||||||
queue : Queue[QueuePayload] = create_queue(queue_payloads)
|
queue : Queue[QueuePayload] = create_queue(queue_payloads)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from typing import Tuple
|
|||||||
import numpy
|
import numpy
|
||||||
import scipy
|
import scipy
|
||||||
|
|
||||||
from facefusion.processors.typing import LivePortraitExpression, LivePortraitPitch, LivePortraitRoll, LivePortraitRotation, LivePortraitYaw
|
from facefusion.processors.types import LivePortraitExpression, LivePortraitPitch, LivePortraitRoll, LivePortraitRotation, LivePortraitYaw
|
||||||
|
|
||||||
EXPRESSION_MIN = numpy.array(
|
EXPRESSION_MIN = numpy.array(
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from typing import Any, List
|
from functools import lru_cache
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy
|
import numpy
|
||||||
from cv2.typing import Size
|
|
||||||
from numpy.typing import NDArray
|
|
||||||
|
|
||||||
|
import facefusion.choices
|
||||||
import facefusion.jobs.job_manager
|
import facefusion.jobs.job_manager
|
||||||
import facefusion.jobs.job_store
|
import facefusion.jobs.job_store
|
||||||
import facefusion.processors.core as processors
|
import facefusion.processors.core as processors
|
||||||
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, wording
|
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, wording
|
||||||
from facefusion.common_helper import create_int_metavar
|
from facefusion.common_helper import create_int_metavar
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
|
from facefusion.execution import has_execution_provider
|
||||||
from facefusion.face_analyser import get_many_faces, get_one_face
|
from facefusion.face_analyser import get_many_faces, get_one_face
|
||||||
from facefusion.face_helper import merge_matrix, paste_back, scale_face_landmark_5, warp_face_by_face_landmark_5
|
from facefusion.face_helper import merge_matrix, paste_back, scale_face_landmark_5, warp_face_by_face_landmark_5
|
||||||
from facefusion.face_masker import create_occlusion_mask, create_static_box_mask
|
from facefusion.face_masker import create_occlusion_mask, create_static_box_mask
|
||||||
@@ -19,59 +20,71 @@ from facefusion.face_selector import find_similar_faces, sort_and_filter_faces
|
|||||||
from facefusion.face_store import get_reference_faces
|
from facefusion.face_store import get_reference_faces
|
||||||
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.typing import AgeModifierInputs
|
from facefusion.processors.types import AgeModifierDirection, AgeModifierInputs
|
||||||
from facefusion.program_helper import find_argument_group
|
from facefusion.program_helper import find_argument_group
|
||||||
from facefusion.thread_helper import thread_semaphore
|
from facefusion.thread_helper import thread_semaphore
|
||||||
from facefusion.typing import ApplyStateItem, Args, Face, InferencePool, Mask, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
from facefusion.types import ApplyStateItem, Args, DownloadScope, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
||||||
from facefusion.vision import read_image, read_static_image, write_image
|
from facefusion.vision import match_frame_color, read_image, read_static_image, write_image
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'styleganex_age':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'styleganex_age':
|
||||||
{
|
{
|
||||||
'age_modifier':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/styleganex_age.hash',
|
'age_modifier':
|
||||||
'path': resolve_relative_path('../.assets/models/styleganex_age.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.1.0', 'styleganex_age.hash'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/styleganex_age.hash')
|
||||||
'sources':
|
}
|
||||||
{
|
},
|
||||||
'age_modifier':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/styleganex_age.onnx',
|
'age_modifier':
|
||||||
'path': resolve_relative_path('../.assets/models/styleganex_age.onnx')
|
{
|
||||||
|
'url': resolve_download_url('models-3.1.0', 'styleganex_age.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/styleganex_age.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'templates':
|
||||||
|
{
|
||||||
|
'target': 'ffhq_512',
|
||||||
|
'target_with_background': 'styleganex_384'
|
||||||
|
},
|
||||||
|
'sizes':
|
||||||
|
{
|
||||||
|
'target': (256, 256),
|
||||||
|
'target_with_background': (384, 384)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
'template': 'ffhq_512',
|
|
||||||
'size': (512, 512)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
model_sources = get_model_options().get('sources')
|
model_names = [ state_manager.get_item('age_modifier_model') ]
|
||||||
model_context = __name__ + '.' + state_manager.get_item('age_modifier_model')
|
model_source_set = get_model_options().get('sources')
|
||||||
return inference_manager.get_inference_pool(model_context, model_sources)
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
model_context = __name__ + '.' + state_manager.get_item('age_modifier_model')
|
model_names = [ state_manager.get_item('age_modifier_model') ]
|
||||||
inference_manager.clear_inference_pool(model_context)
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def get_model_options() -> ModelOptions:
|
def get_model_options() -> ModelOptions:
|
||||||
age_modifier_model = state_manager.get_item('age_modifier_model')
|
model_name = state_manager.get_item('age_modifier_model')
|
||||||
return MODEL_SET.get(age_modifier_model)
|
return create_static_model_set('full').get(model_name)
|
||||||
|
|
||||||
|
|
||||||
def register_args(program : ArgumentParser) -> None:
|
def register_args(program : ArgumentParser) -> None:
|
||||||
group_processors = find_argument_group(program, 'processors')
|
group_processors = find_argument_group(program, 'processors')
|
||||||
if group_processors:
|
if group_processors:
|
||||||
group_processors.add_argument('--age-modifier-model', help = wording.get('help.age_modifier_model'), default = config.get_str_value('processors.age_modifier_model', 'styleganex_age'), choices = processors_choices.age_modifier_models)
|
group_processors.add_argument('--age-modifier-model', help = wording.get('help.age_modifier_model'), default = config.get_str_value('processors', 'age_modifier_model', 'styleganex_age'), choices = processors_choices.age_modifier_models)
|
||||||
group_processors.add_argument('--age-modifier-direction', help = wording.get('help.age_modifier_direction'), type = int, default = config.get_int_value('processors.age_modifier_direction', '0'), choices = processors_choices.age_modifier_direction_range, metavar = create_int_metavar(processors_choices.age_modifier_direction_range))
|
group_processors.add_argument('--age-modifier-direction', help = wording.get('help.age_modifier_direction'), type = int, default = config.get_int_value('processors', 'age_modifier_direction', '0'), choices = processors_choices.age_modifier_direction_range, metavar = create_int_metavar(processors_choices.age_modifier_direction_range))
|
||||||
facefusion.jobs.job_store.register_step_keys([ 'age_modifier_model', 'age_modifier_direction' ])
|
facefusion.jobs.job_store.register_step_keys([ 'age_modifier_model', 'age_modifier_direction' ])
|
||||||
|
|
||||||
|
|
||||||
@@ -81,11 +94,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set = get_model_options().get('hashes')
|
||||||
model_hashes = get_model_options().get('hashes')
|
model_source_set = get_model_options().get('sources')
|
||||||
model_sources = get_model_options().get('sources')
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def pre_process(mode : ProcessMode) -> bool:
|
def pre_process(mode : ProcessMode) -> bool:
|
||||||
@@ -95,7 +107,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
|||||||
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
if mode == 'output' and not same_file_extension([ state_manager.get_item('target_path'), state_manager.get_item('output_path') ]):
|
if mode == 'output' and not same_file_extension(state_manager.get_item('target_path'), state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@@ -115,15 +127,14 @@ def post_process() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def modify_age(target_face : Face, temp_vision_frame : VisionFrame) -> VisionFrame:
|
def modify_age(target_face : Face, temp_vision_frame : VisionFrame) -> VisionFrame:
|
||||||
model_template = get_model_options().get('template')
|
model_templates = get_model_options().get('templates')
|
||||||
model_size = get_model_options().get('size')
|
model_sizes = get_model_options().get('sizes')
|
||||||
crop_size = (model_size[0] // 2, model_size[1] // 2)
|
|
||||||
face_landmark_5 = target_face.landmark_set.get('5/68').copy()
|
face_landmark_5 = target_face.landmark_set.get('5/68').copy()
|
||||||
extend_face_landmark_5 = scale_face_landmark_5(face_landmark_5, 2.0)
|
crop_vision_frame, affine_matrix = warp_face_by_face_landmark_5(temp_vision_frame, face_landmark_5, model_templates.get('target'), model_sizes.get('target'))
|
||||||
crop_vision_frame, affine_matrix = warp_face_by_face_landmark_5(temp_vision_frame, face_landmark_5, model_template, crop_size)
|
extend_face_landmark_5 = scale_face_landmark_5(face_landmark_5, 0.875)
|
||||||
extend_vision_frame, extend_affine_matrix = warp_face_by_face_landmark_5(temp_vision_frame, extend_face_landmark_5, model_template, model_size)
|
extend_vision_frame, extend_affine_matrix = warp_face_by_face_landmark_5(temp_vision_frame, extend_face_landmark_5, model_templates.get('target_with_background'), model_sizes.get('target_with_background'))
|
||||||
extend_vision_frame_raw = extend_vision_frame.copy()
|
extend_vision_frame_raw = extend_vision_frame.copy()
|
||||||
box_mask = create_static_box_mask(model_size, state_manager.get_item('face_mask_blur'), (0, 0, 0, 0))
|
box_mask = create_static_box_mask(model_sizes.get('target_with_background'), state_manager.get_item('face_mask_blur'), (0, 0, 0, 0))
|
||||||
crop_masks =\
|
crop_masks =\
|
||||||
[
|
[
|
||||||
box_mask
|
box_mask
|
||||||
@@ -132,31 +143,36 @@ def modify_age(target_face : Face, temp_vision_frame : VisionFrame) -> VisionFra
|
|||||||
if 'occlusion' in state_manager.get_item('face_mask_types'):
|
if 'occlusion' in state_manager.get_item('face_mask_types'):
|
||||||
occlusion_mask = create_occlusion_mask(crop_vision_frame)
|
occlusion_mask = create_occlusion_mask(crop_vision_frame)
|
||||||
combined_matrix = merge_matrix([ extend_affine_matrix, cv2.invertAffineTransform(affine_matrix) ])
|
combined_matrix = merge_matrix([ extend_affine_matrix, cv2.invertAffineTransform(affine_matrix) ])
|
||||||
occlusion_mask = cv2.warpAffine(occlusion_mask, combined_matrix, model_size)
|
occlusion_mask = cv2.warpAffine(occlusion_mask, combined_matrix, model_sizes.get('target_with_background'))
|
||||||
crop_masks.append(occlusion_mask)
|
crop_masks.append(occlusion_mask)
|
||||||
|
|
||||||
crop_vision_frame = prepare_vision_frame(crop_vision_frame)
|
crop_vision_frame = prepare_vision_frame(crop_vision_frame)
|
||||||
extend_vision_frame = prepare_vision_frame(extend_vision_frame)
|
extend_vision_frame = prepare_vision_frame(extend_vision_frame)
|
||||||
extend_vision_frame = forward(crop_vision_frame, extend_vision_frame)
|
age_modifier_direction = numpy.array(numpy.interp(state_manager.get_item('age_modifier_direction'), [ -100, 100 ], [ 2.5, -2.5 ])).astype(numpy.float32)
|
||||||
|
extend_vision_frame = forward(crop_vision_frame, extend_vision_frame, age_modifier_direction)
|
||||||
extend_vision_frame = normalize_extend_frame(extend_vision_frame)
|
extend_vision_frame = normalize_extend_frame(extend_vision_frame)
|
||||||
extend_vision_frame = fix_color(extend_vision_frame_raw, extend_vision_frame)
|
extend_vision_frame = match_frame_color(extend_vision_frame_raw, extend_vision_frame)
|
||||||
extend_crop_mask = cv2.pyrUp(numpy.minimum.reduce(crop_masks).clip(0, 1))
|
extend_affine_matrix *= (model_sizes.get('target')[0] * 4) / model_sizes.get('target_with_background')[0]
|
||||||
extend_affine_matrix *= extend_vision_frame.shape[0] / 512
|
crop_mask = numpy.minimum.reduce(crop_masks).clip(0, 1)
|
||||||
paste_vision_frame = paste_back(temp_vision_frame, extend_vision_frame, extend_crop_mask, extend_affine_matrix)
|
crop_mask = cv2.resize(crop_mask, (model_sizes.get('target')[0] * 4, model_sizes.get('target')[1] * 4))
|
||||||
|
paste_vision_frame = paste_back(temp_vision_frame, extend_vision_frame, crop_mask, extend_affine_matrix)
|
||||||
return paste_vision_frame
|
return paste_vision_frame
|
||||||
|
|
||||||
|
|
||||||
def forward(crop_vision_frame : VisionFrame, extend_vision_frame : VisionFrame) -> VisionFrame:
|
def forward(crop_vision_frame : VisionFrame, extend_vision_frame : VisionFrame, age_modifier_direction : AgeModifierDirection) -> VisionFrame:
|
||||||
age_modifier = get_inference_pool().get('age_modifier')
|
age_modifier = get_inference_pool().get('age_modifier')
|
||||||
age_modifier_inputs = {}
|
age_modifier_inputs = {}
|
||||||
|
|
||||||
|
if has_execution_provider('coreml'):
|
||||||
|
age_modifier.set_providers([ facefusion.choices.execution_provider_set.get('cpu') ])
|
||||||
|
|
||||||
for age_modifier_input in age_modifier.get_inputs():
|
for age_modifier_input in age_modifier.get_inputs():
|
||||||
if age_modifier_input.name == 'target':
|
if age_modifier_input.name == 'target':
|
||||||
age_modifier_inputs[age_modifier_input.name] = crop_vision_frame
|
age_modifier_inputs[age_modifier_input.name] = crop_vision_frame
|
||||||
if age_modifier_input.name == 'target_with_background':
|
if age_modifier_input.name == 'target_with_background':
|
||||||
age_modifier_inputs[age_modifier_input.name] = extend_vision_frame
|
age_modifier_inputs[age_modifier_input.name] = extend_vision_frame
|
||||||
if age_modifier_input.name == 'direction':
|
if age_modifier_input.name == 'direction':
|
||||||
age_modifier_inputs[age_modifier_input.name] = prepare_direction(state_manager.get_item('age_modifier_direction'))
|
age_modifier_inputs[age_modifier_input.name] = age_modifier_direction
|
||||||
|
|
||||||
with thread_semaphore():
|
with thread_semaphore():
|
||||||
crop_vision_frame = age_modifier.run(None, age_modifier_inputs)[0][0]
|
crop_vision_frame = age_modifier.run(None, age_modifier_inputs)[0][0]
|
||||||
@@ -164,38 +180,6 @@ def forward(crop_vision_frame : VisionFrame, extend_vision_frame : VisionFrame)
|
|||||||
return crop_vision_frame
|
return crop_vision_frame
|
||||||
|
|
||||||
|
|
||||||
def fix_color(extend_vision_frame_raw : VisionFrame, extend_vision_frame : VisionFrame) -> VisionFrame:
|
|
||||||
color_difference = compute_color_difference(extend_vision_frame_raw, extend_vision_frame, (48, 48))
|
|
||||||
color_difference_mask = create_static_box_mask(extend_vision_frame.shape[:2][::-1], 1.0, (0, 0, 0, 0))
|
|
||||||
color_difference_mask = numpy.stack((color_difference_mask, ) * 3, axis = -1)
|
|
||||||
extend_vision_frame = normalize_color_difference(color_difference, color_difference_mask, extend_vision_frame)
|
|
||||||
return extend_vision_frame
|
|
||||||
|
|
||||||
|
|
||||||
def compute_color_difference(extend_vision_frame_raw : VisionFrame, extend_vision_frame : VisionFrame, size : Size) -> VisionFrame:
|
|
||||||
extend_vision_frame_raw = extend_vision_frame_raw.astype(numpy.float32) / 255
|
|
||||||
extend_vision_frame_raw = cv2.resize(extend_vision_frame_raw, size, interpolation = cv2.INTER_AREA)
|
|
||||||
extend_vision_frame = extend_vision_frame.astype(numpy.float32) / 255
|
|
||||||
extend_vision_frame = cv2.resize(extend_vision_frame, size, interpolation = cv2.INTER_AREA)
|
|
||||||
color_difference = extend_vision_frame_raw - extend_vision_frame
|
|
||||||
return color_difference
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_color_difference(color_difference : VisionFrame, color_difference_mask : Mask, extend_vision_frame : VisionFrame) -> VisionFrame:
|
|
||||||
color_difference = cv2.resize(color_difference, extend_vision_frame.shape[:2][::-1], interpolation = cv2.INTER_CUBIC)
|
|
||||||
color_difference_mask = 1 - color_difference_mask.clip(0, 0.75)
|
|
||||||
extend_vision_frame = extend_vision_frame.astype(numpy.float32) / 255
|
|
||||||
extend_vision_frame += color_difference * color_difference_mask
|
|
||||||
extend_vision_frame = extend_vision_frame.clip(0, 1)
|
|
||||||
extend_vision_frame = numpy.multiply(extend_vision_frame, 255).astype(numpy.uint8)
|
|
||||||
return extend_vision_frame
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_direction(direction : int) -> NDArray[Any]:
|
|
||||||
direction = numpy.interp(float(direction), [ -100, 100 ], [ 2.5, -2.5 ]) #type:ignore[assignment]
|
|
||||||
return numpy.array(direction).astype(numpy.float32)
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_vision_frame(vision_frame : VisionFrame) -> VisionFrame:
|
def prepare_vision_frame(vision_frame : VisionFrame) -> VisionFrame:
|
||||||
vision_frame = vision_frame[:, :, ::-1] / 255.0
|
vision_frame = vision_frame[:, :, ::-1] / 255.0
|
||||||
vision_frame = (vision_frame - 0.5) / 0.5
|
vision_frame = (vision_frame - 0.5) / 0.5
|
||||||
@@ -204,12 +188,13 @@ def prepare_vision_frame(vision_frame : VisionFrame) -> VisionFrame:
|
|||||||
|
|
||||||
|
|
||||||
def normalize_extend_frame(extend_vision_frame : VisionFrame) -> VisionFrame:
|
def normalize_extend_frame(extend_vision_frame : VisionFrame) -> VisionFrame:
|
||||||
|
model_sizes = get_model_options().get('sizes')
|
||||||
extend_vision_frame = numpy.clip(extend_vision_frame, -1, 1)
|
extend_vision_frame = numpy.clip(extend_vision_frame, -1, 1)
|
||||||
extend_vision_frame = (extend_vision_frame + 1) / 2
|
extend_vision_frame = (extend_vision_frame + 1) / 2
|
||||||
extend_vision_frame = extend_vision_frame.transpose(1, 2, 0).clip(0, 255)
|
extend_vision_frame = extend_vision_frame.transpose(1, 2, 0).clip(0, 255)
|
||||||
extend_vision_frame = (extend_vision_frame * 255.0)
|
extend_vision_frame = (extend_vision_frame * 255.0)
|
||||||
extend_vision_frame = extend_vision_frame.astype(numpy.uint8)[:, :, ::-1]
|
extend_vision_frame = extend_vision_frame.astype(numpy.uint8)[:, :, ::-1]
|
||||||
extend_vision_frame = cv2.pyrDown(extend_vision_frame)
|
extend_vision_frame = cv2.resize(extend_vision_frame, (model_sizes.get('target')[0] * 4, model_sizes.get('target')[1] * 4), interpolation = cv2.INTER_AREA)
|
||||||
return extend_vision_frame
|
return extend_vision_frame
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+450
@@ -0,0 +1,450 @@
|
|||||||
|
from argparse import ArgumentParser
|
||||||
|
from functools import lru_cache
|
||||||
|
from typing import List, Tuple
|
||||||
|
|
||||||
|
import cv2
|
||||||
|
import numpy
|
||||||
|
from cv2.typing import Size
|
||||||
|
|
||||||
|
import facefusion.jobs.job_manager
|
||||||
|
import facefusion.jobs.job_store
|
||||||
|
import facefusion.processors.core as processors
|
||||||
|
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, wording
|
||||||
|
from facefusion.common_helper import create_int_metavar
|
||||||
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url_by_provider
|
||||||
|
from facefusion.face_analyser import get_many_faces, get_one_face
|
||||||
|
from facefusion.face_helper import paste_back, warp_face_by_face_landmark_5
|
||||||
|
from facefusion.face_masker import create_occlusion_mask, create_region_mask, create_static_box_mask
|
||||||
|
from facefusion.face_selector import find_similar_faces, sort_and_filter_faces
|
||||||
|
from facefusion.face_store import get_reference_faces
|
||||||
|
from facefusion.filesystem import get_file_name, in_directory, is_image, is_video, resolve_file_paths, resolve_relative_path, same_file_extension
|
||||||
|
from facefusion.processors import choices as processors_choices
|
||||||
|
from facefusion.processors.types import DeepSwapperInputs, DeepSwapperMorph
|
||||||
|
from facefusion.program_helper import find_argument_group
|
||||||
|
from facefusion.thread_helper import thread_semaphore
|
||||||
|
from facefusion.types import ApplyStateItem, Args, DownloadScope, Face, InferencePool, Mask, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
||||||
|
from facefusion.vision import conditional_match_frame_color, read_image, read_static_image, write_image
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize = None)
|
||||||
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
model_config = []
|
||||||
|
|
||||||
|
if download_scope == 'full':
|
||||||
|
model_config.extend(
|
||||||
|
[
|
||||||
|
('druuzil', 'adrianne_palicki_384'),
|
||||||
|
('druuzil', 'agnetha_falskog_224'),
|
||||||
|
('druuzil', 'alan_ritchson_320'),
|
||||||
|
('druuzil', 'alicia_vikander_320'),
|
||||||
|
('druuzil', 'amber_midthunder_320'),
|
||||||
|
('druuzil', 'andras_arato_384'),
|
||||||
|
('druuzil', 'andrew_tate_320'),
|
||||||
|
('druuzil', 'anne_hathaway_320'),
|
||||||
|
('druuzil', 'anya_chalotra_320'),
|
||||||
|
('druuzil', 'arnold_schwarzenegger_320'),
|
||||||
|
('druuzil', 'benjamin_affleck_320'),
|
||||||
|
('druuzil', 'benjamin_stiller_384'),
|
||||||
|
('druuzil', 'bradley_pitt_224'),
|
||||||
|
('druuzil', 'brie_larson_384'),
|
||||||
|
('druuzil', 'bryan_cranston_320'),
|
||||||
|
('druuzil', 'catherine_blanchett_352'),
|
||||||
|
('druuzil', 'christian_bale_320'),
|
||||||
|
('druuzil', 'christopher_hemsworth_320'),
|
||||||
|
('druuzil', 'christoph_waltz_384'),
|
||||||
|
('druuzil', 'cillian_murphy_320'),
|
||||||
|
('druuzil', 'cobie_smulders_256'),
|
||||||
|
('druuzil', 'dwayne_johnson_384'),
|
||||||
|
('druuzil', 'edward_norton_320'),
|
||||||
|
('druuzil', 'elisabeth_shue_320'),
|
||||||
|
('druuzil', 'elizabeth_olsen_384'),
|
||||||
|
('druuzil', 'elon_musk_320'),
|
||||||
|
('druuzil', 'emily_blunt_320'),
|
||||||
|
('druuzil', 'emma_stone_384'),
|
||||||
|
('druuzil', 'emma_watson_320'),
|
||||||
|
('druuzil', 'erin_moriarty_384'),
|
||||||
|
('druuzil', 'eva_green_320'),
|
||||||
|
('druuzil', 'ewan_mcgregor_320'),
|
||||||
|
('druuzil', 'florence_pugh_320'),
|
||||||
|
('druuzil', 'freya_allan_320'),
|
||||||
|
('druuzil', 'gary_cole_224'),
|
||||||
|
('druuzil', 'gigi_hadid_224'),
|
||||||
|
('druuzil', 'harrison_ford_384'),
|
||||||
|
('druuzil', 'hayden_christensen_320'),
|
||||||
|
('druuzil', 'heath_ledger_320'),
|
||||||
|
('druuzil', 'henry_cavill_448'),
|
||||||
|
('druuzil', 'hugh_jackman_384'),
|
||||||
|
('druuzil', 'idris_elba_320'),
|
||||||
|
('druuzil', 'jack_nicholson_320'),
|
||||||
|
('druuzil', 'james_mcavoy_320'),
|
||||||
|
('druuzil', 'james_varney_320'),
|
||||||
|
('druuzil', 'jason_momoa_320'),
|
||||||
|
('druuzil', 'jason_statham_320'),
|
||||||
|
('druuzil', 'jennifer_connelly_384'),
|
||||||
|
('druuzil', 'jimmy_donaldson_320'),
|
||||||
|
('druuzil', 'jordan_peterson_384'),
|
||||||
|
('druuzil', 'karl_urban_224'),
|
||||||
|
('druuzil', 'kate_beckinsale_384'),
|
||||||
|
('druuzil', 'laurence_fishburne_384'),
|
||||||
|
('druuzil', 'lili_reinhart_320'),
|
||||||
|
('druuzil', 'mads_mikkelsen_384'),
|
||||||
|
('druuzil', 'mary_winstead_320'),
|
||||||
|
('druuzil', 'margaret_qualley_384'),
|
||||||
|
('druuzil', 'melina_juergens_320'),
|
||||||
|
('druuzil', 'michael_fassbender_320'),
|
||||||
|
('druuzil', 'michael_fox_320'),
|
||||||
|
('druuzil', 'millie_bobby_brown_320'),
|
||||||
|
('druuzil', 'morgan_freeman_320'),
|
||||||
|
('druuzil', 'patrick_stewart_320'),
|
||||||
|
('druuzil', 'rebecca_ferguson_320'),
|
||||||
|
('druuzil', 'scarlett_johansson_320'),
|
||||||
|
('druuzil', 'seth_macfarlane_384'),
|
||||||
|
('druuzil', 'thomas_cruise_320'),
|
||||||
|
('druuzil', 'thomas_hanks_384'),
|
||||||
|
('druuzil', 'william_murray_384'),
|
||||||
|
('edel', 'emma_roberts_224'),
|
||||||
|
('edel', 'ivanka_trump_224'),
|
||||||
|
('edel', 'lize_dzjabrailova_224'),
|
||||||
|
('edel', 'sidney_sweeney_224'),
|
||||||
|
('edel', 'winona_ryder_224')
|
||||||
|
])
|
||||||
|
if download_scope in [ 'lite', 'full' ]:
|
||||||
|
model_config.extend(
|
||||||
|
[
|
||||||
|
('iperov', 'alexandra_daddario_224'),
|
||||||
|
('iperov', 'alexei_navalny_224'),
|
||||||
|
('iperov', 'amber_heard_224'),
|
||||||
|
('iperov', 'dilraba_dilmurat_224'),
|
||||||
|
('iperov', 'elon_musk_224'),
|
||||||
|
('iperov', 'emilia_clarke_224'),
|
||||||
|
('iperov', 'emma_watson_224'),
|
||||||
|
('iperov', 'erin_moriarty_224'),
|
||||||
|
('iperov', 'jackie_chan_224'),
|
||||||
|
('iperov', 'james_carrey_224'),
|
||||||
|
('iperov', 'jason_statham_320'),
|
||||||
|
('iperov', 'keanu_reeves_320'),
|
||||||
|
('iperov', 'margot_robbie_224'),
|
||||||
|
('iperov', 'natalie_dormer_224'),
|
||||||
|
('iperov', 'nicolas_coppola_224'),
|
||||||
|
('iperov', 'robert_downey_224'),
|
||||||
|
('iperov', 'rowan_atkinson_224'),
|
||||||
|
('iperov', 'ryan_reynolds_224'),
|
||||||
|
('iperov', 'scarlett_johansson_224'),
|
||||||
|
('iperov', 'sylvester_stallone_224'),
|
||||||
|
('iperov', 'thomas_cruise_224'),
|
||||||
|
('iperov', 'thomas_holland_224'),
|
||||||
|
('iperov', 'vin_diesel_224'),
|
||||||
|
('iperov', 'vladimir_putin_224')
|
||||||
|
])
|
||||||
|
if download_scope == 'full':
|
||||||
|
model_config.extend(
|
||||||
|
[
|
||||||
|
('jen', 'angelica_trae_288'),
|
||||||
|
('jen', 'ella_freya_224'),
|
||||||
|
('jen', 'emma_myers_320'),
|
||||||
|
('jen', 'evie_pickerill_224'),
|
||||||
|
('jen', 'kang_hyewon_320'),
|
||||||
|
('jen', 'maddie_mead_224'),
|
||||||
|
('jen', 'nicole_turnbull_288'),
|
||||||
|
('mats', 'alica_schmidt_320'),
|
||||||
|
('mats', 'ashley_alexiss_224'),
|
||||||
|
('mats', 'billie_eilish_224'),
|
||||||
|
('mats', 'brie_larson_224'),
|
||||||
|
('mats', 'cara_delevingne_224'),
|
||||||
|
('mats', 'carolin_kebekus_224'),
|
||||||
|
('mats', 'chelsea_clinton_224'),
|
||||||
|
('mats', 'claire_boucher_224'),
|
||||||
|
('mats', 'corinna_kopf_224'),
|
||||||
|
('mats', 'florence_pugh_224'),
|
||||||
|
('mats', 'hillary_clinton_224'),
|
||||||
|
('mats', 'jenna_fischer_224'),
|
||||||
|
('mats', 'kim_jisoo_320'),
|
||||||
|
('mats', 'mica_suarez_320'),
|
||||||
|
('mats', 'shailene_woodley_224'),
|
||||||
|
('mats', 'shraddha_kapoor_320'),
|
||||||
|
('mats', 'yu_jimin_352'),
|
||||||
|
('rumateus', 'alison_brie_224'),
|
||||||
|
('rumateus', 'amber_heard_224'),
|
||||||
|
('rumateus', 'angelina_jolie_224'),
|
||||||
|
('rumateus', 'aubrey_plaza_224'),
|
||||||
|
('rumateus', 'bridget_regan_224'),
|
||||||
|
('rumateus', 'cobie_smulders_224'),
|
||||||
|
('rumateus', 'deborah_woll_224'),
|
||||||
|
('rumateus', 'dua_lipa_224'),
|
||||||
|
('rumateus', 'emma_stone_224'),
|
||||||
|
('rumateus', 'hailee_steinfeld_224'),
|
||||||
|
('rumateus', 'hilary_duff_224'),
|
||||||
|
('rumateus', 'jessica_alba_224'),
|
||||||
|
('rumateus', 'jessica_biel_224'),
|
||||||
|
('rumateus', 'john_cena_224'),
|
||||||
|
('rumateus', 'kim_kardashian_224'),
|
||||||
|
('rumateus', 'kristen_bell_224'),
|
||||||
|
('rumateus', 'lucy_liu_224'),
|
||||||
|
('rumateus', 'margot_robbie_224'),
|
||||||
|
('rumateus', 'megan_fox_224'),
|
||||||
|
('rumateus', 'meghan_markle_224'),
|
||||||
|
('rumateus', 'millie_bobby_brown_224'),
|
||||||
|
('rumateus', 'natalie_portman_224'),
|
||||||
|
('rumateus', 'nicki_minaj_224'),
|
||||||
|
('rumateus', 'olivia_wilde_224'),
|
||||||
|
('rumateus', 'shay_mitchell_224'),
|
||||||
|
('rumateus', 'sophie_turner_224'),
|
||||||
|
('rumateus', 'taylor_swift_224')
|
||||||
|
])
|
||||||
|
model_set : ModelSet = {}
|
||||||
|
|
||||||
|
for model_scope, model_name in model_config:
|
||||||
|
model_id = '/'.join([ model_scope, model_name ])
|
||||||
|
|
||||||
|
model_set[model_id] =\
|
||||||
|
{
|
||||||
|
'hashes':
|
||||||
|
{
|
||||||
|
'deep_swapper':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url_by_provider('huggingface', 'deepfacelive-models-' + model_scope, model_name + '.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/' + model_scope + '/' + model_name + '.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'deep_swapper':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url_by_provider('huggingface', 'deepfacelive-models-' + model_scope, model_name + '.dfm'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/' + model_scope + '/' + model_name + '.dfm')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'template': 'dfl_whole_face'
|
||||||
|
}
|
||||||
|
|
||||||
|
custom_model_file_paths = resolve_file_paths(resolve_relative_path('../.assets/models/custom'))
|
||||||
|
|
||||||
|
if custom_model_file_paths:
|
||||||
|
|
||||||
|
for model_file_path in custom_model_file_paths:
|
||||||
|
model_id = '/'.join([ 'custom', get_file_name(model_file_path) ])
|
||||||
|
|
||||||
|
model_set[model_id] =\
|
||||||
|
{
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'deep_swapper':
|
||||||
|
{
|
||||||
|
'path': resolve_relative_path(model_file_path)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'template': 'dfl_whole_face'
|
||||||
|
}
|
||||||
|
|
||||||
|
return model_set
|
||||||
|
|
||||||
|
|
||||||
|
def get_inference_pool() -> InferencePool:
|
||||||
|
model_names = [ state_manager.get_item('deep_swapper_model') ]
|
||||||
|
model_source_set = get_model_options().get('sources')
|
||||||
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
|
def clear_inference_pool() -> None:
|
||||||
|
model_names = [ state_manager.get_item('deep_swapper_model') ]
|
||||||
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
|
def get_model_options() -> ModelOptions:
|
||||||
|
model_name = state_manager.get_item('deep_swapper_model')
|
||||||
|
return create_static_model_set('full').get(model_name)
|
||||||
|
|
||||||
|
|
||||||
|
def get_model_size() -> Size:
|
||||||
|
deep_swapper = get_inference_pool().get('deep_swapper')
|
||||||
|
|
||||||
|
for deep_swapper_input in deep_swapper.get_inputs():
|
||||||
|
if deep_swapper_input.name == 'in_face:0':
|
||||||
|
return deep_swapper_input.shape[1:3]
|
||||||
|
|
||||||
|
return 0, 0
|
||||||
|
|
||||||
|
|
||||||
|
def register_args(program : ArgumentParser) -> None:
|
||||||
|
group_processors = find_argument_group(program, 'processors')
|
||||||
|
if group_processors:
|
||||||
|
group_processors.add_argument('--deep-swapper-model', help = wording.get('help.deep_swapper_model'), default = config.get_str_value('processors', 'deep_swapper_model', 'iperov/elon_musk_224'), choices = processors_choices.deep_swapper_models)
|
||||||
|
group_processors.add_argument('--deep-swapper-morph', help = wording.get('help.deep_swapper_morph'), type = int, default = config.get_int_value('processors', 'deep_swapper_morph', '100'), choices = processors_choices.deep_swapper_morph_range, metavar = create_int_metavar(processors_choices.deep_swapper_morph_range))
|
||||||
|
facefusion.jobs.job_store.register_step_keys([ 'deep_swapper_model', 'deep_swapper_morph' ])
|
||||||
|
|
||||||
|
|
||||||
|
def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
||||||
|
apply_state_item('deep_swapper_model', args.get('deep_swapper_model'))
|
||||||
|
apply_state_item('deep_swapper_morph', args.get('deep_swapper_morph'))
|
||||||
|
|
||||||
|
|
||||||
|
def pre_check() -> bool:
|
||||||
|
model_hash_set = get_model_options().get('hashes')
|
||||||
|
model_source_set = get_model_options().get('sources')
|
||||||
|
|
||||||
|
if model_hash_set and model_source_set:
|
||||||
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def pre_process(mode : ProcessMode) -> bool:
|
||||||
|
if mode in [ 'output', 'preview' ] and not is_image(state_manager.get_item('target_path')) and not is_video(state_manager.get_item('target_path')):
|
||||||
|
logger.error(wording.get('choose_image_or_video_target') + wording.get('exclamation_mark'), __name__)
|
||||||
|
return False
|
||||||
|
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
||||||
|
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
||||||
|
return False
|
||||||
|
if mode == 'output' and not same_file_extension(state_manager.get_item('target_path'), state_manager.get_item('output_path')):
|
||||||
|
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def post_process() -> None:
|
||||||
|
read_static_image.cache_clear()
|
||||||
|
if state_manager.get_item('video_memory_strategy') in [ 'strict', 'moderate' ]:
|
||||||
|
clear_inference_pool()
|
||||||
|
if state_manager.get_item('video_memory_strategy') == 'strict':
|
||||||
|
content_analyser.clear_inference_pool()
|
||||||
|
face_classifier.clear_inference_pool()
|
||||||
|
face_detector.clear_inference_pool()
|
||||||
|
face_landmarker.clear_inference_pool()
|
||||||
|
face_masker.clear_inference_pool()
|
||||||
|
face_recognizer.clear_inference_pool()
|
||||||
|
|
||||||
|
|
||||||
|
def swap_face(target_face : Face, temp_vision_frame : VisionFrame) -> VisionFrame:
|
||||||
|
model_template = get_model_options().get('template')
|
||||||
|
model_size = get_model_size()
|
||||||
|
crop_vision_frame, affine_matrix = warp_face_by_face_landmark_5(temp_vision_frame, target_face.landmark_set.get('5/68'), model_template, model_size)
|
||||||
|
crop_vision_frame_raw = crop_vision_frame.copy()
|
||||||
|
box_mask = create_static_box_mask(crop_vision_frame.shape[:2][::-1], state_manager.get_item('face_mask_blur'), state_manager.get_item('face_mask_padding'))
|
||||||
|
crop_masks =\
|
||||||
|
[
|
||||||
|
box_mask
|
||||||
|
]
|
||||||
|
|
||||||
|
if 'occlusion' in state_manager.get_item('face_mask_types'):
|
||||||
|
occlusion_mask = create_occlusion_mask(crop_vision_frame)
|
||||||
|
crop_masks.append(occlusion_mask)
|
||||||
|
|
||||||
|
crop_vision_frame = prepare_crop_frame(crop_vision_frame)
|
||||||
|
deep_swapper_morph = numpy.array([ numpy.interp(state_manager.get_item('deep_swapper_morph'), [ 0, 100 ], [ 0, 1 ]) ]).astype(numpy.float32)
|
||||||
|
crop_vision_frame, crop_source_mask, crop_target_mask = forward(crop_vision_frame, deep_swapper_morph)
|
||||||
|
crop_vision_frame = normalize_crop_frame(crop_vision_frame)
|
||||||
|
crop_vision_frame = conditional_match_frame_color(crop_vision_frame_raw, crop_vision_frame)
|
||||||
|
crop_masks.append(prepare_crop_mask(crop_source_mask, crop_target_mask))
|
||||||
|
|
||||||
|
if 'region' in state_manager.get_item('face_mask_types'):
|
||||||
|
region_mask = create_region_mask(crop_vision_frame, state_manager.get_item('face_mask_regions'))
|
||||||
|
crop_masks.append(region_mask)
|
||||||
|
|
||||||
|
crop_mask = numpy.minimum.reduce(crop_masks).clip(0, 1)
|
||||||
|
paste_vision_frame = paste_back(temp_vision_frame, crop_vision_frame, crop_mask, affine_matrix)
|
||||||
|
return paste_vision_frame
|
||||||
|
|
||||||
|
|
||||||
|
def forward(crop_vision_frame : VisionFrame, deep_swapper_morph : DeepSwapperMorph) -> Tuple[VisionFrame, Mask, Mask]:
|
||||||
|
deep_swapper = get_inference_pool().get('deep_swapper')
|
||||||
|
deep_swapper_inputs = {}
|
||||||
|
|
||||||
|
for deep_swapper_input in deep_swapper.get_inputs():
|
||||||
|
if deep_swapper_input.name == 'in_face:0':
|
||||||
|
deep_swapper_inputs[deep_swapper_input.name] = crop_vision_frame
|
||||||
|
if deep_swapper_input.name == 'morph_value:0':
|
||||||
|
deep_swapper_inputs[deep_swapper_input.name] = deep_swapper_morph
|
||||||
|
|
||||||
|
with thread_semaphore():
|
||||||
|
crop_target_mask, crop_vision_frame, crop_source_mask = deep_swapper.run(None, deep_swapper_inputs)
|
||||||
|
|
||||||
|
return crop_vision_frame[0], crop_source_mask[0], crop_target_mask[0]
|
||||||
|
|
||||||
|
|
||||||
|
def has_morph_input() -> bool:
|
||||||
|
deep_swapper = get_inference_pool().get('deep_swapper')
|
||||||
|
|
||||||
|
for deep_swapper_input in deep_swapper.get_inputs():
|
||||||
|
if deep_swapper_input.name == 'morph_value:0':
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_crop_frame(crop_vision_frame : VisionFrame) -> VisionFrame:
|
||||||
|
crop_vision_frame = cv2.addWeighted(crop_vision_frame, 1.75, cv2.GaussianBlur(crop_vision_frame, (0, 0), 2), -0.75, 0)
|
||||||
|
crop_vision_frame = crop_vision_frame / 255.0
|
||||||
|
crop_vision_frame = numpy.expand_dims(crop_vision_frame, axis = 0).astype(numpy.float32)
|
||||||
|
return crop_vision_frame
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_crop_frame(crop_vision_frame : VisionFrame) -> VisionFrame:
|
||||||
|
crop_vision_frame = (crop_vision_frame * 255.0).clip(0, 255)
|
||||||
|
crop_vision_frame = crop_vision_frame.astype(numpy.uint8)
|
||||||
|
return crop_vision_frame
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_crop_mask(crop_source_mask : Mask, crop_target_mask : Mask) -> Mask:
|
||||||
|
model_size = get_model_size()
|
||||||
|
blur_size = 6.25
|
||||||
|
kernel_size = 3
|
||||||
|
crop_mask = numpy.minimum.reduce([ crop_source_mask, crop_target_mask ])
|
||||||
|
crop_mask = crop_mask.reshape(model_size).clip(0, 1)
|
||||||
|
crop_mask = cv2.erode(crop_mask, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (kernel_size, kernel_size)), iterations = 2)
|
||||||
|
crop_mask = cv2.GaussianBlur(crop_mask, (0, 0), blur_size)
|
||||||
|
return crop_mask
|
||||||
|
|
||||||
|
|
||||||
|
def get_reference_frame(source_face : Face, target_face : Face, temp_vision_frame : VisionFrame) -> VisionFrame:
|
||||||
|
return swap_face(target_face, temp_vision_frame)
|
||||||
|
|
||||||
|
|
||||||
|
def process_frame(inputs : DeepSwapperInputs) -> VisionFrame:
|
||||||
|
reference_faces = inputs.get('reference_faces')
|
||||||
|
target_vision_frame = inputs.get('target_vision_frame')
|
||||||
|
many_faces = sort_and_filter_faces(get_many_faces([ target_vision_frame ]))
|
||||||
|
|
||||||
|
if state_manager.get_item('face_selector_mode') == 'many':
|
||||||
|
if many_faces:
|
||||||
|
for target_face in many_faces:
|
||||||
|
target_vision_frame = swap_face(target_face, target_vision_frame)
|
||||||
|
if state_manager.get_item('face_selector_mode') == 'one':
|
||||||
|
target_face = get_one_face(many_faces)
|
||||||
|
if target_face:
|
||||||
|
target_vision_frame = swap_face(target_face, target_vision_frame)
|
||||||
|
if state_manager.get_item('face_selector_mode') == 'reference':
|
||||||
|
similar_faces = find_similar_faces(many_faces, reference_faces, state_manager.get_item('reference_face_distance'))
|
||||||
|
if similar_faces:
|
||||||
|
for similar_face in similar_faces:
|
||||||
|
target_vision_frame = swap_face(similar_face, target_vision_frame)
|
||||||
|
return target_vision_frame
|
||||||
|
|
||||||
|
|
||||||
|
def process_frames(source_path : List[str], queue_payloads : List[QueuePayload], update_progress : UpdateProgress) -> None:
|
||||||
|
reference_faces = get_reference_faces() if 'reference' in state_manager.get_item('face_selector_mode') else None
|
||||||
|
|
||||||
|
for queue_payload in process_manager.manage(queue_payloads):
|
||||||
|
target_vision_path = queue_payload['frame_path']
|
||||||
|
target_vision_frame = read_image(target_vision_path)
|
||||||
|
output_vision_frame = process_frame(
|
||||||
|
{
|
||||||
|
'reference_faces': reference_faces,
|
||||||
|
'target_vision_frame': target_vision_frame
|
||||||
|
})
|
||||||
|
write_image(target_vision_path, output_vision_frame)
|
||||||
|
update_progress(1)
|
||||||
|
|
||||||
|
|
||||||
|
def process_image(source_path : str, target_path : str, output_path : str) -> None:
|
||||||
|
reference_faces = get_reference_faces() if 'reference' in state_manager.get_item('face_selector_mode') else None
|
||||||
|
target_vision_frame = read_static_image(target_path)
|
||||||
|
output_vision_frame = process_frame(
|
||||||
|
{
|
||||||
|
'reference_faces': reference_faces,
|
||||||
|
'target_vision_frame': target_vision_frame
|
||||||
|
})
|
||||||
|
write_image(output_path, output_vision_frame)
|
||||||
|
|
||||||
|
|
||||||
|
def process_video(source_paths : List[str], temp_frame_paths : List[str]) -> None:
|
||||||
|
processors.multi_process_frames(None, temp_frame_paths, process_frames)
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from functools import lru_cache
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
@@ -9,7 +10,7 @@ import facefusion.jobs.job_store
|
|||||||
import facefusion.processors.core as processors
|
import facefusion.processors.core as processors
|
||||||
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, wording
|
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, wording
|
||||||
from facefusion.common_helper import create_int_metavar
|
from facefusion.common_helper import create_int_metavar
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
from facefusion.face_analyser import get_many_faces, get_one_face
|
from facefusion.face_analyser import get_many_faces, get_one_face
|
||||||
from facefusion.face_helper import paste_back, warp_face_by_face_landmark_5
|
from facefusion.face_helper import paste_back, warp_face_by_face_landmark_5
|
||||||
from facefusion.face_masker import create_occlusion_mask, create_static_box_mask
|
from facefusion.face_masker import create_occlusion_mask, create_static_box_mask
|
||||||
@@ -18,80 +19,84 @@ from facefusion.face_store import get_reference_faces
|
|||||||
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.live_portrait import create_rotation, limit_expression
|
from facefusion.processors.live_portrait import create_rotation, limit_expression
|
||||||
from facefusion.processors.typing import ExpressionRestorerInputs
|
from facefusion.processors.types import ExpressionRestorerInputs, LivePortraitExpression, LivePortraitFeatureVolume, LivePortraitMotionPoints, LivePortraitPitch, LivePortraitRoll, LivePortraitScale, LivePortraitTranslation, LivePortraitYaw
|
||||||
from facefusion.processors.typing import LivePortraitExpression, LivePortraitFeatureVolume, LivePortraitMotionPoints, LivePortraitPitch, LivePortraitRoll, LivePortraitScale, LivePortraitTranslation, LivePortraitYaw
|
|
||||||
from facefusion.program_helper import find_argument_group
|
from facefusion.program_helper import find_argument_group
|
||||||
from facefusion.thread_helper import conditional_thread_semaphore, thread_semaphore
|
from facefusion.thread_helper import conditional_thread_semaphore, thread_semaphore
|
||||||
from facefusion.typing import ApplyStateItem, Args, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
from facefusion.types import ApplyStateItem, Args, DownloadScope, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
||||||
from facefusion.vision import get_video_frame, read_image, read_static_image, write_image
|
from facefusion.vision import read_image, read_static_image, read_video_frame, write_image
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'live_portrait':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'live_portrait':
|
||||||
{
|
{
|
||||||
'feature_extractor':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_feature_extractor.hash',
|
'feature_extractor':
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_feature_extractor.hash')
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_feature_extractor.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_feature_extractor.hash')
|
||||||
|
},
|
||||||
|
'motion_extractor':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_motion_extractor.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_motion_extractor.hash')
|
||||||
|
},
|
||||||
|
'generator':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_generator.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_generator.hash')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'motion_extractor':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_motion_extractor.hash',
|
'feature_extractor':
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_motion_extractor.hash')
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_feature_extractor.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_feature_extractor.onnx')
|
||||||
|
},
|
||||||
|
'motion_extractor':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_motion_extractor.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_motion_extractor.onnx')
|
||||||
|
},
|
||||||
|
'generator':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_generator.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_generator.onnx')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'generator':
|
'template': 'arcface_128',
|
||||||
{
|
'size': (512, 512)
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_generator.hash',
|
}
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_generator.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'feature_extractor':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_feature_extractor.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_feature_extractor.onnx')
|
|
||||||
},
|
|
||||||
'motion_extractor':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_motion_extractor.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_motion_extractor.onnx')
|
|
||||||
},
|
|
||||||
'generator':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_generator.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_generator.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'template': 'arcface_128_v2',
|
|
||||||
'size': (512, 512)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
model_sources = get_model_options().get('sources')
|
model_names = [ state_manager.get_item('expression_restorer_model') ]
|
||||||
model_context = __name__ + '.' + state_manager.get_item('expression_restorer_model')
|
model_source_set = get_model_options().get('sources')
|
||||||
return inference_manager.get_inference_pool(model_context, model_sources)
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
inference_manager.clear_inference_pool(__name__)
|
model_names = [ state_manager.get_item('expression_restorer_model') ]
|
||||||
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def get_model_options() -> ModelOptions:
|
def get_model_options() -> ModelOptions:
|
||||||
expression_restorer_model = state_manager.get_item('expression_restorer_model')
|
model_name = state_manager.get_item('expression_restorer_model')
|
||||||
return MODEL_SET.get(expression_restorer_model)
|
return create_static_model_set('full').get(model_name)
|
||||||
|
|
||||||
|
|
||||||
def register_args(program : ArgumentParser) -> None:
|
def register_args(program : ArgumentParser) -> None:
|
||||||
group_processors = find_argument_group(program, 'processors')
|
group_processors = find_argument_group(program, 'processors')
|
||||||
if group_processors:
|
if group_processors:
|
||||||
group_processors.add_argument('--expression-restorer-model', help = wording.get('help.expression_restorer_model'), default = config.get_str_value('processors.expression_restorer_model', 'live_portrait'), choices = processors_choices.expression_restorer_models)
|
group_processors.add_argument('--expression-restorer-model', help = wording.get('help.expression_restorer_model'), default = config.get_str_value('processors', 'expression_restorer_model', 'live_portrait'), choices = processors_choices.expression_restorer_models)
|
||||||
group_processors.add_argument('--expression-restorer-factor', help = wording.get('help.expression_restorer_factor'), type = int, default = config.get_int_value('processors.expression_restorer_factor', '80'), choices = processors_choices.expression_restorer_factor_range, metavar = create_int_metavar(processors_choices.expression_restorer_factor_range))
|
group_processors.add_argument('--expression-restorer-factor', help = wording.get('help.expression_restorer_factor'), type = int, default = config.get_int_value('processors', 'expression_restorer_factor', '80'), choices = processors_choices.expression_restorer_factor_range, metavar = create_int_metavar(processors_choices.expression_restorer_factor_range))
|
||||||
facefusion.jobs.job_store.register_step_keys([ 'expression_restorer_model','expression_restorer_factor' ])
|
facefusion.jobs.job_store.register_step_keys([ 'expression_restorer_model', 'expression_restorer_factor' ])
|
||||||
|
|
||||||
|
|
||||||
def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
||||||
@@ -100,21 +105,23 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set = get_model_options().get('hashes')
|
||||||
model_hashes = get_model_options().get('hashes')
|
model_source_set = get_model_options().get('sources')
|
||||||
model_sources = get_model_options().get('sources')
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def pre_process(mode : ProcessMode) -> bool:
|
def pre_process(mode : ProcessMode) -> bool:
|
||||||
|
if mode == 'stream':
|
||||||
|
logger.error(wording.get('stream_not_supported') + wording.get('exclamation_mark'), __name__)
|
||||||
|
return False
|
||||||
if mode in [ 'output', 'preview' ] and not is_image(state_manager.get_item('target_path')) and not is_video(state_manager.get_item('target_path')):
|
if mode in [ 'output', 'preview' ] and not is_image(state_manager.get_item('target_path')) and not is_video(state_manager.get_item('target_path')):
|
||||||
logger.error(wording.get('choose_image_or_video_target') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('choose_image_or_video_target') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
if mode == 'output' and not same_file_extension([ state_manager.get_item('target_path'), state_manager.get_item('output_path') ]):
|
if mode == 'output' and not same_file_extension(state_manager.get_item('target_path'), state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@@ -222,7 +229,7 @@ def prepare_crop_frame(crop_vision_frame : VisionFrame) -> VisionFrame:
|
|||||||
|
|
||||||
def normalize_crop_frame(crop_vision_frame : VisionFrame) -> VisionFrame:
|
def normalize_crop_frame(crop_vision_frame : VisionFrame) -> VisionFrame:
|
||||||
crop_vision_frame = crop_vision_frame.transpose(1, 2, 0).clip(0, 1)
|
crop_vision_frame = crop_vision_frame.transpose(1, 2, 0).clip(0, 1)
|
||||||
crop_vision_frame = (crop_vision_frame * 255.0)
|
crop_vision_frame = crop_vision_frame * 255.0
|
||||||
crop_vision_frame = crop_vision_frame.astype(numpy.uint8)[:, :, ::-1]
|
crop_vision_frame = crop_vision_frame.astype(numpy.uint8)[:, :, ::-1]
|
||||||
return crop_vision_frame
|
return crop_vision_frame
|
||||||
|
|
||||||
@@ -260,7 +267,7 @@ def process_frames(source_path : List[str], queue_payloads : List[QueuePayload],
|
|||||||
frame_number = queue_payload.get('frame_number')
|
frame_number = queue_payload.get('frame_number')
|
||||||
if state_manager.get_item('trim_frame_start'):
|
if state_manager.get_item('trim_frame_start'):
|
||||||
frame_number += state_manager.get_item('trim_frame_start')
|
frame_number += state_manager.get_item('trim_frame_start')
|
||||||
source_vision_frame = get_video_frame(state_manager.get_item('target_path'), frame_number)
|
source_vision_frame = read_video_frame(state_manager.get_item('target_path'), frame_number)
|
||||||
target_vision_path = queue_payload.get('frame_path')
|
target_vision_path = queue_payload.get('frame_path')
|
||||||
target_vision_frame = read_image(target_vision_path)
|
target_vision_frame = read_image(target_vision_path)
|
||||||
output_vision_frame = process_frame(
|
output_vision_frame = process_frame(
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ from facefusion.face_selector import find_similar_faces, sort_and_filter_faces
|
|||||||
from facefusion.face_store import get_reference_faces
|
from facefusion.face_store import get_reference_faces
|
||||||
from facefusion.filesystem import in_directory, same_file_extension
|
from facefusion.filesystem import in_directory, same_file_extension
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.typing import FaceDebuggerInputs
|
from facefusion.processors.types import FaceDebuggerInputs
|
||||||
from facefusion.program_helper import find_argument_group
|
from facefusion.program_helper import find_argument_group
|
||||||
from facefusion.typing import ApplyStateItem, Args, Face, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
from facefusion.types import ApplyStateItem, Args, Face, InferencePool, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
||||||
from facefusion.vision import read_image, read_static_image, write_image
|
from facefusion.vision import read_image, read_static_image, write_image
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> None:
|
def get_inference_pool() -> InferencePool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ def clear_inference_pool() -> None:
|
|||||||
def register_args(program : ArgumentParser) -> None:
|
def register_args(program : ArgumentParser) -> None:
|
||||||
group_processors = find_argument_group(program, 'processors')
|
group_processors = find_argument_group(program, 'processors')
|
||||||
if group_processors:
|
if group_processors:
|
||||||
group_processors.add_argument('--face-debugger-items', help = wording.get('help.face_debugger_items').format(choices = ', '.join(processors_choices.face_debugger_items)), default = config.get_str_list('processors.face_debugger_items', 'face-landmark-5/68 face-mask'), choices = processors_choices.face_debugger_items, nargs = '+', metavar = 'FACE_DEBUGGER_ITEMS')
|
group_processors.add_argument('--face-debugger-items', help = wording.get('help.face_debugger_items').format(choices = ', '.join(processors_choices.face_debugger_items)), default = config.get_str_list('processors', 'face_debugger_items', 'face-landmark-5/68 face-mask'), choices = processors_choices.face_debugger_items, nargs = '+', metavar = 'FACE_DEBUGGER_ITEMS')
|
||||||
facefusion.jobs.job_store.register_step_keys([ 'face_debugger_items' ])
|
facefusion.jobs.job_store.register_step_keys([ 'face_debugger_items' ])
|
||||||
|
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
|||||||
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
if mode == 'output' and not same_file_extension([ state_manager.get_item('target_path'), state_manager.get_item('output_path') ]):
|
if mode == 'output' and not same_file_extension(state_manager.get_item('target_path'), state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@@ -90,7 +90,7 @@ def debug_face(target_face : Face, temp_vision_frame : VisionFrame) -> VisionFra
|
|||||||
cv2.line(temp_vision_frame, (x1, y1), (x1, y2), primary_light_color, 3)
|
cv2.line(temp_vision_frame, (x1, y1), (x1, y2), primary_light_color, 3)
|
||||||
|
|
||||||
if 'face-mask' in face_debugger_items:
|
if 'face-mask' in face_debugger_items:
|
||||||
crop_vision_frame, affine_matrix = warp_face_by_face_landmark_5(temp_vision_frame, target_face.landmark_set.get('5/68'), 'arcface_128_v2', (512, 512))
|
crop_vision_frame, affine_matrix = warp_face_by_face_landmark_5(temp_vision_frame, target_face.landmark_set.get('5/68'), 'arcface_128', (512, 512))
|
||||||
inverse_matrix = cv2.invertAffineTransform(affine_matrix)
|
inverse_matrix = cv2.invertAffineTransform(affine_matrix)
|
||||||
temp_size = temp_vision_frame.shape[:2][::-1]
|
temp_size = temp_vision_frame.shape[:2][::-1]
|
||||||
crop_masks = []
|
crop_masks = []
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from functools import lru_cache
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
@@ -9,7 +10,7 @@ import facefusion.jobs.job_store
|
|||||||
import facefusion.processors.core as processors
|
import facefusion.processors.core as processors
|
||||||
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, wording
|
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, wording
|
||||||
from facefusion.common_helper import create_float_metavar
|
from facefusion.common_helper import create_float_metavar
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
from facefusion.face_analyser import get_many_faces, get_one_face
|
from facefusion.face_analyser import get_many_faces, get_one_face
|
||||||
from facefusion.face_helper import paste_back, scale_face_landmark_5, warp_face_by_face_landmark_5
|
from facefusion.face_helper import paste_back, scale_face_landmark_5, warp_face_by_face_landmark_5
|
||||||
from facefusion.face_masker import create_static_box_mask
|
from facefusion.face_masker import create_static_box_mask
|
||||||
@@ -18,122 +19,126 @@ from facefusion.face_store import get_reference_faces
|
|||||||
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.live_portrait import create_rotation, limit_euler_angles, limit_expression
|
from facefusion.processors.live_portrait import create_rotation, limit_euler_angles, limit_expression
|
||||||
from facefusion.processors.typing import FaceEditorInputs, LivePortraitExpression, LivePortraitFeatureVolume, LivePortraitMotionPoints, LivePortraitPitch, LivePortraitRoll, LivePortraitRotation, LivePortraitScale, LivePortraitTranslation, LivePortraitYaw
|
from facefusion.processors.types import FaceEditorInputs, LivePortraitExpression, LivePortraitFeatureVolume, LivePortraitMotionPoints, LivePortraitPitch, LivePortraitRoll, LivePortraitRotation, LivePortraitScale, LivePortraitTranslation, LivePortraitYaw
|
||||||
from facefusion.program_helper import find_argument_group
|
from facefusion.program_helper import find_argument_group
|
||||||
from facefusion.thread_helper import conditional_thread_semaphore, thread_semaphore
|
from facefusion.thread_helper import conditional_thread_semaphore, thread_semaphore
|
||||||
from facefusion.typing import ApplyStateItem, Args, Face, FaceLandmark68, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
from facefusion.types import ApplyStateItem, Args, DownloadScope, Face, FaceLandmark68, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
||||||
from facefusion.vision import read_image, read_static_image, write_image
|
from facefusion.vision import read_image, read_static_image, write_image
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'live_portrait':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'live_portrait':
|
||||||
{
|
{
|
||||||
'feature_extractor':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_feature_extractor.hash',
|
'feature_extractor':
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_feature_extractor.hash')
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_feature_extractor.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_feature_extractor.hash')
|
||||||
|
},
|
||||||
|
'motion_extractor':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_motion_extractor.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_motion_extractor.hash')
|
||||||
|
},
|
||||||
|
'eye_retargeter':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_eye_retargeter.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_eye_retargeter.hash')
|
||||||
|
},
|
||||||
|
'lip_retargeter':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_lip_retargeter.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_lip_retargeter.hash')
|
||||||
|
},
|
||||||
|
'stitcher':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_stitcher.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_stitcher.hash')
|
||||||
|
},
|
||||||
|
'generator':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_generator.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_generator.hash')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'motion_extractor':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_motion_extractor.hash',
|
'feature_extractor':
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_motion_extractor.hash')
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_feature_extractor.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_feature_extractor.onnx')
|
||||||
|
},
|
||||||
|
'motion_extractor':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_motion_extractor.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_motion_extractor.onnx')
|
||||||
|
},
|
||||||
|
'eye_retargeter':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_eye_retargeter.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_eye_retargeter.onnx')
|
||||||
|
},
|
||||||
|
'lip_retargeter':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_lip_retargeter.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_lip_retargeter.onnx')
|
||||||
|
},
|
||||||
|
'stitcher':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_stitcher.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_stitcher.onnx')
|
||||||
|
},
|
||||||
|
'generator':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'live_portrait_generator.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/live_portrait_generator.onnx')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'eye_retargeter':
|
'template': 'ffhq_512',
|
||||||
{
|
'size': (512, 512)
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_eye_retargeter.hash',
|
}
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_eye_retargeter.hash')
|
|
||||||
},
|
|
||||||
'lip_retargeter':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_lip_retargeter.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_lip_retargeter.hash')
|
|
||||||
},
|
|
||||||
'stitcher':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_stitcher.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_stitcher.hash')
|
|
||||||
},
|
|
||||||
'generator':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_generator.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_generator.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'feature_extractor':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_feature_extractor.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_feature_extractor.onnx')
|
|
||||||
},
|
|
||||||
'motion_extractor':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_motion_extractor.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_motion_extractor.onnx')
|
|
||||||
},
|
|
||||||
'eye_retargeter':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_eye_retargeter.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_eye_retargeter.onnx')
|
|
||||||
},
|
|
||||||
'lip_retargeter':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_lip_retargeter.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_lip_retargeter.onnx')
|
|
||||||
},
|
|
||||||
'stitcher':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_stitcher.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_stitcher.onnx')
|
|
||||||
},
|
|
||||||
'generator':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/live_portrait_generator.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/live_portrait_generator.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'template': 'ffhq_512',
|
|
||||||
'size': (512, 512)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
model_sources = get_model_options().get('sources')
|
model_names = [ state_manager.get_item('face_editor_model') ]
|
||||||
model_context = __name__ + '.' + state_manager.get_item('face_editor_model')
|
model_source_set = get_model_options().get('sources')
|
||||||
return inference_manager.get_inference_pool(model_context, model_sources)
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
model_context = __name__ + '.' + state_manager.get_item('face_editor_model')
|
model_names = [ state_manager.get_item('face_editor_model') ]
|
||||||
inference_manager.clear_inference_pool(model_context)
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def get_model_options() -> ModelOptions:
|
def get_model_options() -> ModelOptions:
|
||||||
face_editor_model = state_manager.get_item('face_editor_model')
|
model_name = state_manager.get_item('face_editor_model')
|
||||||
return MODEL_SET.get(face_editor_model)
|
return create_static_model_set('full').get(model_name)
|
||||||
|
|
||||||
|
|
||||||
def register_args(program : ArgumentParser) -> None:
|
def register_args(program : ArgumentParser) -> None:
|
||||||
group_processors = find_argument_group(program, 'processors')
|
group_processors = find_argument_group(program, 'processors')
|
||||||
if group_processors:
|
if group_processors:
|
||||||
group_processors.add_argument('--face-editor-model', help = wording.get('help.face_editor_model'), default = config.get_str_value('processors.face_editor_model', 'live_portrait'), choices = processors_choices.face_editor_models)
|
group_processors.add_argument('--face-editor-model', help = wording.get('help.face_editor_model'), default = config.get_str_value('processors', 'face_editor_model', 'live_portrait'), choices = processors_choices.face_editor_models)
|
||||||
group_processors.add_argument('--face-editor-eyebrow-direction', help = wording.get('help.face_editor_eyebrow_direction'), type = float, default = config.get_float_value('processors.face_editor_eyebrow_direction', '0'), choices = processors_choices.face_editor_eyebrow_direction_range, metavar = create_float_metavar(processors_choices.face_editor_eyebrow_direction_range))
|
group_processors.add_argument('--face-editor-eyebrow-direction', help = wording.get('help.face_editor_eyebrow_direction'), type = float, default = config.get_float_value('processors', 'face_editor_eyebrow_direction', '0'), choices = processors_choices.face_editor_eyebrow_direction_range, metavar = create_float_metavar(processors_choices.face_editor_eyebrow_direction_range))
|
||||||
group_processors.add_argument('--face-editor-eye-gaze-horizontal', help = wording.get('help.face_editor_eye_gaze_horizontal'), type = float, default = config.get_float_value('processors.face_editor_eye_gaze_horizontal', '0'), choices = processors_choices.face_editor_eye_gaze_horizontal_range, metavar = create_float_metavar(processors_choices.face_editor_eye_gaze_horizontal_range))
|
group_processors.add_argument('--face-editor-eye-gaze-horizontal', help = wording.get('help.face_editor_eye_gaze_horizontal'), type = float, default = config.get_float_value('processors', 'face_editor_eye_gaze_horizontal', '0'), choices = processors_choices.face_editor_eye_gaze_horizontal_range, metavar = create_float_metavar(processors_choices.face_editor_eye_gaze_horizontal_range))
|
||||||
group_processors.add_argument('--face-editor-eye-gaze-vertical', help = wording.get('help.face_editor_eye_gaze_vertical'), type = float, default = config.get_float_value('processors.face_editor_eye_gaze_vertical', '0'), choices = processors_choices.face_editor_eye_gaze_vertical_range, metavar = create_float_metavar(processors_choices.face_editor_eye_gaze_vertical_range))
|
group_processors.add_argument('--face-editor-eye-gaze-vertical', help = wording.get('help.face_editor_eye_gaze_vertical'), type = float, default = config.get_float_value('processors', 'face_editor_eye_gaze_vertical', '0'), choices = processors_choices.face_editor_eye_gaze_vertical_range, metavar = create_float_metavar(processors_choices.face_editor_eye_gaze_vertical_range))
|
||||||
group_processors.add_argument('--face-editor-eye-open-ratio', help = wording.get('help.face_editor_eye_open_ratio'), type = float, default = config.get_float_value('processors.face_editor_eye_open_ratio', '0'), choices = processors_choices.face_editor_eye_open_ratio_range, metavar = create_float_metavar(processors_choices.face_editor_eye_open_ratio_range))
|
group_processors.add_argument('--face-editor-eye-open-ratio', help = wording.get('help.face_editor_eye_open_ratio'), type = float, default = config.get_float_value('processors', 'face_editor_eye_open_ratio', '0'), choices = processors_choices.face_editor_eye_open_ratio_range, metavar = create_float_metavar(processors_choices.face_editor_eye_open_ratio_range))
|
||||||
group_processors.add_argument('--face-editor-lip-open-ratio', help = wording.get('help.face_editor_lip_open_ratio'), type = float, default = config.get_float_value('processors.face_editor_lip_open_ratio', '0'), choices = processors_choices.face_editor_lip_open_ratio_range, metavar = create_float_metavar(processors_choices.face_editor_lip_open_ratio_range))
|
group_processors.add_argument('--face-editor-lip-open-ratio', help = wording.get('help.face_editor_lip_open_ratio'), type = float, default = config.get_float_value('processors', 'face_editor_lip_open_ratio', '0'), choices = processors_choices.face_editor_lip_open_ratio_range, metavar = create_float_metavar(processors_choices.face_editor_lip_open_ratio_range))
|
||||||
group_processors.add_argument('--face-editor-mouth-grim', help = wording.get('help.face_editor_mouth_grim'), type = float, default = config.get_float_value('processors.face_editor_mouth_grim', '0'), choices = processors_choices.face_editor_mouth_grim_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_grim_range))
|
group_processors.add_argument('--face-editor-mouth-grim', help = wording.get('help.face_editor_mouth_grim'), type = float, default = config.get_float_value('processors', 'face_editor_mouth_grim', '0'), choices = processors_choices.face_editor_mouth_grim_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_grim_range))
|
||||||
group_processors.add_argument('--face-editor-mouth-pout', help = wording.get('help.face_editor_mouth_pout'), type = float, default = config.get_float_value('processors.face_editor_mouth_pout', '0'), choices = processors_choices.face_editor_mouth_pout_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_pout_range))
|
group_processors.add_argument('--face-editor-mouth-pout', help = wording.get('help.face_editor_mouth_pout'), type = float, default = config.get_float_value('processors', 'face_editor_mouth_pout', '0'), choices = processors_choices.face_editor_mouth_pout_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_pout_range))
|
||||||
group_processors.add_argument('--face-editor-mouth-purse', help = wording.get('help.face_editor_mouth_purse'), type = float, default = config.get_float_value('processors.face_editor_mouth_purse', '0'), choices = processors_choices.face_editor_mouth_purse_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_purse_range))
|
group_processors.add_argument('--face-editor-mouth-purse', help = wording.get('help.face_editor_mouth_purse'), type = float, default = config.get_float_value('processors', 'face_editor_mouth_purse', '0'), choices = processors_choices.face_editor_mouth_purse_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_purse_range))
|
||||||
group_processors.add_argument('--face-editor-mouth-smile', help = wording.get('help.face_editor_mouth_smile'), type = float, default = config.get_float_value('processors.face_editor_mouth_smile', '0'), choices = processors_choices.face_editor_mouth_smile_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_smile_range))
|
group_processors.add_argument('--face-editor-mouth-smile', help = wording.get('help.face_editor_mouth_smile'), type = float, default = config.get_float_value('processors', 'face_editor_mouth_smile', '0'), choices = processors_choices.face_editor_mouth_smile_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_smile_range))
|
||||||
group_processors.add_argument('--face-editor-mouth-position-horizontal', help = wording.get('help.face_editor_mouth_position_horizontal'), type = float, default = config.get_float_value('processors.face_editor_mouth_position_horizontal', '0'), choices = processors_choices.face_editor_mouth_position_horizontal_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_position_horizontal_range))
|
group_processors.add_argument('--face-editor-mouth-position-horizontal', help = wording.get('help.face_editor_mouth_position_horizontal'), type = float, default = config.get_float_value('processors', 'face_editor_mouth_position_horizontal', '0'), choices = processors_choices.face_editor_mouth_position_horizontal_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_position_horizontal_range))
|
||||||
group_processors.add_argument('--face-editor-mouth-position-vertical', help = wording.get('help.face_editor_mouth_position_vertical'), type = float, default = config.get_float_value('processors.face_editor_mouth_position_vertical', '0'), choices = processors_choices.face_editor_mouth_position_vertical_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_position_vertical_range))
|
group_processors.add_argument('--face-editor-mouth-position-vertical', help = wording.get('help.face_editor_mouth_position_vertical'), type = float, default = config.get_float_value('processors', 'face_editor_mouth_position_vertical', '0'), choices = processors_choices.face_editor_mouth_position_vertical_range, metavar = create_float_metavar(processors_choices.face_editor_mouth_position_vertical_range))
|
||||||
group_processors.add_argument('--face-editor-head-pitch', help = wording.get('help.face_editor_head_pitch'), type = float, default = config.get_float_value('processors.face_editor_head_pitch', '0'), choices = processors_choices.face_editor_head_pitch_range, metavar = create_float_metavar(processors_choices.face_editor_head_pitch_range))
|
group_processors.add_argument('--face-editor-head-pitch', help = wording.get('help.face_editor_head_pitch'), type = float, default = config.get_float_value('processors', 'face_editor_head_pitch', '0'), choices = processors_choices.face_editor_head_pitch_range, metavar = create_float_metavar(processors_choices.face_editor_head_pitch_range))
|
||||||
group_processors.add_argument('--face-editor-head-yaw', help = wording.get('help.face_editor_head_yaw'), type = float, default = config.get_float_value('processors.face_editor_head_yaw', '0'), choices = processors_choices.face_editor_head_yaw_range, metavar = create_float_metavar(processors_choices.face_editor_head_yaw_range))
|
group_processors.add_argument('--face-editor-head-yaw', help = wording.get('help.face_editor_head_yaw'), type = float, default = config.get_float_value('processors', 'face_editor_head_yaw', '0'), choices = processors_choices.face_editor_head_yaw_range, metavar = create_float_metavar(processors_choices.face_editor_head_yaw_range))
|
||||||
group_processors.add_argument('--face-editor-head-roll', help = wording.get('help.face_editor_head_roll'), type = float, default = config.get_float_value('processors.face_editor_head_roll', '0'), choices = processors_choices.face_editor_head_roll_range, metavar = create_float_metavar(processors_choices.face_editor_head_roll_range))
|
group_processors.add_argument('--face-editor-head-roll', help = wording.get('help.face_editor_head_roll'), type = float, default = config.get_float_value('processors', 'face_editor_head_roll', '0'), choices = processors_choices.face_editor_head_roll_range, metavar = create_float_metavar(processors_choices.face_editor_head_roll_range))
|
||||||
facefusion.jobs.job_store.register_step_keys([ 'face_editor_model', 'face_editor_eyebrow_direction', 'face_editor_eye_gaze_horizontal', 'face_editor_eye_gaze_vertical', 'face_editor_eye_open_ratio', 'face_editor_lip_open_ratio', 'face_editor_mouth_grim', 'face_editor_mouth_pout', 'face_editor_mouth_purse', 'face_editor_mouth_smile', 'face_editor_mouth_position_horizontal', 'face_editor_mouth_position_vertical', 'face_editor_head_pitch', 'face_editor_head_yaw', 'face_editor_head_roll' ])
|
facefusion.jobs.job_store.register_step_keys([ 'face_editor_model', 'face_editor_eyebrow_direction', 'face_editor_eye_gaze_horizontal', 'face_editor_eye_gaze_vertical', 'face_editor_eye_open_ratio', 'face_editor_lip_open_ratio', 'face_editor_mouth_grim', 'face_editor_mouth_pout', 'face_editor_mouth_purse', 'face_editor_mouth_smile', 'face_editor_mouth_position_horizontal', 'face_editor_mouth_position_vertical', 'face_editor_head_pitch', 'face_editor_head_yaw', 'face_editor_head_roll' ])
|
||||||
|
|
||||||
|
|
||||||
@@ -156,11 +161,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set = get_model_options().get('hashes')
|
||||||
model_hashes = get_model_options().get('hashes')
|
model_source_set = get_model_options().get('sources')
|
||||||
model_sources = get_model_options().get('sources')
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def pre_process(mode : ProcessMode) -> bool:
|
def pre_process(mode : ProcessMode) -> bool:
|
||||||
@@ -170,7 +174,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
|||||||
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
if mode == 'output' and not same_file_extension([ state_manager.get_item('target_path'), state_manager.get_item('output_path') ]):
|
if mode == 'output' and not same_file_extension(state_manager.get_item('target_path'), state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@@ -359,7 +363,7 @@ def edit_lip_open(motion_points : LivePortraitMotionPoints, face_landmark_68 : F
|
|||||||
else:
|
else:
|
||||||
lip_motion_points = numpy.concatenate([ motion_points.ravel(), [ lip_ratio, 1.0 ] ])
|
lip_motion_points = numpy.concatenate([ motion_points.ravel(), [ lip_ratio, 1.0 ] ])
|
||||||
lip_motion_points = lip_motion_points.reshape(1, -1).astype(numpy.float32)
|
lip_motion_points = lip_motion_points.reshape(1, -1).astype(numpy.float32)
|
||||||
lip_motion_points = forward_retarget_lip(lip_motion_points) * numpy.abs(face_editor_lip_open_ratio)
|
lip_motion_points = forward_retarget_lip(lip_motion_points) * numpy.abs(face_editor_lip_open_ratio)
|
||||||
lip_motion_points = lip_motion_points.reshape(-1, 21, 3)
|
lip_motion_points = lip_motion_points.reshape(-1, 21, 3)
|
||||||
return lip_motion_points
|
return lip_motion_points
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from functools import lru_cache
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
@@ -8,8 +9,8 @@ import facefusion.jobs.job_manager
|
|||||||
import facefusion.jobs.job_store
|
import facefusion.jobs.job_store
|
||||||
import facefusion.processors.core as processors
|
import facefusion.processors.core as processors
|
||||||
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, wording
|
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, wording
|
||||||
from facefusion.common_helper import create_int_metavar
|
from facefusion.common_helper import create_float_metavar, create_int_metavar
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
from facefusion.face_analyser import get_many_faces, get_one_face
|
from facefusion.face_analyser import get_many_faces, get_one_face
|
||||||
from facefusion.face_helper import paste_back, warp_face_by_face_landmark_5
|
from facefusion.face_helper import paste_back, warp_face_by_face_landmark_5
|
||||||
from facefusion.face_masker import create_occlusion_mask, create_static_box_mask
|
from facefusion.face_masker import create_occlusion_mask, create_static_box_mask
|
||||||
@@ -17,241 +18,246 @@ from facefusion.face_selector import find_similar_faces, sort_and_filter_faces
|
|||||||
from facefusion.face_store import get_reference_faces
|
from facefusion.face_store import get_reference_faces
|
||||||
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.typing import FaceEnhancerInputs
|
from facefusion.processors.types import FaceEnhancerInputs, FaceEnhancerWeight
|
||||||
from facefusion.program_helper import find_argument_group
|
from facefusion.program_helper import find_argument_group
|
||||||
from facefusion.thread_helper import thread_semaphore
|
from facefusion.thread_helper import thread_semaphore
|
||||||
from facefusion.typing import ApplyStateItem, Args, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
from facefusion.types import ApplyStateItem, Args, DownloadScope, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
||||||
from facefusion.vision import read_image, read_static_image, write_image
|
from facefusion.vision import read_image, read_static_image, write_image
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'codeformer':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'codeformer':
|
||||||
{
|
{
|
||||||
'face_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/codeformer.hash',
|
'face_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/codeformer.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'codeformer.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/codeformer.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'codeformer.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/codeformer.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'template': 'ffhq_512',
|
||||||
|
'size': (512, 512)
|
||||||
},
|
},
|
||||||
'sources':
|
'gfpgan_1.2':
|
||||||
{
|
{
|
||||||
'face_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/codeformer.onnx',
|
'face_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/codeformer.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'gfpgan_1.2.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gfpgan_1.2.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'gfpgan_1.2.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gfpgan_1.2.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'template': 'ffhq_512',
|
||||||
|
'size': (512, 512)
|
||||||
},
|
},
|
||||||
'template': 'ffhq_512',
|
'gfpgan_1.3':
|
||||||
'size': (512, 512)
|
|
||||||
},
|
|
||||||
'gfpgan_1.2':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'face_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gfpgan_1.2.hash',
|
'face_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/gfpgan_1.2.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'gfpgan_1.3.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gfpgan_1.3.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'gfpgan_1.3.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gfpgan_1.3.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'template': 'ffhq_512',
|
||||||
|
'size': (512, 512)
|
||||||
},
|
},
|
||||||
'sources':
|
'gfpgan_1.4':
|
||||||
{
|
{
|
||||||
'face_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gfpgan_1.2.onnx',
|
'face_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/gfpgan_1.2.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'gfpgan_1.4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gfpgan_1.4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'gfpgan_1.4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gfpgan_1.4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'template': 'ffhq_512',
|
||||||
|
'size': (512, 512)
|
||||||
},
|
},
|
||||||
'template': 'ffhq_512',
|
'gpen_bfr_256':
|
||||||
'size': (512, 512)
|
|
||||||
},
|
|
||||||
'gfpgan_1.3':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'face_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gfpgan_1.3.hash',
|
'face_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/gfpgan_1.3.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'gpen_bfr_256.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gpen_bfr_256.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'gpen_bfr_256.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gpen_bfr_256.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'template': 'arcface_128',
|
||||||
|
'size': (256, 256)
|
||||||
},
|
},
|
||||||
'sources':
|
'gpen_bfr_512':
|
||||||
{
|
{
|
||||||
'face_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gfpgan_1.3.onnx',
|
'face_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/gfpgan_1.3.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'gpen_bfr_512.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gpen_bfr_512.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'gpen_bfr_512.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gpen_bfr_512.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'template': 'ffhq_512',
|
||||||
|
'size': (512, 512)
|
||||||
},
|
},
|
||||||
'template': 'ffhq_512',
|
'gpen_bfr_1024':
|
||||||
'size': (512, 512)
|
|
||||||
},
|
|
||||||
'gfpgan_1.4':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'face_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gfpgan_1.4.hash',
|
'face_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/gfpgan_1.4.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'gpen_bfr_1024.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gpen_bfr_1024.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'gpen_bfr_1024.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gpen_bfr_1024.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'template': 'ffhq_512',
|
||||||
|
'size': (1024, 1024)
|
||||||
},
|
},
|
||||||
'sources':
|
'gpen_bfr_2048':
|
||||||
{
|
{
|
||||||
'face_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gfpgan_1.4.onnx',
|
'face_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/gfpgan_1.4.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'gpen_bfr_2048.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gpen_bfr_2048.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'gpen_bfr_2048.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/gpen_bfr_2048.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'template': 'ffhq_512',
|
||||||
|
'size': (2048, 2048)
|
||||||
},
|
},
|
||||||
'template': 'ffhq_512',
|
'restoreformer_plus_plus':
|
||||||
'size': (512, 512)
|
|
||||||
},
|
|
||||||
'gpen_bfr_256':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'face_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gpen_bfr_256.hash',
|
'face_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/gpen_bfr_256.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'restoreformer_plus_plus.hash'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/restoreformer_plus_plus.hash')
|
||||||
'sources':
|
}
|
||||||
{
|
},
|
||||||
'face_enhancer':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gpen_bfr_256.onnx',
|
'face_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/gpen_bfr_256.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'restoreformer_plus_plus.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/restoreformer_plus_plus.onnx')
|
||||||
'template': 'arcface_128_v2',
|
}
|
||||||
'size': (256, 256)
|
},
|
||||||
},
|
'template': 'ffhq_512',
|
||||||
'gpen_bfr_512':
|
'size': (512, 512)
|
||||||
{
|
}
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'face_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gpen_bfr_512.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/gpen_bfr_512.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'face_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gpen_bfr_512.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/gpen_bfr_512.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'template': 'ffhq_512',
|
|
||||||
'size': (512, 512)
|
|
||||||
},
|
|
||||||
'gpen_bfr_1024':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'face_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gpen_bfr_1024.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/gpen_bfr_1024.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'face_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gpen_bfr_1024.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/gpen_bfr_1024.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'template': 'ffhq_512',
|
|
||||||
'size': (1024, 1024)
|
|
||||||
},
|
|
||||||
'gpen_bfr_2048':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'face_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gpen_bfr_2048.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/gpen_bfr_2048.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'face_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/gpen_bfr_2048.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/gpen_bfr_2048.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'template': 'ffhq_512',
|
|
||||||
'size': (2048, 2048)
|
|
||||||
},
|
|
||||||
'restoreformer_plus_plus':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'face_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/restoreformer_plus_plus.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/restoreformer_plus_plus.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'face_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/restoreformer_plus_plus.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/restoreformer_plus_plus.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'template': 'ffhq_512',
|
|
||||||
'size': (512, 512)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
model_sources = get_model_options().get('sources')
|
model_names = [ state_manager.get_item('face_enhancer_model') ]
|
||||||
model_context = __name__ + '.' + state_manager.get_item('face_enhancer_model')
|
model_source_set = get_model_options().get('sources')
|
||||||
return inference_manager.get_inference_pool(model_context, model_sources)
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
model_context = __name__ + '.' + state_manager.get_item('face_enhancer_model')
|
model_names = [ state_manager.get_item('face_enhancer_model') ]
|
||||||
inference_manager.clear_inference_pool(model_context)
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def get_model_options() -> ModelOptions:
|
def get_model_options() -> ModelOptions:
|
||||||
face_enhancer_model = state_manager.get_item('face_enhancer_model')
|
model_name = state_manager.get_item('face_enhancer_model')
|
||||||
return MODEL_SET.get(face_enhancer_model)
|
return create_static_model_set('full').get(model_name)
|
||||||
|
|
||||||
|
|
||||||
def register_args(program : ArgumentParser) -> None:
|
def register_args(program : ArgumentParser) -> None:
|
||||||
group_processors = find_argument_group(program, 'processors')
|
group_processors = find_argument_group(program, 'processors')
|
||||||
if group_processors:
|
if group_processors:
|
||||||
group_processors.add_argument('--face-enhancer-model', help = wording.get('help.face_enhancer_model'), default = config.get_str_value('processors.face_enhancer_model', 'gfpgan_1.4'), choices = processors_choices.face_enhancer_models)
|
group_processors.add_argument('--face-enhancer-model', help = wording.get('help.face_enhancer_model'), default = config.get_str_value('processors', 'face_enhancer_model', 'gfpgan_1.4'), choices = processors_choices.face_enhancer_models)
|
||||||
group_processors.add_argument('--face-enhancer-blend', help = wording.get('help.face_enhancer_blend'), type = int, default = config.get_int_value('processors.face_enhancer_blend', '80'), choices = processors_choices.face_enhancer_blend_range, metavar = create_int_metavar(processors_choices.face_enhancer_blend_range))
|
group_processors.add_argument('--face-enhancer-blend', help = wording.get('help.face_enhancer_blend'), type = int, default = config.get_int_value('processors', 'face_enhancer_blend', '80'), choices = processors_choices.face_enhancer_blend_range, metavar = create_int_metavar(processors_choices.face_enhancer_blend_range))
|
||||||
facefusion.jobs.job_store.register_step_keys([ 'face_enhancer_model', 'face_enhancer_blend' ])
|
group_processors.add_argument('--face-enhancer-weight', help = wording.get('help.face_enhancer_weight'), type = float, default = config.get_float_value('processors', 'face_enhancer_weight', '1.0'), choices = processors_choices.face_enhancer_weight_range, metavar = create_float_metavar(processors_choices.face_enhancer_weight_range))
|
||||||
|
facefusion.jobs.job_store.register_step_keys([ 'face_enhancer_model', 'face_enhancer_blend', 'face_enhancer_weight' ])
|
||||||
|
|
||||||
|
|
||||||
def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
||||||
apply_state_item('face_enhancer_model', args.get('face_enhancer_model'))
|
apply_state_item('face_enhancer_model', args.get('face_enhancer_model'))
|
||||||
apply_state_item('face_enhancer_blend', args.get('face_enhancer_blend'))
|
apply_state_item('face_enhancer_blend', args.get('face_enhancer_blend'))
|
||||||
|
apply_state_item('face_enhancer_weight', args.get('face_enhancer_weight'))
|
||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set = get_model_options().get('hashes')
|
||||||
model_hashes = get_model_options().get('hashes')
|
model_source_set = get_model_options().get('sources')
|
||||||
model_sources = get_model_options().get('sources')
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def pre_process(mode : ProcessMode) -> bool:
|
def pre_process(mode : ProcessMode) -> bool:
|
||||||
@@ -261,7 +267,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
|||||||
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
if mode == 'output' and not same_file_extension([ state_manager.get_item('target_path'), state_manager.get_item('output_path') ]):
|
if mode == 'output' and not same_file_extension(state_manager.get_item('target_path'), state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@@ -295,7 +301,8 @@ def enhance_face(target_face : Face, temp_vision_frame : VisionFrame) -> VisionF
|
|||||||
crop_masks.append(occlusion_mask)
|
crop_masks.append(occlusion_mask)
|
||||||
|
|
||||||
crop_vision_frame = prepare_crop_frame(crop_vision_frame)
|
crop_vision_frame = prepare_crop_frame(crop_vision_frame)
|
||||||
crop_vision_frame = forward(crop_vision_frame)
|
face_enhancer_weight = numpy.array([ state_manager.get_item('face_enhancer_weight') ]).astype(numpy.double)
|
||||||
|
crop_vision_frame = forward(crop_vision_frame, face_enhancer_weight)
|
||||||
crop_vision_frame = normalize_crop_frame(crop_vision_frame)
|
crop_vision_frame = normalize_crop_frame(crop_vision_frame)
|
||||||
crop_mask = numpy.minimum.reduce(crop_masks).clip(0, 1)
|
crop_mask = numpy.minimum.reduce(crop_masks).clip(0, 1)
|
||||||
paste_vision_frame = paste_back(temp_vision_frame, crop_vision_frame, crop_mask, affine_matrix)
|
paste_vision_frame = paste_back(temp_vision_frame, crop_vision_frame, crop_mask, affine_matrix)
|
||||||
@@ -303,7 +310,7 @@ def enhance_face(target_face : Face, temp_vision_frame : VisionFrame) -> VisionF
|
|||||||
return temp_vision_frame
|
return temp_vision_frame
|
||||||
|
|
||||||
|
|
||||||
def forward(crop_vision_frame : VisionFrame) -> VisionFrame:
|
def forward(crop_vision_frame : VisionFrame, face_enhancer_weight : FaceEnhancerWeight) -> VisionFrame:
|
||||||
face_enhancer = get_inference_pool().get('face_enhancer')
|
face_enhancer = get_inference_pool().get('face_enhancer')
|
||||||
face_enhancer_inputs = {}
|
face_enhancer_inputs = {}
|
||||||
|
|
||||||
@@ -311,8 +318,7 @@ def forward(crop_vision_frame : VisionFrame) -> VisionFrame:
|
|||||||
if face_enhancer_input.name == 'input':
|
if face_enhancer_input.name == 'input':
|
||||||
face_enhancer_inputs[face_enhancer_input.name] = crop_vision_frame
|
face_enhancer_inputs[face_enhancer_input.name] = crop_vision_frame
|
||||||
if face_enhancer_input.name == 'weight':
|
if face_enhancer_input.name == 'weight':
|
||||||
weight = numpy.array([ 1 ]).astype(numpy.double)
|
face_enhancer_inputs[face_enhancer_input.name] = face_enhancer_weight
|
||||||
face_enhancer_inputs[face_enhancer_input.name] = weight
|
|
||||||
|
|
||||||
with thread_semaphore():
|
with thread_semaphore():
|
||||||
crop_vision_frame = face_enhancer.run(None, face_enhancer_inputs)[0][0]
|
crop_vision_frame = face_enhancer.run(None, face_enhancer_inputs)[0][0]
|
||||||
@@ -320,6 +326,16 @@ def forward(crop_vision_frame : VisionFrame) -> VisionFrame:
|
|||||||
return crop_vision_frame
|
return crop_vision_frame
|
||||||
|
|
||||||
|
|
||||||
|
def has_weight_input() -> bool:
|
||||||
|
face_enhancer = get_inference_pool().get('face_enhancer')
|
||||||
|
|
||||||
|
for deep_swapper_input in face_enhancer.get_inputs():
|
||||||
|
if deep_swapper_input.name == 'weight':
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def prepare_crop_frame(crop_vision_frame : VisionFrame) -> VisionFrame:
|
def prepare_crop_frame(crop_vision_frame : VisionFrame) -> VisionFrame:
|
||||||
crop_vision_frame = crop_vision_frame[:, :, ::-1] / 255.0
|
crop_vision_frame = crop_vision_frame[:, :, ::-1] / 255.0
|
||||||
crop_vision_frame = (crop_vision_frame - 0.5) / 0.5
|
crop_vision_frame = (crop_vision_frame - 0.5) / 0.5
|
||||||
|
|||||||
@@ -1,324 +1,372 @@
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from functools import lru_cache
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
|
import facefusion.choices
|
||||||
import facefusion.jobs.job_manager
|
import facefusion.jobs.job_manager
|
||||||
import facefusion.jobs.job_store
|
import facefusion.jobs.job_store
|
||||||
import facefusion.processors.core as processors
|
import facefusion.processors.core as processors
|
||||||
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, wording
|
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, wording
|
||||||
from facefusion.common_helper import get_first
|
from facefusion.common_helper import get_first
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
from facefusion.execution import has_execution_provider
|
from facefusion.execution import has_execution_provider
|
||||||
from facefusion.face_analyser import get_average_face, get_many_faces, get_one_face
|
from facefusion.face_analyser import get_average_face, get_many_faces, get_one_face
|
||||||
from facefusion.face_helper import paste_back, warp_face_by_face_landmark_5
|
from facefusion.face_helper import paste_back, warp_face_by_face_landmark_5
|
||||||
from facefusion.face_masker import create_occlusion_mask, create_region_mask, create_static_box_mask
|
from facefusion.face_masker import create_occlusion_mask, create_region_mask, create_static_box_mask
|
||||||
from facefusion.face_selector import find_similar_faces, sort_and_filter_faces
|
from facefusion.face_selector import find_similar_faces, sort_and_filter_faces, sort_faces_by_order
|
||||||
from facefusion.face_store import get_reference_faces
|
from facefusion.face_store import get_reference_faces
|
||||||
from facefusion.filesystem import filter_image_paths, has_image, in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
from facefusion.filesystem import filter_image_paths, has_image, in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
||||||
from facefusion.inference_manager import get_static_model_initializer
|
from facefusion.model_helper import get_static_model_initializer
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.pixel_boost import explode_pixel_boost, implode_pixel_boost
|
from facefusion.processors.pixel_boost import explode_pixel_boost, implode_pixel_boost
|
||||||
from facefusion.processors.typing import FaceSwapperInputs
|
from facefusion.processors.types import FaceSwapperInputs
|
||||||
from facefusion.program_helper import find_argument_group, suggest_face_swapper_pixel_boost_choices
|
from facefusion.program_helper import find_argument_group
|
||||||
from facefusion.thread_helper import conditional_thread_semaphore
|
from facefusion.thread_helper import conditional_thread_semaphore
|
||||||
from facefusion.typing import ApplyStateItem, Args, Embedding, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
from facefusion.types import ApplyStateItem, Args, DownloadScope, Embedding, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
||||||
from facefusion.vision import read_image, read_static_image, read_static_images, unpack_resolution, write_image
|
from facefusion.vision import read_image, read_static_image, read_static_images, unpack_resolution, write_image
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'blendswap_256':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'blendswap_256':
|
||||||
{
|
{
|
||||||
'face_swapper':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/blendswap_256.hash',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/blendswap_256.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'blendswap_256.hash'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/blendswap_256.hash')
|
||||||
'sources':
|
}
|
||||||
{
|
|
||||||
'face_swapper':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/blendswap_256.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/blendswap_256.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'type': 'blendswap',
|
|
||||||
'template': 'ffhq_512',
|
|
||||||
'size': (256, 256),
|
|
||||||
'mean': [ 0.0, 0.0, 0.0 ],
|
|
||||||
'standard_deviation': [ 1.0, 1.0, 1.0 ]
|
|
||||||
},
|
|
||||||
'ghost_1_256':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'face_swapper':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ghost_1_256.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/ghost_1_256.hash')
|
|
||||||
},
|
},
|
||||||
'embedding_converter':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_converter_ghost.hash',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'blendswap_256.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/blendswap_256.onnx')
|
||||||
'sources':
|
}
|
||||||
{
|
|
||||||
'face_swapper':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ghost_1_256.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/ghost_1_256.onnx')
|
|
||||||
},
|
},
|
||||||
'embedding_converter':
|
'type': 'blendswap',
|
||||||
{
|
'template': 'ffhq_512',
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_converter_ghost.onnx',
|
'size': (256, 256),
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.onnx')
|
'mean': [ 0.0, 0.0, 0.0 ],
|
||||||
}
|
'standard_deviation': [ 1.0, 1.0, 1.0 ]
|
||||||
},
|
},
|
||||||
'type': 'ghost',
|
'ghost_1_256':
|
||||||
'template': 'arcface_112_v1',
|
|
||||||
'size': (256, 256),
|
|
||||||
'mean': [ 0.5, 0.5, 0.5 ],
|
|
||||||
'standard_deviation': [ 0.5, 0.5, 0.5 ]
|
|
||||||
},
|
|
||||||
'ghost_2_256':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'face_swapper':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ghost_2_256.hash',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/ghost_2_256.hash')
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'ghost_1_256.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/ghost_1_256.hash')
|
||||||
|
},
|
||||||
|
'embedding_converter':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'arcface_converter_ghost.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.hash')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'embedding_converter':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_converter_ghost.hash',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'ghost_1_256.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/ghost_1_256.onnx')
|
||||||
'sources':
|
},
|
||||||
{
|
'embedding_converter':
|
||||||
'face_swapper':
|
{
|
||||||
{
|
'url': resolve_download_url('models-3.0.0', 'arcface_converter_ghost.onnx'),
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ghost_2_256.onnx',
|
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.onnx')
|
||||||
'path': resolve_relative_path('../.assets/models/ghost_2_256.onnx')
|
}
|
||||||
},
|
},
|
||||||
'embedding_converter':
|
'type': 'ghost',
|
||||||
{
|
'template': 'arcface_112_v1',
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_converter_ghost.onnx',
|
'size': (256, 256),
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.onnx')
|
'mean': [ 0.5, 0.5, 0.5 ],
|
||||||
}
|
'standard_deviation': [ 0.5, 0.5, 0.5 ]
|
||||||
},
|
},
|
||||||
'type': 'ghost',
|
'ghost_2_256':
|
||||||
'template': 'arcface_112_v1',
|
|
||||||
'size': (256, 256),
|
|
||||||
'mean': [ 0.5, 0.5, 0.5 ],
|
|
||||||
'standard_deviation': [ 0.5, 0.5, 0.5 ]
|
|
||||||
},
|
|
||||||
'ghost_3_256':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'face_swapper':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ghost_3_256.hash',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/ghost_3_256.hash')
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'ghost_2_256.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/ghost_2_256.hash')
|
||||||
|
},
|
||||||
|
'embedding_converter':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'arcface_converter_ghost.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.hash')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'embedding_converter':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_converter_ghost.hash',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'ghost_2_256.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/ghost_2_256.onnx')
|
||||||
'sources':
|
},
|
||||||
{
|
'embedding_converter':
|
||||||
'face_swapper':
|
{
|
||||||
{
|
'url': resolve_download_url('models-3.0.0', 'arcface_converter_ghost.onnx'),
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ghost_3_256.onnx',
|
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.onnx')
|
||||||
'path': resolve_relative_path('../.assets/models/ghost_3_256.onnx')
|
}
|
||||||
},
|
},
|
||||||
'embedding_converter':
|
'type': 'ghost',
|
||||||
{
|
'template': 'arcface_112_v1',
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_converter_ghost.onnx',
|
'size': (256, 256),
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.onnx')
|
'mean': [ 0.5, 0.5, 0.5 ],
|
||||||
}
|
'standard_deviation': [ 0.5, 0.5, 0.5 ]
|
||||||
},
|
},
|
||||||
'type': 'ghost',
|
'ghost_3_256':
|
||||||
'template': 'arcface_112_v1',
|
|
||||||
'size': (256, 256),
|
|
||||||
'mean': [ 0.5, 0.5, 0.5 ],
|
|
||||||
'standard_deviation': [ 0.5, 0.5, 0.5 ]
|
|
||||||
},
|
|
||||||
'inswapper_128':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'face_swapper':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/inswapper_128.hash',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/inswapper_128.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'ghost_3_256.hash'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/ghost_3_256.hash')
|
||||||
'sources':
|
},
|
||||||
{
|
'embedding_converter':
|
||||||
'face_swapper':
|
{
|
||||||
{
|
'url': resolve_download_url('models-3.0.0', 'arcface_converter_ghost.hash'),
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/inswapper_128.onnx',
|
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.hash')
|
||||||
'path': resolve_relative_path('../.assets/models/inswapper_128.onnx')
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
'type': 'inswapper',
|
|
||||||
'template': 'arcface_128_v2',
|
|
||||||
'size': (128, 128),
|
|
||||||
'mean': [ 0.0, 0.0, 0.0 ],
|
|
||||||
'standard_deviation': [ 1.0, 1.0, 1.0 ]
|
|
||||||
},
|
|
||||||
'inswapper_128_fp16':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'face_swapper':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/inswapper_128_fp16.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/inswapper_128_fp16.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'face_swapper':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/inswapper_128_fp16.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/inswapper_128_fp16.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'type': 'inswapper',
|
|
||||||
'template': 'arcface_128_v2',
|
|
||||||
'size': (128, 128),
|
|
||||||
'mean': [ 0.0, 0.0, 0.0 ],
|
|
||||||
'standard_deviation': [ 1.0, 1.0, 1.0 ]
|
|
||||||
},
|
|
||||||
'simswap_256':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'face_swapper':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/simswap_256.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/simswap_256.hash')
|
|
||||||
},
|
},
|
||||||
'embedding_converter':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_converter_simswap.hash',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_converter_simswap.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'ghost_3_256.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/ghost_3_256.onnx')
|
||||||
'sources':
|
},
|
||||||
{
|
'embedding_converter':
|
||||||
'face_swapper':
|
{
|
||||||
{
|
'url': resolve_download_url('models-3.0.0', 'arcface_converter_ghost.onnx'),
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/simswap_256.onnx',
|
'path': resolve_relative_path('../.assets/models/arcface_converter_ghost.onnx')
|
||||||
'path': resolve_relative_path('../.assets/models/simswap_256.onnx')
|
}
|
||||||
},
|
},
|
||||||
'embedding_converter':
|
'type': 'ghost',
|
||||||
{
|
'template': 'arcface_112_v1',
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_converter_simswap.onnx',
|
'size': (256, 256),
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_converter_simswap.onnx')
|
'mean': [ 0.5, 0.5, 0.5 ],
|
||||||
}
|
'standard_deviation': [ 0.5, 0.5, 0.5 ]
|
||||||
},
|
},
|
||||||
'type': 'simswap',
|
'hififace_unofficial_256':
|
||||||
'template': 'arcface_112_v1',
|
|
||||||
'size': (256, 256),
|
|
||||||
'mean': [ 0.485, 0.456, 0.406 ],
|
|
||||||
'standard_deviation': [ 0.229, 0.224, 0.225 ]
|
|
||||||
},
|
|
||||||
'simswap_unofficial_512':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'face_swapper':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/simswap_unofficial_512.hash',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/simswap_unofficial_512.hash')
|
{
|
||||||
|
'url': resolve_download_url('models-3.1.0', 'hififace_unofficial_256.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/hififace_unofficial_256.hash')
|
||||||
|
},
|
||||||
|
'embedding_converter':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.1.0', 'arcface_converter_hififace.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/arcface_converter_hififace.hash')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'embedding_converter':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_converter_simswap.hash',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_converter_simswap.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.1.0', 'hififace_unofficial_256.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/hififace_unofficial_256.onnx')
|
||||||
'sources':
|
},
|
||||||
{
|
'embedding_converter':
|
||||||
'face_swapper':
|
{
|
||||||
{
|
'url': resolve_download_url('models-3.1.0', 'arcface_converter_hififace.onnx'),
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/simswap_unofficial_512.onnx',
|
'path': resolve_relative_path('../.assets/models/arcface_converter_hififace.onnx')
|
||||||
'path': resolve_relative_path('../.assets/models/simswap_unofficial_512.onnx')
|
}
|
||||||
},
|
},
|
||||||
'embedding_converter':
|
'type': 'hififace',
|
||||||
{
|
'template': 'mtcnn_512',
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/arcface_converter_simswap.onnx',
|
'size': (256, 256),
|
||||||
'path': resolve_relative_path('../.assets/models/arcface_converter_simswap.onnx')
|
'mean': [ 0.5, 0.5, 0.5 ],
|
||||||
}
|
'standard_deviation': [ 0.5, 0.5, 0.5 ]
|
||||||
},
|
},
|
||||||
'type': 'simswap',
|
'inswapper_128':
|
||||||
'template': 'arcface_112_v1',
|
|
||||||
'size': (512, 512),
|
|
||||||
'mean': [ 0.0, 0.0, 0.0 ],
|
|
||||||
'standard_deviation': [ 1.0, 1.0, 1.0 ]
|
|
||||||
},
|
|
||||||
'uniface_256':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'face_swapper':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/uniface_256.hash',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/uniface_256.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'inswapper_128.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/inswapper_128.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_swapper':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'inswapper_128.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/inswapper_128.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'type': 'inswapper',
|
||||||
|
'template': 'arcface_128',
|
||||||
|
'size': (128, 128),
|
||||||
|
'mean': [ 0.0, 0.0, 0.0 ],
|
||||||
|
'standard_deviation': [ 1.0, 1.0, 1.0 ]
|
||||||
},
|
},
|
||||||
'sources':
|
'inswapper_128_fp16':
|
||||||
{
|
{
|
||||||
'face_swapper':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/uniface_256.onnx',
|
'face_swapper':
|
||||||
'path': resolve_relative_path('../.assets/models/uniface_256.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'inswapper_128_fp16.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/inswapper_128_fp16.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_swapper':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'inswapper_128_fp16.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/inswapper_128_fp16.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'type': 'inswapper',
|
||||||
|
'template': 'arcface_128',
|
||||||
|
'size': (128, 128),
|
||||||
|
'mean': [ 0.0, 0.0, 0.0 ],
|
||||||
|
'standard_deviation': [ 1.0, 1.0, 1.0 ]
|
||||||
},
|
},
|
||||||
'type': 'uniface',
|
'simswap_256':
|
||||||
'template': 'ffhq_512',
|
{
|
||||||
'size': (256, 256),
|
'hashes':
|
||||||
'mean': [ 0.5, 0.5, 0.5 ],
|
{
|
||||||
'standard_deviation': [ 0.5, 0.5, 0.5 ]
|
'face_swapper':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'simswap_256.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/simswap_256.hash')
|
||||||
|
},
|
||||||
|
'embedding_converter':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'arcface_converter_simswap.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/arcface_converter_simswap.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_swapper':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'simswap_256.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/simswap_256.onnx')
|
||||||
|
},
|
||||||
|
'embedding_converter':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'arcface_converter_simswap.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/arcface_converter_simswap.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'type': 'simswap',
|
||||||
|
'template': 'arcface_112_v1',
|
||||||
|
'size': (256, 256),
|
||||||
|
'mean': [ 0.485, 0.456, 0.406 ],
|
||||||
|
'standard_deviation': [ 0.229, 0.224, 0.225 ]
|
||||||
|
},
|
||||||
|
'simswap_unofficial_512':
|
||||||
|
{
|
||||||
|
'hashes':
|
||||||
|
{
|
||||||
|
'face_swapper':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'simswap_unofficial_512.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/simswap_unofficial_512.hash')
|
||||||
|
},
|
||||||
|
'embedding_converter':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'arcface_converter_simswap.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/arcface_converter_simswap.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_swapper':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'simswap_unofficial_512.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/simswap_unofficial_512.onnx')
|
||||||
|
},
|
||||||
|
'embedding_converter':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'arcface_converter_simswap.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/arcface_converter_simswap.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'type': 'simswap',
|
||||||
|
'template': 'arcface_112_v1',
|
||||||
|
'size': (512, 512),
|
||||||
|
'mean': [ 0.0, 0.0, 0.0 ],
|
||||||
|
'standard_deviation': [ 1.0, 1.0, 1.0 ]
|
||||||
|
},
|
||||||
|
'uniface_256':
|
||||||
|
{
|
||||||
|
'hashes':
|
||||||
|
{
|
||||||
|
'face_swapper':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'uniface_256.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/uniface_256.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'face_swapper':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'uniface_256.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/uniface_256.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'type': 'uniface',
|
||||||
|
'template': 'ffhq_512',
|
||||||
|
'size': (256, 256),
|
||||||
|
'mean': [ 0.5, 0.5, 0.5 ],
|
||||||
|
'standard_deviation': [ 0.5, 0.5, 0.5 ]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
model_sources = get_model_options().get('sources')
|
model_names = [ get_model_name() ]
|
||||||
model_context = __name__ + '.' + state_manager.get_item('face_swapper_model')
|
model_source_set = get_model_options().get('sources')
|
||||||
return inference_manager.get_inference_pool(model_context, model_sources)
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
model_context = __name__ + '.' + state_manager.get_item('face_swapper_model')
|
model_names = [ get_model_name() ]
|
||||||
inference_manager.clear_inference_pool(model_context)
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def get_model_options() -> ModelOptions:
|
def get_model_options() -> ModelOptions:
|
||||||
face_swapper_model = state_manager.get_item('face_swapper_model')
|
model_name = get_model_name()
|
||||||
face_swapper_model = 'inswapper_128' if has_execution_provider('coreml') and face_swapper_model == 'inswapper_128_fp16' else face_swapper_model
|
return create_static_model_set('full').get(model_name)
|
||||||
return MODEL_SET.get(face_swapper_model)
|
|
||||||
|
|
||||||
|
def get_model_name() -> str:
|
||||||
|
model_name = state_manager.get_item('face_swapper_model')
|
||||||
|
|
||||||
|
if has_execution_provider('coreml') and model_name == 'inswapper_128_fp16':
|
||||||
|
return 'inswapper_128'
|
||||||
|
return model_name
|
||||||
|
|
||||||
|
|
||||||
def register_args(program : ArgumentParser) -> None:
|
def register_args(program : ArgumentParser) -> None:
|
||||||
group_processors = find_argument_group(program, 'processors')
|
group_processors = find_argument_group(program, 'processors')
|
||||||
if group_processors:
|
if group_processors:
|
||||||
group_processors.add_argument('--face-swapper-model', help = wording.get('help.face_swapper_model'), default = config.get_str_value('processors.face_swapper_model', 'inswapper_128_fp16'), choices = processors_choices.face_swapper_set.keys())
|
group_processors.add_argument('--face-swapper-model', help = wording.get('help.face_swapper_model'), default = config.get_str_value('processors', 'face_swapper_model', 'inswapper_128_fp16'), choices = processors_choices.face_swapper_models)
|
||||||
face_swapper_pixel_boost_choices = suggest_face_swapper_pixel_boost_choices(program)
|
known_args, _ = program.parse_known_args()
|
||||||
group_processors.add_argument('--face-swapper-pixel-boost', help = wording.get('help.face_swapper_pixel_boost'), default = config.get_str_value('processors.face_swapper_pixel_boost', get_first(face_swapper_pixel_boost_choices)), choices = face_swapper_pixel_boost_choices)
|
face_swapper_pixel_boost_choices = processors_choices.face_swapper_set.get(known_args.face_swapper_model)
|
||||||
|
group_processors.add_argument('--face-swapper-pixel-boost', help = wording.get('help.face_swapper_pixel_boost'), default = config.get_str_value('processors', 'face_swapper_pixel_boost', get_first(face_swapper_pixel_boost_choices)), choices = face_swapper_pixel_boost_choices)
|
||||||
facefusion.jobs.job_store.register_step_keys([ 'face_swapper_model', 'face_swapper_pixel_boost' ])
|
facefusion.jobs.job_store.register_step_keys([ 'face_swapper_model', 'face_swapper_pixel_boost' ])
|
||||||
|
|
||||||
|
|
||||||
@@ -328,11 +376,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set = get_model_options().get('hashes')
|
||||||
model_hashes = get_model_options().get('hashes')
|
model_source_set = get_model_options().get('sources')
|
||||||
model_sources = get_model_options().get('sources')
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def pre_process(mode : ProcessMode) -> bool:
|
def pre_process(mode : ProcessMode) -> bool:
|
||||||
@@ -351,7 +398,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
|||||||
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
if mode == 'output' and not same_file_extension([ state_manager.get_item('target_path'), state_manager.get_item('output_path') ]):
|
if mode == 'output' and not same_file_extension(state_manager.get_item('target_path'), state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@@ -410,9 +457,12 @@ def forward_swap_face(source_face : Face, crop_vision_frame : VisionFrame) -> Vi
|
|||||||
model_type = get_model_options().get('type')
|
model_type = get_model_options().get('type')
|
||||||
face_swapper_inputs = {}
|
face_swapper_inputs = {}
|
||||||
|
|
||||||
|
if has_execution_provider('coreml') and model_type in [ 'ghost', 'uniface' ]:
|
||||||
|
face_swapper.set_providers([ facefusion.choices.execution_provider_set.get('cpu') ])
|
||||||
|
|
||||||
for face_swapper_input in face_swapper.get_inputs():
|
for face_swapper_input in face_swapper.get_inputs():
|
||||||
if face_swapper_input.name == 'source':
|
if face_swapper_input.name == 'source':
|
||||||
if model_type == 'blendswap' or model_type == 'uniface':
|
if model_type in [ 'blendswap', 'uniface' ]:
|
||||||
face_swapper_inputs[face_swapper_input.name] = prepare_source_frame(source_face)
|
face_swapper_inputs[face_swapper_input.name] = prepare_source_frame(source_face)
|
||||||
else:
|
else:
|
||||||
face_swapper_inputs[face_swapper_input.name] = prepare_source_embedding(source_face)
|
face_swapper_inputs[face_swapper_input.name] = prepare_source_embedding(source_face)
|
||||||
@@ -493,7 +543,7 @@ def normalize_crop_frame(crop_vision_frame : VisionFrame) -> VisionFrame:
|
|||||||
model_standard_deviation = get_model_options().get('standard_deviation')
|
model_standard_deviation = get_model_options().get('standard_deviation')
|
||||||
|
|
||||||
crop_vision_frame = crop_vision_frame.transpose(1, 2, 0)
|
crop_vision_frame = crop_vision_frame.transpose(1, 2, 0)
|
||||||
if model_type == 'ghost' or model_type == 'uniface':
|
if model_type in [ 'ghost', 'hififace', 'uniface' ]:
|
||||||
crop_vision_frame = crop_vision_frame * model_standard_deviation + model_mean
|
crop_vision_frame = crop_vision_frame * model_standard_deviation + model_mean
|
||||||
crop_vision_frame = crop_vision_frame.clip(0, 1)
|
crop_vision_frame = crop_vision_frame.clip(0, 1)
|
||||||
crop_vision_frame = crop_vision_frame[:, :, ::-1] * 255
|
crop_vision_frame = crop_vision_frame[:, :, ::-1] * 255
|
||||||
@@ -529,7 +579,13 @@ def process_frame(inputs : FaceSwapperInputs) -> VisionFrame:
|
|||||||
def process_frames(source_paths : List[str], queue_payloads : List[QueuePayload], update_progress : UpdateProgress) -> None:
|
def process_frames(source_paths : List[str], queue_payloads : List[QueuePayload], update_progress : UpdateProgress) -> None:
|
||||||
reference_faces = get_reference_faces() if 'reference' in state_manager.get_item('face_selector_mode') else None
|
reference_faces = get_reference_faces() if 'reference' in state_manager.get_item('face_selector_mode') else None
|
||||||
source_frames = read_static_images(source_paths)
|
source_frames = read_static_images(source_paths)
|
||||||
source_faces = get_many_faces(source_frames)
|
source_faces = []
|
||||||
|
|
||||||
|
for source_frame in source_frames:
|
||||||
|
temp_faces = get_many_faces([ source_frame ])
|
||||||
|
temp_faces = sort_faces_by_order(temp_faces, 'large-small')
|
||||||
|
if temp_faces:
|
||||||
|
source_faces.append(get_first(temp_faces))
|
||||||
source_face = get_average_face(source_faces)
|
source_face = get_average_face(source_faces)
|
||||||
|
|
||||||
for queue_payload in process_manager.manage(queue_payloads):
|
for queue_payload in process_manager.manage(queue_payloads):
|
||||||
@@ -548,7 +604,13 @@ def process_frames(source_paths : List[str], queue_payloads : List[QueuePayload]
|
|||||||
def process_image(source_paths : List[str], target_path : str, output_path : str) -> None:
|
def process_image(source_paths : List[str], target_path : str, output_path : str) -> None:
|
||||||
reference_faces = get_reference_faces() if 'reference' in state_manager.get_item('face_selector_mode') else None
|
reference_faces = get_reference_faces() if 'reference' in state_manager.get_item('face_selector_mode') else None
|
||||||
source_frames = read_static_images(source_paths)
|
source_frames = read_static_images(source_paths)
|
||||||
source_faces = get_many_faces(source_frames)
|
source_faces = []
|
||||||
|
|
||||||
|
for source_frame in source_frames:
|
||||||
|
temp_faces = get_many_faces([ source_frame ])
|
||||||
|
temp_faces = sort_faces_by_order(temp_faces, 'large-small')
|
||||||
|
if temp_faces:
|
||||||
|
source_faces.append(get_first(temp_faces))
|
||||||
source_face = get_average_face(source_faces)
|
source_face = get_average_face(source_faces)
|
||||||
target_vision_frame = read_static_image(target_path)
|
target_vision_frame = read_static_image(target_path)
|
||||||
output_vision_frame = process_frame(
|
output_vision_frame = process_frame(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from functools import lru_cache
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
@@ -9,142 +10,153 @@ import facefusion.jobs.job_store
|
|||||||
import facefusion.processors.core as processors
|
import facefusion.processors.core as processors
|
||||||
from facefusion import config, content_analyser, inference_manager, logger, process_manager, state_manager, wording
|
from facefusion import config, content_analyser, inference_manager, logger, process_manager, state_manager, wording
|
||||||
from facefusion.common_helper import create_int_metavar
|
from facefusion.common_helper import create_int_metavar
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
|
from facefusion.execution import has_execution_provider
|
||||||
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.typing import FrameColorizerInputs
|
from facefusion.processors.types import FrameColorizerInputs
|
||||||
from facefusion.program_helper import find_argument_group
|
from facefusion.program_helper import find_argument_group
|
||||||
from facefusion.thread_helper import thread_semaphore
|
from facefusion.thread_helper import thread_semaphore
|
||||||
from facefusion.typing import ApplyStateItem, Args, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
from facefusion.types import ApplyStateItem, Args, DownloadScope, ExecutionProvider, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
||||||
from facefusion.vision import read_image, read_static_image, unpack_resolution, write_image
|
from facefusion.vision import read_image, read_static_image, unpack_resolution, write_image
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'ddcolor':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'ddcolor':
|
||||||
{
|
{
|
||||||
'frame_colorizer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ddcolor.hash',
|
'frame_colorizer':
|
||||||
'path': resolve_relative_path('../.assets/models/ddcolor.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'ddcolor.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/ddcolor.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_colorizer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'ddcolor.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/ddcolor.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'type': 'ddcolor'
|
||||||
},
|
},
|
||||||
'sources':
|
'ddcolor_artistic':
|
||||||
{
|
{
|
||||||
'frame_colorizer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ddcolor.onnx',
|
'frame_colorizer':
|
||||||
'path': resolve_relative_path('../.assets/models/ddcolor.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'ddcolor_artistic.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/ddcolor_artistic.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_colorizer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'ddcolor_artistic.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/ddcolor_artistic.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'type': 'ddcolor'
|
||||||
},
|
},
|
||||||
'type': 'ddcolor'
|
'deoldify':
|
||||||
},
|
|
||||||
'ddcolor_artistic':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'frame_colorizer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ddcolor_artistic.hash',
|
'frame_colorizer':
|
||||||
'path': resolve_relative_path('../.assets/models/ddcolor_artistic.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'deoldify.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/deoldify.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_colorizer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'deoldify.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/deoldify.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'type': 'deoldify'
|
||||||
},
|
},
|
||||||
'sources':
|
'deoldify_artistic':
|
||||||
{
|
{
|
||||||
'frame_colorizer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ddcolor_artistic.onnx',
|
'frame_colorizer':
|
||||||
'path': resolve_relative_path('../.assets/models/ddcolor_artistic.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'deoldify_artistic.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/deoldify_artistic.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_colorizer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'deoldify_artistic.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/deoldify_artistic.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'type': 'deoldify'
|
||||||
},
|
},
|
||||||
'type': 'ddcolor'
|
'deoldify_stable':
|
||||||
},
|
|
||||||
'deoldify':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'frame_colorizer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/deoldify.hash',
|
'frame_colorizer':
|
||||||
'path': resolve_relative_path('../.assets/models/deoldify.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'deoldify_stable.hash'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/deoldify_stable.hash')
|
||||||
'sources':
|
}
|
||||||
{
|
},
|
||||||
'frame_colorizer':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/deoldify.onnx',
|
'frame_colorizer':
|
||||||
'path': resolve_relative_path('../.assets/models/deoldify.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'deoldify_stable.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/deoldify_stable.onnx')
|
||||||
'type': 'deoldify'
|
}
|
||||||
},
|
},
|
||||||
'deoldify_artistic':
|
'type': 'deoldify'
|
||||||
{
|
}
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'frame_colorizer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/deoldify_artistic.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/deoldify_artistic.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'frame_colorizer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/deoldify_artistic.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/deoldify_artistic.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'type': 'deoldify'
|
|
||||||
},
|
|
||||||
'deoldify_stable':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'frame_colorizer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/deoldify_stable.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/deoldify_stable.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'frame_colorizer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/deoldify_stable.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/deoldify_stable.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'type': 'deoldify'
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
model_sources = get_model_options().get('sources')
|
model_names = [ state_manager.get_item('frame_colorizer_model') ]
|
||||||
model_context = __name__ + '.' + state_manager.get_item('frame_colorizer_model')
|
model_source_set = get_model_options().get('sources')
|
||||||
return inference_manager.get_inference_pool(model_context, model_sources)
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
model_context = __name__ + '.' + state_manager.get_item('frame_colorizer_model')
|
model_names = [ state_manager.get_item('frame_colorizer_model') ]
|
||||||
inference_manager.clear_inference_pool(model_context)
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_execution_providers() -> List[ExecutionProvider]:
|
||||||
|
if has_execution_provider('coreml'):
|
||||||
|
return [ 'cpu' ]
|
||||||
|
return state_manager.get_item('execution_providers')
|
||||||
|
|
||||||
|
|
||||||
def get_model_options() -> ModelOptions:
|
def get_model_options() -> ModelOptions:
|
||||||
frame_colorizer_model = state_manager.get_item('frame_colorizer_model')
|
model_name = state_manager.get_item('frame_colorizer_model')
|
||||||
return MODEL_SET.get(frame_colorizer_model)
|
return create_static_model_set('full').get(model_name)
|
||||||
|
|
||||||
|
|
||||||
def register_args(program : ArgumentParser) -> None:
|
def register_args(program : ArgumentParser) -> None:
|
||||||
group_processors = find_argument_group(program, 'processors')
|
group_processors = find_argument_group(program, 'processors')
|
||||||
if group_processors:
|
if group_processors:
|
||||||
group_processors.add_argument('--frame-colorizer-model', help = wording.get('help.frame_colorizer_model'), default = config.get_str_value('processors.frame_colorizer_model', 'ddcolor'), choices = processors_choices.frame_colorizer_models)
|
group_processors.add_argument('--frame-colorizer-model', help = wording.get('help.frame_colorizer_model'), default = config.get_str_value('processors', 'frame_colorizer_model', 'ddcolor'), choices = processors_choices.frame_colorizer_models)
|
||||||
group_processors.add_argument('--frame-colorizer-size', help = wording.get('help.frame_colorizer_size'), type = str, default = config.get_str_value('processors.frame_colorizer_size', '256x256'), choices = processors_choices.frame_colorizer_sizes)
|
group_processors.add_argument('--frame-colorizer-size', help = wording.get('help.frame_colorizer_size'), type = str, default = config.get_str_value('processors', 'frame_colorizer_size', '256x256'), choices = processors_choices.frame_colorizer_sizes)
|
||||||
group_processors.add_argument('--frame-colorizer-blend', help = wording.get('help.frame_colorizer_blend'), type = int, default = config.get_int_value('processors.frame_colorizer_blend', '100'), choices = processors_choices.frame_colorizer_blend_range, metavar = create_int_metavar(processors_choices.frame_colorizer_blend_range))
|
group_processors.add_argument('--frame-colorizer-blend', help = wording.get('help.frame_colorizer_blend'), type = int, default = config.get_int_value('processors', 'frame_colorizer_blend', '100'), choices = processors_choices.frame_colorizer_blend_range, metavar = create_int_metavar(processors_choices.frame_colorizer_blend_range))
|
||||||
facefusion.jobs.job_store.register_step_keys([ 'frame_colorizer_model', 'frame_colorizer_blend', 'frame_colorizer_size' ])
|
facefusion.jobs.job_store.register_step_keys([ 'frame_colorizer_model', 'frame_colorizer_blend', 'frame_colorizer_size' ])
|
||||||
|
|
||||||
|
|
||||||
@@ -155,11 +167,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set = get_model_options().get('hashes')
|
||||||
model_hashes = get_model_options().get('hashes')
|
model_source_set = get_model_options().get('sources')
|
||||||
model_sources = get_model_options().get('sources')
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def pre_process(mode : ProcessMode) -> bool:
|
def pre_process(mode : ProcessMode) -> bool:
|
||||||
@@ -169,7 +180,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
|||||||
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
if mode == 'output' and not same_file_extension([ state_manager.get_item('target_path'), state_manager.get_item('output_path') ]):
|
if mode == 'output' and not same_file_extension(state_manager.get_item('target_path'), state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from functools import lru_cache
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
@@ -9,293 +10,416 @@ import facefusion.jobs.job_store
|
|||||||
import facefusion.processors.core as processors
|
import facefusion.processors.core as processors
|
||||||
from facefusion import config, content_analyser, inference_manager, logger, process_manager, state_manager, wording
|
from facefusion import config, content_analyser, inference_manager, logger, process_manager, state_manager, wording
|
||||||
from facefusion.common_helper import create_int_metavar
|
from facefusion.common_helper import create_int_metavar
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
|
from facefusion.execution import has_execution_provider
|
||||||
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.typing import FrameEnhancerInputs
|
from facefusion.processors.types import FrameEnhancerInputs
|
||||||
from facefusion.program_helper import find_argument_group
|
from facefusion.program_helper import find_argument_group
|
||||||
from facefusion.thread_helper import conditional_thread_semaphore
|
from facefusion.thread_helper import conditional_thread_semaphore
|
||||||
from facefusion.typing import ApplyStateItem, Args, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
from facefusion.types import ApplyStateItem, Args, DownloadScope, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
||||||
from facefusion.vision import create_tile_frames, merge_tile_frames, read_image, read_static_image, write_image
|
from facefusion.vision import create_tile_frames, merge_tile_frames, read_image, read_static_image, write_image
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'clear_reality_x4':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'clear_reality_x4':
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/clear_reality_x4.hash',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/clear_reality_x4.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'clear_reality_x4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/clear_reality_x4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'clear_reality_x4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/clear_reality_x4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (128, 8, 4),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'sources':
|
'lsdir_x4':
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/clear_reality_x4.onnx',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/clear_reality_x4.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'lsdir_x4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/lsdir_x4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'lsdir_x4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/lsdir_x4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (128, 8, 4),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'size': (128, 8, 4),
|
'nomos8k_sc_x4':
|
||||||
'scale': 4
|
|
||||||
},
|
|
||||||
'lsdir_x4':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/lsdir_x4.hash',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/lsdir_x4.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'nomos8k_sc_x4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/nomos8k_sc_x4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'nomos8k_sc_x4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/nomos8k_sc_x4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (128, 8, 4),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'sources':
|
'real_esrgan_x2':
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/lsdir_x4.onnx',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/lsdir_x4.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x2.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x2.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x2.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x2.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 16, 8),
|
||||||
|
'scale': 2
|
||||||
},
|
},
|
||||||
'size': (128, 8, 4),
|
'real_esrgan_x2_fp16':
|
||||||
'scale': 4
|
|
||||||
},
|
|
||||||
'nomos8k_sc_x4':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/nomos8k_sc_x4.hash',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/nomos8k_sc_x4.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x2_fp16.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x2_fp16.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x2_fp16.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x2_fp16.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 16, 8),
|
||||||
|
'scale': 2
|
||||||
},
|
},
|
||||||
'sources':
|
'real_esrgan_x4':
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/nomos8k_sc_x4.onnx',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/nomos8k_sc_x4.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 16, 8),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'size': (128, 8, 4),
|
'real_esrgan_x4_fp16':
|
||||||
'scale': 4
|
|
||||||
},
|
|
||||||
'real_esrgan_x2':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x2.hash',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x2.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x4_fp16.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x4_fp16.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x4_fp16.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x4_fp16.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 16, 8),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'sources':
|
'real_esrgan_x8':
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x2.onnx',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x2.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x8.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x8.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x8.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x8.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 16, 8),
|
||||||
|
'scale': 8
|
||||||
},
|
},
|
||||||
'size': (256, 16, 8),
|
'real_esrgan_x8_fp16':
|
||||||
'scale': 2
|
|
||||||
},
|
|
||||||
'real_esrgan_x2_fp16':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x2_fp16.hash',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x2_fp16.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x8_fp16.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x8_fp16.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'real_esrgan_x8_fp16.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_esrgan_x8_fp16.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 16, 8),
|
||||||
|
'scale': 8
|
||||||
},
|
},
|
||||||
'sources':
|
'real_hatgan_x4':
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x2_fp16.onnx',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x2_fp16.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'real_hatgan_x4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_hatgan_x4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'real_hatgan_x4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_hatgan_x4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (256, 16, 8),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'size': (256, 16, 8),
|
'real_web_photo_x4':
|
||||||
'scale': 2
|
|
||||||
},
|
|
||||||
'real_esrgan_x4':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x4.hash',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x4.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.1.0', 'real_web_photo_x4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_web_photo_x4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.1.0', 'real_web_photo_x4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/real_web_photo_x4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (64, 4, 2),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'sources':
|
'realistic_rescaler_x4':
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x4.onnx',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x4.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.1.0', 'realistic_rescaler_x4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/realistic_rescaler_x4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.1.0', 'realistic_rescaler_x4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/realistic_rescaler_x4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (128, 8, 4),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'size': (256, 16, 8),
|
'remacri_x4':
|
||||||
'scale': 4
|
|
||||||
},
|
|
||||||
'real_esrgan_x4_fp16':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x4_fp16.hash',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x4_fp16.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.1.0', 'remacri_x4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/remacri_x4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.1.0', 'remacri_x4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/remacri_x4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (128, 8, 4),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'sources':
|
'siax_x4':
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x4_fp16.onnx',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x4_fp16.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.1.0', 'siax_x4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/siax_x4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.1.0', 'siax_x4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/siax_x4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (128, 8, 4),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'size': (256, 16, 8),
|
'span_kendata_x4':
|
||||||
'scale': 4
|
|
||||||
},
|
|
||||||
'real_esrgan_x8':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x8.hash',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x8.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'span_kendata_x4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/span_kendata_x4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'span_kendata_x4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/span_kendata_x4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (128, 8, 4),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'sources':
|
'swin2_sr_x4':
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x8.onnx',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x8.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.1.0', 'swin2_sr_x4.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/swin2_sr_x4.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'frame_enhancer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.1.0', 'swin2_sr_x4.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/swin2_sr_x4.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (128, 8, 4),
|
||||||
|
'scale': 4
|
||||||
},
|
},
|
||||||
'size': (256, 16, 8),
|
'ultra_sharp_x4':
|
||||||
'scale': 8
|
|
||||||
},
|
|
||||||
'real_esrgan_x8_fp16':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
{
|
||||||
'frame_enhancer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x8_fp16.hash',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x8_fp16.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'ultra_sharp_x4.hash'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/ultra_sharp_x4.hash')
|
||||||
'sources':
|
}
|
||||||
{
|
},
|
||||||
'frame_enhancer':
|
'sources':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_esrgan_x8_fp16.onnx',
|
'frame_enhancer':
|
||||||
'path': resolve_relative_path('../.assets/models/real_esrgan_x8_fp16.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'ultra_sharp_x4.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/ultra_sharp_x4.onnx')
|
||||||
'size': (256, 16, 8),
|
}
|
||||||
'scale': 8
|
},
|
||||||
},
|
'size': (128, 8, 4),
|
||||||
'real_hatgan_x4':
|
'scale': 4
|
||||||
{
|
}
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'frame_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_hatgan_x4.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/real_hatgan_x4.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'frame_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/real_hatgan_x4.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/real_hatgan_x4.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'size': (256, 16, 8),
|
|
||||||
'scale': 4
|
|
||||||
},
|
|
||||||
'span_kendata_x4':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'frame_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/span_kendata_x4.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/span_kendata_x4.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'frame_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/span_kendata_x4.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/span_kendata_x4.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'size': (128, 8, 4),
|
|
||||||
'scale': 4
|
|
||||||
},
|
|
||||||
'ultra_sharp_x4':
|
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'frame_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ultra_sharp_x4.hash',
|
|
||||||
'path': resolve_relative_path('../.assets/models/ultra_sharp_x4.hash')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sources':
|
|
||||||
{
|
|
||||||
'frame_enhancer':
|
|
||||||
{
|
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/ultra_sharp_x4.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/ultra_sharp_x4.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'size': (128, 8, 4),
|
|
||||||
'scale': 4
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
model_sources = get_model_options().get('sources')
|
model_names = [ get_frame_enhancer_model() ]
|
||||||
model_context = __name__ + '.' + state_manager.get_item('frame_enhancer_model')
|
model_source_set = get_model_options().get('sources')
|
||||||
return inference_manager.get_inference_pool(model_context, model_sources)
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
model_context = __name__ + '.' + state_manager.get_item('frame_enhancer_model')
|
model_names = [ get_frame_enhancer_model() ]
|
||||||
inference_manager.clear_inference_pool(model_context)
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def get_model_options() -> ModelOptions:
|
def get_model_options() -> ModelOptions:
|
||||||
|
model_name = get_frame_enhancer_model()
|
||||||
|
return create_static_model_set('full').get(model_name)
|
||||||
|
|
||||||
|
|
||||||
|
def get_frame_enhancer_model() -> str:
|
||||||
frame_enhancer_model = state_manager.get_item('frame_enhancer_model')
|
frame_enhancer_model = state_manager.get_item('frame_enhancer_model')
|
||||||
return MODEL_SET.get(frame_enhancer_model)
|
|
||||||
|
if has_execution_provider('coreml'):
|
||||||
|
if frame_enhancer_model == 'real_esrgan_x2_fp16':
|
||||||
|
return 'real_esrgan_x2'
|
||||||
|
if frame_enhancer_model == 'real_esrgan_x4_fp16':
|
||||||
|
return 'real_esrgan_x4'
|
||||||
|
if frame_enhancer_model == 'real_esrgan_x8_fp16':
|
||||||
|
return 'real_esrgan_x8'
|
||||||
|
return frame_enhancer_model
|
||||||
|
|
||||||
|
|
||||||
def register_args(program : ArgumentParser) -> None:
|
def register_args(program : ArgumentParser) -> None:
|
||||||
group_processors = find_argument_group(program, 'processors')
|
group_processors = find_argument_group(program, 'processors')
|
||||||
if group_processors:
|
if group_processors:
|
||||||
group_processors.add_argument('--frame-enhancer-model', help = wording.get('help.frame_enhancer_model'), default = config.get_str_value('processors.frame_enhancer_model', 'span_kendata_x4'), choices = processors_choices.frame_enhancer_models)
|
group_processors.add_argument('--frame-enhancer-model', help = wording.get('help.frame_enhancer_model'), default = config.get_str_value('processors', 'frame_enhancer_model', 'span_kendata_x4'), choices = processors_choices.frame_enhancer_models)
|
||||||
group_processors.add_argument('--frame-enhancer-blend', help = wording.get('help.frame_enhancer_blend'), type = int, default = config.get_int_value('processors.frame_enhancer_blend', '80'), choices = processors_choices.frame_enhancer_blend_range, metavar = create_int_metavar(processors_choices.frame_enhancer_blend_range))
|
group_processors.add_argument('--frame-enhancer-blend', help = wording.get('help.frame_enhancer_blend'), type = int, default = config.get_int_value('processors', 'frame_enhancer_blend', '80'), choices = processors_choices.frame_enhancer_blend_range, metavar = create_int_metavar(processors_choices.frame_enhancer_blend_range))
|
||||||
facefusion.jobs.job_store.register_step_keys([ 'frame_enhancer_model', 'frame_enhancer_blend' ])
|
facefusion.jobs.job_store.register_step_keys([ 'frame_enhancer_model', 'frame_enhancer_blend' ])
|
||||||
|
|
||||||
|
|
||||||
@@ -305,11 +429,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set = get_model_options().get('hashes')
|
||||||
model_hashes = get_model_options().get('hashes')
|
model_source_set = get_model_options().get('sources')
|
||||||
model_sources = get_model_options().get('sources')
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def pre_process(mode : ProcessMode) -> bool:
|
def pre_process(mode : ProcessMode) -> bool:
|
||||||
@@ -319,7 +442,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
|||||||
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
if mode == 'output' and not same_file_extension([ state_manager.get_item('target_path'), state_manager.get_item('output_path') ]):
|
if mode == 'output' and not same_file_extension(state_manager.get_item('target_path'), state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@@ -364,7 +487,7 @@ def forward(tile_vision_frame : VisionFrame) -> VisionFrame:
|
|||||||
def prepare_tile_frame(vision_tile_frame : VisionFrame) -> VisionFrame:
|
def prepare_tile_frame(vision_tile_frame : VisionFrame) -> VisionFrame:
|
||||||
vision_tile_frame = numpy.expand_dims(vision_tile_frame[:, :, ::-1], axis = 0)
|
vision_tile_frame = numpy.expand_dims(vision_tile_frame[:, :, ::-1], axis = 0)
|
||||||
vision_tile_frame = vision_tile_frame.transpose(0, 3, 1, 2)
|
vision_tile_frame = vision_tile_frame.transpose(0, 3, 1, 2)
|
||||||
vision_tile_frame = vision_tile_frame.astype(numpy.float32) / 255
|
vision_tile_frame = vision_tile_frame.astype(numpy.float32) / 255.0
|
||||||
return vision_tile_frame
|
return vision_tile_frame
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from functools import lru_cache
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
@@ -10,7 +11,7 @@ import facefusion.processors.core as processors
|
|||||||
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, voice_extractor, wording
|
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, process_manager, state_manager, voice_extractor, wording
|
||||||
from facefusion.audio import create_empty_audio_frame, get_voice_frame, read_static_voice
|
from facefusion.audio import create_empty_audio_frame, get_voice_frame, read_static_voice
|
||||||
from facefusion.common_helper import get_first
|
from facefusion.common_helper import get_first
|
||||||
from facefusion.download import conditional_download_hashes, conditional_download_sources
|
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
||||||
from facefusion.face_analyser import get_many_faces, get_one_face
|
from facefusion.face_analyser import get_many_faces, get_one_face
|
||||||
from facefusion.face_helper import create_bounding_box, paste_back, warp_face_by_bounding_box, warp_face_by_face_landmark_5
|
from facefusion.face_helper import create_bounding_box, paste_back, warp_face_by_bounding_box, warp_face_by_face_landmark_5
|
||||||
from facefusion.face_masker import create_mouth_mask, create_occlusion_mask, create_static_box_mask
|
from facefusion.face_masker import create_mouth_mask, create_occlusion_mask, create_static_box_mask
|
||||||
@@ -18,77 +19,81 @@ from facefusion.face_selector import find_similar_faces, sort_and_filter_faces
|
|||||||
from facefusion.face_store import get_reference_faces
|
from facefusion.face_store import get_reference_faces
|
||||||
from facefusion.filesystem import filter_audio_paths, has_audio, in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
from facefusion.filesystem import filter_audio_paths, has_audio, in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.typing import LipSyncerInputs
|
from facefusion.processors.types import LipSyncerInputs
|
||||||
from facefusion.program_helper import find_argument_group
|
from facefusion.program_helper import find_argument_group
|
||||||
from facefusion.thread_helper import conditional_thread_semaphore
|
from facefusion.thread_helper import conditional_thread_semaphore
|
||||||
from facefusion.typing import ApplyStateItem, Args, AudioFrame, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
from facefusion.types import ApplyStateItem, Args, AudioFrame, DownloadScope, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, QueuePayload, UpdateProgress, VisionFrame
|
||||||
from facefusion.vision import read_image, read_static_image, restrict_video_fps, write_image
|
from facefusion.vision import read_image, read_static_image, restrict_video_fps, write_image
|
||||||
|
|
||||||
MODEL_SET : ModelSet =\
|
|
||||||
{
|
@lru_cache(maxsize = None)
|
||||||
'wav2lip_96':
|
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
||||||
|
return\
|
||||||
{
|
{
|
||||||
'hashes':
|
'wav2lip_96':
|
||||||
{
|
{
|
||||||
'lip_syncer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/wav2lip_96.hash',
|
'lip_syncer':
|
||||||
'path': resolve_relative_path('../.assets/models/wav2lip_96.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'wav2lip_96.hash'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/wav2lip_96.hash')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sources':
|
||||||
|
{
|
||||||
|
'lip_syncer':
|
||||||
|
{
|
||||||
|
'url': resolve_download_url('models-3.0.0', 'wav2lip_96.onnx'),
|
||||||
|
'path': resolve_relative_path('../.assets/models/wav2lip_96.onnx')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': (96, 96)
|
||||||
},
|
},
|
||||||
'sources':
|
'wav2lip_gan_96':
|
||||||
{
|
{
|
||||||
'lip_syncer':
|
'hashes':
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/wav2lip_96.onnx',
|
'lip_syncer':
|
||||||
'path': resolve_relative_path('../.assets/models/wav2lip_96.onnx')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'wav2lip_gan_96.hash'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/wav2lip_gan_96.hash')
|
||||||
'size': (96, 96)
|
}
|
||||||
},
|
},
|
||||||
'wav2lip_gan_96':
|
'sources':
|
||||||
{
|
|
||||||
'hashes':
|
|
||||||
{
|
|
||||||
'lip_syncer':
|
|
||||||
{
|
{
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/wav2lip_gan_96.hash',
|
'lip_syncer':
|
||||||
'path': resolve_relative_path('../.assets/models/wav2lip_gan_96.hash')
|
{
|
||||||
}
|
'url': resolve_download_url('models-3.0.0', 'wav2lip_gan_96.onnx'),
|
||||||
},
|
'path': resolve_relative_path('../.assets/models/wav2lip_gan_96.onnx')
|
||||||
'sources':
|
}
|
||||||
{
|
},
|
||||||
'lip_syncer':
|
'size': (96, 96)
|
||||||
{
|
}
|
||||||
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/wav2lip_gan_96.onnx',
|
|
||||||
'path': resolve_relative_path('../.assets/models/wav2lip_gan_96.onnx')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'size': (96, 96)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_inference_pool() -> InferencePool:
|
def get_inference_pool() -> InferencePool:
|
||||||
model_sources = get_model_options().get('sources')
|
model_names = [ state_manager.get_item('lip_syncer_model') ]
|
||||||
model_context = __name__ + '.' + state_manager.get_item('lip_syncer_model')
|
model_source_set = get_model_options().get('sources')
|
||||||
return inference_manager.get_inference_pool(model_context, model_sources)
|
|
||||||
|
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def clear_inference_pool() -> None:
|
def clear_inference_pool() -> None:
|
||||||
model_context = __name__ + '.' + state_manager.get_item('lip_syncer_model')
|
model_names = [ state_manager.get_item('lip_syncer_model') ]
|
||||||
inference_manager.clear_inference_pool(model_context)
|
inference_manager.clear_inference_pool(__name__, model_names)
|
||||||
|
|
||||||
|
|
||||||
def get_model_options() -> ModelOptions:
|
def get_model_options() -> ModelOptions:
|
||||||
lip_syncer_model = state_manager.get_item('lip_syncer_model')
|
model_name = state_manager.get_item('lip_syncer_model')
|
||||||
return MODEL_SET.get(lip_syncer_model)
|
return create_static_model_set('full').get(model_name)
|
||||||
|
|
||||||
|
|
||||||
def register_args(program : ArgumentParser) -> None:
|
def register_args(program : ArgumentParser) -> None:
|
||||||
group_processors = find_argument_group(program, 'processors')
|
group_processors = find_argument_group(program, 'processors')
|
||||||
if group_processors:
|
if group_processors:
|
||||||
group_processors.add_argument('--lip-syncer-model', help = wording.get('help.lip_syncer_model'), default = config.get_str_value('processors.lip_syncer_model', 'wav2lip_gan_96'), choices = processors_choices.lip_syncer_models)
|
group_processors.add_argument('--lip-syncer-model', help = wording.get('help.lip_syncer_model'), default = config.get_str_value('processors', 'lip_syncer_model', 'wav2lip_gan_96'), choices = processors_choices.lip_syncer_models)
|
||||||
facefusion.jobs.job_store.register_step_keys([ 'lip_syncer_model' ])
|
facefusion.jobs.job_store.register_step_keys([ 'lip_syncer_model' ])
|
||||||
|
|
||||||
|
|
||||||
@@ -97,11 +102,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../.assets/models')
|
model_hash_set = get_model_options().get('hashes')
|
||||||
model_hashes = get_model_options().get('hashes')
|
model_source_set = get_model_options().get('sources')
|
||||||
model_sources = get_model_options().get('sources')
|
|
||||||
|
|
||||||
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
|
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
||||||
|
|
||||||
|
|
||||||
def pre_process(mode : ProcessMode) -> bool:
|
def pre_process(mode : ProcessMode) -> bool:
|
||||||
@@ -114,7 +118,7 @@ def pre_process(mode : ProcessMode) -> bool:
|
|||||||
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('specify_image_or_video_output') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
if mode == 'output' and not same_file_extension([ state_manager.get_item('target_path'), state_manager.get_item('output_path') ]):
|
if mode == 'output' and not same_file_extension(state_manager.get_item('target_path'), state_manager.get_item('output_path')):
|
||||||
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
logger.error(wording.get('match_target_and_output_extension') + wording.get('exclamation_mark'), __name__)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from typing import List
|
|||||||
import numpy
|
import numpy
|
||||||
from cv2.typing import Size
|
from cv2.typing import Size
|
||||||
|
|
||||||
from facefusion.typing import VisionFrame
|
from facefusion.types import VisionFrame
|
||||||
|
|
||||||
|
|
||||||
def implode_pixel_boost(crop_vision_frame : VisionFrame, pixel_boost_total : int, model_size : Size) -> VisionFrame:
|
def implode_pixel_boost(crop_vision_frame : VisionFrame, pixel_boost_total : int, model_size : Size) -> VisionFrame:
|
||||||
@@ -13,6 +13,6 @@ def implode_pixel_boost(crop_vision_frame : VisionFrame, pixel_boost_total : int
|
|||||||
|
|
||||||
|
|
||||||
def explode_pixel_boost(temp_vision_frames : List[VisionFrame], pixel_boost_total : int, model_size : Size, pixel_boost_size : Size) -> VisionFrame:
|
def explode_pixel_boost(temp_vision_frames : List[VisionFrame], pixel_boost_total : int, model_size : Size, pixel_boost_size : Size) -> VisionFrame:
|
||||||
crop_vision_frame = numpy.stack(temp_vision_frames, axis = 0).reshape(pixel_boost_total, pixel_boost_total, model_size[0], model_size[1], 3)
|
crop_vision_frame = numpy.stack(temp_vision_frames).reshape(pixel_boost_total, pixel_boost_total, model_size[0], model_size[1], 3)
|
||||||
crop_vision_frame = crop_vision_frame.transpose(2, 0, 3, 1, 4).reshape(pixel_boost_size[0], pixel_boost_size[1], 3)
|
crop_vision_frame = crop_vision_frame.transpose(2, 0, 3, 1, 4).reshape(pixel_boost_size[0], pixel_boost_size[1], 3)
|
||||||
return crop_vision_frame
|
return crop_vision_frame
|
||||||
|
|||||||
@@ -1,26 +1,32 @@
|
|||||||
from typing import Any, Dict, List, Literal, TypedDict
|
from typing import Any, Dict, List, Literal, TypeAlias, TypedDict
|
||||||
|
|
||||||
from numpy._typing import NDArray
|
from numpy.typing import NDArray
|
||||||
|
|
||||||
from facefusion.typing import AppContext, AudioFrame, Face, FaceSet, VisionFrame
|
from facefusion.types import AppContext, AudioFrame, Face, FaceSet, VisionFrame
|
||||||
|
|
||||||
AgeModifierModel = Literal['styleganex_age']
|
AgeModifierModel = Literal['styleganex_age']
|
||||||
|
DeepSwapperModel : TypeAlias = str
|
||||||
ExpressionRestorerModel = Literal['live_portrait']
|
ExpressionRestorerModel = Literal['live_portrait']
|
||||||
FaceDebuggerItem = Literal['bounding-box', 'face-landmark-5', 'face-landmark-5/68', 'face-landmark-68', 'face-landmark-68/5', 'face-mask', 'face-detector-score', 'face-landmarker-score', 'age', 'gender', 'race']
|
FaceDebuggerItem = Literal['bounding-box', 'face-landmark-5', 'face-landmark-5/68', 'face-landmark-68', 'face-landmark-68/5', 'face-mask', 'face-detector-score', 'face-landmarker-score', 'age', 'gender', 'race']
|
||||||
FaceEditorModel = Literal['live_portrait']
|
FaceEditorModel = Literal['live_portrait']
|
||||||
FaceEnhancerModel = Literal['codeformer', 'gfpgan_1.2', 'gfpgan_1.3', 'gfpgan_1.4', 'gpen_bfr_256', 'gpen_bfr_512', 'gpen_bfr_1024', 'gpen_bfr_2048', 'restoreformer_plus_plus']
|
FaceEnhancerModel = Literal['codeformer', 'gfpgan_1.2', 'gfpgan_1.3', 'gfpgan_1.4', 'gpen_bfr_256', 'gpen_bfr_512', 'gpen_bfr_1024', 'gpen_bfr_2048', 'restoreformer_plus_plus']
|
||||||
FaceSwapperModel = Literal['blendswap_256', 'ghost_1_256', 'ghost_2_256', 'ghost_3_256', 'inswapper_128', 'inswapper_128_fp16', 'simswap_256', 'simswap_unofficial_512', 'uniface_256']
|
FaceSwapperModel = Literal['blendswap_256', 'ghost_1_256', 'ghost_2_256', 'ghost_3_256', 'hififace_unofficial_256', 'inswapper_128', 'inswapper_128_fp16', 'simswap_256', 'simswap_unofficial_512', 'uniface_256']
|
||||||
FrameColorizerModel = Literal['ddcolor', 'ddcolor_artistic', 'deoldify', 'deoldify_artistic', 'deoldify_stable']
|
FrameColorizerModel = Literal['ddcolor', 'ddcolor_artistic', 'deoldify', 'deoldify_artistic', 'deoldify_stable']
|
||||||
FrameEnhancerModel = Literal['clear_reality_x4', 'lsdir_x4', 'nomos8k_sc_x4', 'real_esrgan_x2', 'real_esrgan_x2_fp16', 'real_esrgan_x4', 'real_esrgan_x4_fp16', 'real_hatgan_x4', 'real_esrgan_x8', 'real_esrgan_x8_fp16', 'span_kendata_x4', 'ultra_sharp_x4']
|
FrameEnhancerModel = Literal['clear_reality_x4', 'lsdir_x4', 'nomos8k_sc_x4', 'real_esrgan_x2', 'real_esrgan_x2_fp16', 'real_esrgan_x4', 'real_esrgan_x4_fp16', 'real_esrgan_x8', 'real_esrgan_x8_fp16', 'real_hatgan_x4', 'real_web_photo_x4', 'realistic_rescaler_x4', 'remacri_x4', 'siax_x4', 'span_kendata_x4', 'swin2_sr_x4', 'ultra_sharp_x4']
|
||||||
LipSyncerModel = Literal['wav2lip_96', 'wav2lip_gan_96']
|
LipSyncerModel = Literal['wav2lip_96', 'wav2lip_gan_96']
|
||||||
|
|
||||||
FaceSwapperSet = Dict[FaceSwapperModel, List[str]]
|
FaceSwapperSet : TypeAlias = Dict[FaceSwapperModel, List[str]]
|
||||||
|
|
||||||
AgeModifierInputs = TypedDict('AgeModifierInputs',
|
AgeModifierInputs = TypedDict('AgeModifierInputs',
|
||||||
{
|
{
|
||||||
'reference_faces' : FaceSet,
|
'reference_faces' : FaceSet,
|
||||||
'target_vision_frame' : VisionFrame
|
'target_vision_frame' : VisionFrame
|
||||||
})
|
})
|
||||||
|
DeepSwapperInputs = TypedDict('DeepSwapperInputs',
|
||||||
|
{
|
||||||
|
'reference_faces' : FaceSet,
|
||||||
|
'target_vision_frame' : VisionFrame
|
||||||
|
})
|
||||||
ExpressionRestorerInputs = TypedDict('ExpressionRestorerInputs',
|
ExpressionRestorerInputs = TypedDict('ExpressionRestorerInputs',
|
||||||
{
|
{
|
||||||
'reference_faces' : FaceSet,
|
'reference_faces' : FaceSet,
|
||||||
@@ -67,6 +73,8 @@ ProcessorStateKey = Literal\
|
|||||||
[
|
[
|
||||||
'age_modifier_model',
|
'age_modifier_model',
|
||||||
'age_modifier_direction',
|
'age_modifier_direction',
|
||||||
|
'deep_swapper_model',
|
||||||
|
'deep_swapper_morph',
|
||||||
'expression_restorer_model',
|
'expression_restorer_model',
|
||||||
'expression_restorer_factor',
|
'expression_restorer_factor',
|
||||||
'face_debugger_items',
|
'face_debugger_items',
|
||||||
@@ -87,6 +95,7 @@ ProcessorStateKey = Literal\
|
|||||||
'face_editor_head_roll',
|
'face_editor_head_roll',
|
||||||
'face_enhancer_model',
|
'face_enhancer_model',
|
||||||
'face_enhancer_blend',
|
'face_enhancer_blend',
|
||||||
|
'face_enhancer_weight',
|
||||||
'face_swapper_model',
|
'face_swapper_model',
|
||||||
'face_swapper_pixel_boost',
|
'face_swapper_pixel_boost',
|
||||||
'frame_colorizer_model',
|
'frame_colorizer_model',
|
||||||
@@ -100,6 +109,8 @@ ProcessorState = TypedDict('ProcessorState',
|
|||||||
{
|
{
|
||||||
'age_modifier_model' : AgeModifierModel,
|
'age_modifier_model' : AgeModifierModel,
|
||||||
'age_modifier_direction' : int,
|
'age_modifier_direction' : int,
|
||||||
|
'deep_swapper_model' : DeepSwapperModel,
|
||||||
|
'deep_swapper_morph' : int,
|
||||||
'expression_restorer_model' : ExpressionRestorerModel,
|
'expression_restorer_model' : ExpressionRestorerModel,
|
||||||
'expression_restorer_factor' : int,
|
'expression_restorer_factor' : int,
|
||||||
'face_debugger_items' : List[FaceDebuggerItem],
|
'face_debugger_items' : List[FaceDebuggerItem],
|
||||||
@@ -120,6 +131,7 @@ ProcessorState = TypedDict('ProcessorState',
|
|||||||
'face_editor_head_roll' : float,
|
'face_editor_head_roll' : float,
|
||||||
'face_enhancer_model' : FaceEnhancerModel,
|
'face_enhancer_model' : FaceEnhancerModel,
|
||||||
'face_enhancer_blend' : int,
|
'face_enhancer_blend' : int,
|
||||||
|
'face_enhancer_weight' : float,
|
||||||
'face_swapper_model' : FaceSwapperModel,
|
'face_swapper_model' : FaceSwapperModel,
|
||||||
'face_swapper_pixel_boost' : str,
|
'face_swapper_pixel_boost' : str,
|
||||||
'frame_colorizer_model' : FrameColorizerModel,
|
'frame_colorizer_model' : FrameColorizerModel,
|
||||||
@@ -129,14 +141,17 @@ ProcessorState = TypedDict('ProcessorState',
|
|||||||
'frame_enhancer_blend' : int,
|
'frame_enhancer_blend' : int,
|
||||||
'lip_syncer_model' : LipSyncerModel
|
'lip_syncer_model' : LipSyncerModel
|
||||||
})
|
})
|
||||||
ProcessorStateSet = Dict[AppContext, ProcessorState]
|
ProcessorStateSet : TypeAlias = Dict[AppContext, ProcessorState]
|
||||||
|
|
||||||
LivePortraitPitch = float
|
AgeModifierDirection : TypeAlias = NDArray[Any]
|
||||||
LivePortraitYaw = float
|
DeepSwapperMorph : TypeAlias = NDArray[Any]
|
||||||
LivePortraitRoll = float
|
FaceEnhancerWeight : TypeAlias = NDArray[Any]
|
||||||
LivePortraitExpression = NDArray[Any]
|
LivePortraitPitch : TypeAlias = float
|
||||||
LivePortraitFeatureVolume = NDArray[Any]
|
LivePortraitYaw : TypeAlias = float
|
||||||
LivePortraitMotionPoints = NDArray[Any]
|
LivePortraitRoll : TypeAlias = float
|
||||||
LivePortraitRotation = NDArray[Any]
|
LivePortraitExpression : TypeAlias = NDArray[Any]
|
||||||
LivePortraitScale = NDArray[Any]
|
LivePortraitFeatureVolume : TypeAlias = NDArray[Any]
|
||||||
LivePortraitTranslation = NDArray[Any]
|
LivePortraitMotionPoints : TypeAlias = NDArray[Any]
|
||||||
|
LivePortraitRotation : TypeAlias = NDArray[Any]
|
||||||
|
LivePortraitScale : TypeAlias = NDArray[Any]
|
||||||
|
LivePortraitTranslation : TypeAlias = NDArray[Any]
|
||||||
+154
-84
@@ -1,13 +1,14 @@
|
|||||||
|
import tempfile
|
||||||
from argparse import ArgumentParser, HelpFormatter
|
from argparse import ArgumentParser, HelpFormatter
|
||||||
|
|
||||||
import facefusion.choices
|
import facefusion.choices
|
||||||
from facefusion import config, metadata, state_manager, wording
|
from facefusion import config, metadata, state_manager, wording
|
||||||
from facefusion.common_helper import create_float_metavar, create_int_metavar
|
from facefusion.common_helper import create_float_metavar, create_int_metavar, get_first, get_last
|
||||||
from facefusion.execution import get_execution_provider_choices
|
from facefusion.execution import get_available_execution_providers
|
||||||
from facefusion.filesystem import list_directory
|
from facefusion.ffmpeg import get_available_encoder_set
|
||||||
|
from facefusion.filesystem import get_file_name, resolve_file_paths
|
||||||
from facefusion.jobs import job_store
|
from facefusion.jobs import job_store
|
||||||
from facefusion.processors.core import get_processors_modules
|
from facefusion.processors.core import get_processors_modules
|
||||||
from facefusion.program_helper import remove_args, suggest_face_detector_choices
|
|
||||||
|
|
||||||
|
|
||||||
def create_help_formatter_small(prog : str) -> HelpFormatter:
|
def create_help_formatter_small(prog : str) -> HelpFormatter:
|
||||||
@@ -18,40 +19,88 @@ def create_help_formatter_large(prog : str) -> HelpFormatter:
|
|||||||
return HelpFormatter(prog, max_help_position = 300)
|
return HelpFormatter(prog, max_help_position = 300)
|
||||||
|
|
||||||
|
|
||||||
def create_config_program() -> ArgumentParser:
|
def create_config_path_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
group_paths = program.add_argument_group('paths')
|
group_paths = program.add_argument_group('paths')
|
||||||
group_paths.add_argument('-c', '--config-path', help = wording.get('help.config_path'), default = 'facefusion.ini')
|
group_paths.add_argument('--config-path', help = wording.get('help.config_path'), default = 'facefusion.ini')
|
||||||
job_store.register_job_keys([ 'config-path' ])
|
job_store.register_job_keys([ 'config_path' ])
|
||||||
apply_config_path(program)
|
apply_config_path(program)
|
||||||
return program
|
return program
|
||||||
|
|
||||||
|
|
||||||
|
def create_temp_path_program() -> ArgumentParser:
|
||||||
|
program = ArgumentParser(add_help = False)
|
||||||
|
group_paths = program.add_argument_group('paths')
|
||||||
|
group_paths.add_argument('--temp-path', help = wording.get('help.temp_path'), default = config.get_str_value('paths', 'temp_path', tempfile.gettempdir()))
|
||||||
|
job_store.register_job_keys([ 'temp_path' ])
|
||||||
|
return program
|
||||||
|
|
||||||
|
|
||||||
def create_jobs_path_program() -> ArgumentParser:
|
def create_jobs_path_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
group_paths = program.add_argument_group('paths')
|
group_paths = program.add_argument_group('paths')
|
||||||
group_paths.add_argument('-j', '--jobs-path', help = wording.get('help.jobs_path'), default = config.get_str_value('paths.jobs_path', '.jobs'))
|
group_paths.add_argument('--jobs-path', help = wording.get('help.jobs_path'), default = config.get_str_value('paths', 'jobs_path', '.jobs'))
|
||||||
job_store.register_job_keys([ 'jobs_path' ])
|
job_store.register_job_keys([ 'jobs_path' ])
|
||||||
return program
|
return program
|
||||||
|
|
||||||
|
|
||||||
def create_paths_program() -> ArgumentParser:
|
def create_source_paths_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
group_paths = program.add_argument_group('paths')
|
group_paths = program.add_argument_group('paths')
|
||||||
group_paths.add_argument('-s', '--source-paths', help = wording.get('help.source_paths'), action = 'append', default = config.get_str_list('paths.source_paths'))
|
group_paths.add_argument('-s', '--source-paths', help = wording.get('help.source_paths'), default = config.get_str_list('paths', 'source_paths'), nargs = '+')
|
||||||
group_paths.add_argument('-t', '--target-path', help = wording.get('help.target_path'), default = config.get_str_value('paths.target_path'))
|
job_store.register_step_keys([ 'source_paths' ])
|
||||||
group_paths.add_argument('-o', '--output-path', help = wording.get('help.output_path'), default = config.get_str_value('paths.output_path'))
|
return program
|
||||||
job_store.register_step_keys([ 'source_paths', 'target_path', 'output_path' ])
|
|
||||||
|
|
||||||
|
def create_target_path_program() -> ArgumentParser:
|
||||||
|
program = ArgumentParser(add_help = False)
|
||||||
|
group_paths = program.add_argument_group('paths')
|
||||||
|
group_paths.add_argument('-t', '--target-path', help = wording.get('help.target_path'), default = config.get_str_value('paths', 'target_path'))
|
||||||
|
job_store.register_step_keys([ 'target_path' ])
|
||||||
|
return program
|
||||||
|
|
||||||
|
|
||||||
|
def create_output_path_program() -> ArgumentParser:
|
||||||
|
program = ArgumentParser(add_help = False)
|
||||||
|
group_paths = program.add_argument_group('paths')
|
||||||
|
group_paths.add_argument('-o', '--output-path', help = wording.get('help.output_path'), default = config.get_str_value('paths', 'output_path'))
|
||||||
|
job_store.register_step_keys([ 'output_path' ])
|
||||||
|
return program
|
||||||
|
|
||||||
|
|
||||||
|
def create_source_pattern_program() -> ArgumentParser:
|
||||||
|
program = ArgumentParser(add_help = False)
|
||||||
|
group_patterns = program.add_argument_group('patterns')
|
||||||
|
group_patterns.add_argument('-s', '--source-pattern', help = wording.get('help.source_pattern'), default = config.get_str_value('patterns', 'source_pattern'))
|
||||||
|
job_store.register_job_keys([ 'source_pattern' ])
|
||||||
|
return program
|
||||||
|
|
||||||
|
|
||||||
|
def create_target_pattern_program() -> ArgumentParser:
|
||||||
|
program = ArgumentParser(add_help = False)
|
||||||
|
group_patterns = program.add_argument_group('patterns')
|
||||||
|
group_patterns.add_argument('-t', '--target-pattern', help = wording.get('help.target_pattern'), default = config.get_str_value('patterns', 'target_pattern'))
|
||||||
|
job_store.register_job_keys([ 'target_pattern' ])
|
||||||
|
return program
|
||||||
|
|
||||||
|
|
||||||
|
def create_output_pattern_program() -> ArgumentParser:
|
||||||
|
program = ArgumentParser(add_help = False)
|
||||||
|
group_patterns = program.add_argument_group('patterns')
|
||||||
|
group_patterns.add_argument('-o', '--output-pattern', help = wording.get('help.output_pattern'), default = config.get_str_value('patterns', 'output_pattern'))
|
||||||
|
job_store.register_job_keys([ 'output_pattern' ])
|
||||||
return program
|
return program
|
||||||
|
|
||||||
|
|
||||||
def create_face_detector_program() -> ArgumentParser:
|
def create_face_detector_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
group_face_detector = program.add_argument_group('face detector')
|
group_face_detector = program.add_argument_group('face detector')
|
||||||
group_face_detector.add_argument('--face-detector-model', help = wording.get('help.face_detector_model'), default = config.get_str_value('face_detector.face_detector_model', 'yoloface'), choices = facefusion.choices.face_detector_set.keys())
|
group_face_detector.add_argument('--face-detector-model', help = wording.get('help.face_detector_model'), default = config.get_str_value('face_detector', 'face_detector_model', 'yolo_face'), choices = facefusion.choices.face_detector_models)
|
||||||
group_face_detector.add_argument('--face-detector-size', help = wording.get('help.face_detector_size'), default = config.get_str_value('face_detector.face_detector_size', '640x640'), choices = suggest_face_detector_choices(program))
|
known_args, _ = program.parse_known_args()
|
||||||
group_face_detector.add_argument('--face-detector-angles', help = wording.get('help.face_detector_angles'), type = int, default = config.get_int_list('face_detector.face_detector_angles', '0'), choices = facefusion.choices.face_detector_angles, nargs = '+', metavar = 'FACE_DETECTOR_ANGLES')
|
face_detector_size_choices = facefusion.choices.face_detector_set.get(known_args.face_detector_model)
|
||||||
group_face_detector.add_argument('--face-detector-score', help = wording.get('help.face_detector_score'), type = float, default = config.get_float_value('face_detector.face_detector_score', '0.5'), choices = facefusion.choices.face_detector_score_range, metavar = create_float_metavar(facefusion.choices.face_detector_score_range))
|
group_face_detector.add_argument('--face-detector-size', help = wording.get('help.face_detector_size'), default = config.get_str_value('face_detector', 'face_detector_size', get_last(face_detector_size_choices)), choices = face_detector_size_choices)
|
||||||
|
group_face_detector.add_argument('--face-detector-angles', help = wording.get('help.face_detector_angles'), type = int, default = config.get_int_list('face_detector', 'face_detector_angles', '0'), choices = facefusion.choices.face_detector_angles, nargs = '+', metavar = 'FACE_DETECTOR_ANGLES')
|
||||||
|
group_face_detector.add_argument('--face-detector-score', help = wording.get('help.face_detector_score'), type = float, default = config.get_float_value('face_detector', 'face_detector_score', '0.5'), choices = facefusion.choices.face_detector_score_range, metavar = create_float_metavar(facefusion.choices.face_detector_score_range))
|
||||||
job_store.register_step_keys([ 'face_detector_model', 'face_detector_angles', 'face_detector_size', 'face_detector_score' ])
|
job_store.register_step_keys([ 'face_detector_model', 'face_detector_angles', 'face_detector_size', 'face_detector_score' ])
|
||||||
return program
|
return program
|
||||||
|
|
||||||
@@ -59,8 +108,8 @@ def create_face_detector_program() -> ArgumentParser:
|
|||||||
def create_face_landmarker_program() -> ArgumentParser:
|
def create_face_landmarker_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
group_face_landmarker = program.add_argument_group('face landmarker')
|
group_face_landmarker = program.add_argument_group('face landmarker')
|
||||||
group_face_landmarker.add_argument('--face-landmarker-model', help = wording.get('help.face_landmarker_model'), default = config.get_str_value('face_landmarker.face_landmarker_model', '2dfan4'), choices = facefusion.choices.face_landmarker_models)
|
group_face_landmarker.add_argument('--face-landmarker-model', help = wording.get('help.face_landmarker_model'), default = config.get_str_value('face_landmarker', 'face_landmarker_model', '2dfan4'), choices = facefusion.choices.face_landmarker_models)
|
||||||
group_face_landmarker.add_argument('--face-landmarker-score', help = wording.get('help.face_landmarker_score'), type = float, default = config.get_float_value('face_landmarker.face_landmarker_score', '0.5'), choices = facefusion.choices.face_landmarker_score_range, metavar = create_float_metavar(facefusion.choices.face_landmarker_score_range))
|
group_face_landmarker.add_argument('--face-landmarker-score', help = wording.get('help.face_landmarker_score'), type = float, default = config.get_float_value('face_landmarker', 'face_landmarker_score', '0.5'), choices = facefusion.choices.face_landmarker_score_range, metavar = create_float_metavar(facefusion.choices.face_landmarker_score_range))
|
||||||
job_store.register_step_keys([ 'face_landmarker_model', 'face_landmarker_score' ])
|
job_store.register_step_keys([ 'face_landmarker_model', 'face_landmarker_score' ])
|
||||||
return program
|
return program
|
||||||
|
|
||||||
@@ -68,15 +117,15 @@ def create_face_landmarker_program() -> ArgumentParser:
|
|||||||
def create_face_selector_program() -> ArgumentParser:
|
def create_face_selector_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
group_face_selector = program.add_argument_group('face selector')
|
group_face_selector = program.add_argument_group('face selector')
|
||||||
group_face_selector.add_argument('--face-selector-mode', help = wording.get('help.face_selector_mode'), default = config.get_str_value('face_selector.face_selector_mode', 'reference'), choices = facefusion.choices.face_selector_modes)
|
group_face_selector.add_argument('--face-selector-mode', help = wording.get('help.face_selector_mode'), default = config.get_str_value('face_selector', 'face_selector_mode', 'reference'), choices = facefusion.choices.face_selector_modes)
|
||||||
group_face_selector.add_argument('--face-selector-order', help = wording.get('help.face_selector_order'), default = config.get_str_value('face_selector.face_selector_order', 'large-small'), choices = facefusion.choices.face_selector_orders)
|
group_face_selector.add_argument('--face-selector-order', help = wording.get('help.face_selector_order'), default = config.get_str_value('face_selector', 'face_selector_order', 'large-small'), choices = facefusion.choices.face_selector_orders)
|
||||||
group_face_selector.add_argument('--face-selector-age-start', help = wording.get('help.face_selector_age_start'), type = int, default = config.get_int_value('face_selector.face_selector_age_start'), choices = facefusion.choices.face_selector_age_range, metavar = create_int_metavar(facefusion.choices.face_selector_age_range))
|
group_face_selector.add_argument('--face-selector-age-start', help = wording.get('help.face_selector_age_start'), type = int, default = config.get_int_value('face_selector', 'face_selector_age_start'), choices = facefusion.choices.face_selector_age_range, metavar = create_int_metavar(facefusion.choices.face_selector_age_range))
|
||||||
group_face_selector.add_argument('--face-selector-age-end', help = wording.get('help.face_selector_age_end'), type = int, default = config.get_int_value('face_selector.face_selector_age_end'), choices = facefusion.choices.face_selector_age_range, metavar = create_int_metavar(facefusion.choices.face_selector_age_range))
|
group_face_selector.add_argument('--face-selector-age-end', help = wording.get('help.face_selector_age_end'), type = int, default = config.get_int_value('face_selector', 'face_selector_age_end'), choices = facefusion.choices.face_selector_age_range, metavar = create_int_metavar(facefusion.choices.face_selector_age_range))
|
||||||
group_face_selector.add_argument('--face-selector-gender', help = wording.get('help.face_selector_gender'), default = config.get_str_value('face_selector.face_selector_gender'), choices = facefusion.choices.face_selector_genders)
|
group_face_selector.add_argument('--face-selector-gender', help = wording.get('help.face_selector_gender'), default = config.get_str_value('face_selector', 'face_selector_gender'), choices = facefusion.choices.face_selector_genders)
|
||||||
group_face_selector.add_argument('--face-selector-race', help = wording.get('help.face_selector_race'), default = config.get_str_value('face_selector.face_selector_race'), choices = facefusion.choices.face_selector_races)
|
group_face_selector.add_argument('--face-selector-race', help = wording.get('help.face_selector_race'), default = config.get_str_value('face_selector', 'face_selector_race'), choices = facefusion.choices.face_selector_races)
|
||||||
group_face_selector.add_argument('--reference-face-position', help = wording.get('help.reference_face_position'), type = int, default = config.get_int_value('face_selector.reference_face_position', '0'))
|
group_face_selector.add_argument('--reference-face-position', help = wording.get('help.reference_face_position'), type = int, default = config.get_int_value('face_selector', 'reference_face_position', '0'))
|
||||||
group_face_selector.add_argument('--reference-face-distance', help = wording.get('help.reference_face_distance'), type = float, default = config.get_float_value('face_selector.reference_face_distance', '0.6'), choices = facefusion.choices.reference_face_distance_range, metavar = create_float_metavar(facefusion.choices.reference_face_distance_range))
|
group_face_selector.add_argument('--reference-face-distance', help = wording.get('help.reference_face_distance'), type = float, default = config.get_float_value('face_selector', 'reference_face_distance', '0.3'), choices = facefusion.choices.reference_face_distance_range, metavar = create_float_metavar(facefusion.choices.reference_face_distance_range))
|
||||||
group_face_selector.add_argument('--reference-frame-number', help = wording.get('help.reference_frame_number'), type = int, default = config.get_int_value('face_selector.reference_frame_number', '0'))
|
group_face_selector.add_argument('--reference-frame-number', help = wording.get('help.reference_frame_number'), type = int, default = config.get_int_value('face_selector', 'reference_frame_number', '0'))
|
||||||
job_store.register_step_keys([ 'face_selector_mode', 'face_selector_order', 'face_selector_gender', 'face_selector_race', 'face_selector_age_start', 'face_selector_age_end', 'reference_face_position', 'reference_face_distance', 'reference_frame_number' ])
|
job_store.register_step_keys([ 'face_selector_mode', 'face_selector_order', 'face_selector_gender', 'face_selector_race', 'face_selector_age_start', 'face_selector_age_end', 'reference_face_position', 'reference_face_distance', 'reference_frame_number' ])
|
||||||
return program
|
return program
|
||||||
|
|
||||||
@@ -84,46 +133,50 @@ def create_face_selector_program() -> ArgumentParser:
|
|||||||
def create_face_masker_program() -> ArgumentParser:
|
def create_face_masker_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
group_face_masker = program.add_argument_group('face masker')
|
group_face_masker = program.add_argument_group('face masker')
|
||||||
group_face_masker.add_argument('--face-mask-types', help = wording.get('help.face_mask_types').format(choices = ', '.join(facefusion.choices.face_mask_types)), default = config.get_str_list('face_masker.face_mask_types', 'box'), choices = facefusion.choices.face_mask_types, nargs = '+', metavar = 'FACE_MASK_TYPES')
|
group_face_masker.add_argument('--face-occluder-model', help = wording.get('help.face_occluder_model'), default = config.get_str_value('face_masker', 'face_occluder_model', 'xseg_1'), choices = facefusion.choices.face_occluder_models)
|
||||||
group_face_masker.add_argument('--face-mask-blur', help = wording.get('help.face_mask_blur'), type = float, default = config.get_float_value('face_masker.face_mask_blur', '0.3'), choices = facefusion.choices.face_mask_blur_range, metavar = create_float_metavar(facefusion.choices.face_mask_blur_range))
|
group_face_masker.add_argument('--face-parser-model', help = wording.get('help.face_parser_model'), default = config.get_str_value('face_masker', 'face_parser_model', 'bisenet_resnet_34'), choices = facefusion.choices.face_parser_models)
|
||||||
group_face_masker.add_argument('--face-mask-padding', help = wording.get('help.face_mask_padding'), type = int, default = config.get_int_list('face_masker.face_mask_padding', '0 0 0 0'), nargs = '+')
|
group_face_masker.add_argument('--face-mask-types', help = wording.get('help.face_mask_types').format(choices = ', '.join(facefusion.choices.face_mask_types)), default = config.get_str_list('face_masker', 'face_mask_types', 'box'), choices = facefusion.choices.face_mask_types, nargs = '+', metavar = 'FACE_MASK_TYPES')
|
||||||
group_face_masker.add_argument('--face-mask-regions', help = wording.get('help.face_mask_regions').format(choices = ', '.join(facefusion.choices.face_mask_regions)), default = config.get_str_list('face_masker.face_mask_regions', ' '.join(facefusion.choices.face_mask_regions)), choices = facefusion.choices.face_mask_regions, nargs = '+', metavar = 'FACE_MASK_REGIONS')
|
group_face_masker.add_argument('--face-mask-blur', help = wording.get('help.face_mask_blur'), type = float, default = config.get_float_value('face_masker', 'face_mask_blur', '0.3'), choices = facefusion.choices.face_mask_blur_range, metavar = create_float_metavar(facefusion.choices.face_mask_blur_range))
|
||||||
job_store.register_step_keys([ 'face_mask_types', 'face_mask_blur', 'face_mask_padding', 'face_mask_regions' ])
|
group_face_masker.add_argument('--face-mask-padding', help = wording.get('help.face_mask_padding'), type = int, default = config.get_int_list('face_masker', 'face_mask_padding', '0 0 0 0'), nargs = '+')
|
||||||
|
group_face_masker.add_argument('--face-mask-regions', help = wording.get('help.face_mask_regions').format(choices = ', '.join(facefusion.choices.face_mask_regions)), default = config.get_str_list('face_masker', 'face_mask_regions', ' '.join(facefusion.choices.face_mask_regions)), choices = facefusion.choices.face_mask_regions, nargs = '+', metavar = 'FACE_MASK_REGIONS')
|
||||||
|
job_store.register_step_keys([ 'face_occluder_model', 'face_parser_model', 'face_mask_types', 'face_mask_blur', 'face_mask_padding', 'face_mask_regions' ])
|
||||||
return program
|
return program
|
||||||
|
|
||||||
|
|
||||||
def create_frame_extraction_program() -> ArgumentParser:
|
def create_frame_extraction_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
group_frame_extraction = program.add_argument_group('frame extraction')
|
group_frame_extraction = program.add_argument_group('frame extraction')
|
||||||
group_frame_extraction.add_argument('--trim-frame-start', help = wording.get('help.trim_frame_start'), type = int, default = facefusion.config.get_int_value('frame_extraction.trim_frame_start'))
|
group_frame_extraction.add_argument('--trim-frame-start', help = wording.get('help.trim_frame_start'), type = int, default = facefusion.config.get_int_value('frame_extraction', 'trim_frame_start'))
|
||||||
group_frame_extraction.add_argument('--trim-frame-end', help = wording.get('help.trim_frame_end'), type = int, default = facefusion.config.get_int_value('frame_extraction.trim_frame_end'))
|
group_frame_extraction.add_argument('--trim-frame-end', help = wording.get('help.trim_frame_end'), type = int, default = facefusion.config.get_int_value('frame_extraction', 'trim_frame_end'))
|
||||||
group_frame_extraction.add_argument('--temp-frame-format', help = wording.get('help.temp_frame_format'), default = config.get_str_value('frame_extraction.temp_frame_format', 'png'), choices = facefusion.choices.temp_frame_formats)
|
group_frame_extraction.add_argument('--temp-frame-format', help = wording.get('help.temp_frame_format'), default = config.get_str_value('frame_extraction', 'temp_frame_format', 'png'), choices = facefusion.choices.temp_frame_formats)
|
||||||
group_frame_extraction.add_argument('--keep-temp', help = wording.get('help.keep_temp'), action = 'store_true', default = config.get_bool_value('frame_extraction.keep_temp'))
|
group_frame_extraction.add_argument('--keep-temp', help = wording.get('help.keep_temp'), action = 'store_true', default = config.get_bool_value('frame_extraction', 'keep_temp'))
|
||||||
job_store.register_step_keys([ 'trim_frame_start', 'trim_frame_end', 'temp_frame_format', 'keep_temp' ])
|
job_store.register_step_keys([ 'trim_frame_start', 'trim_frame_end', 'temp_frame_format', 'keep_temp' ])
|
||||||
return program
|
return program
|
||||||
|
|
||||||
|
|
||||||
def create_output_creation_program() -> ArgumentParser:
|
def create_output_creation_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
|
available_encoder_set = get_available_encoder_set()
|
||||||
group_output_creation = program.add_argument_group('output creation')
|
group_output_creation = program.add_argument_group('output creation')
|
||||||
group_output_creation.add_argument('--output-image-quality', help = wording.get('help.output_image_quality'), type = int, default = config.get_int_value('output_creation.output_image_quality', '80'), choices = facefusion.choices.output_image_quality_range, metavar = create_int_metavar(facefusion.choices.output_image_quality_range))
|
group_output_creation.add_argument('--output-image-quality', help = wording.get('help.output_image_quality'), type = int, default = config.get_int_value('output_creation', 'output_image_quality', '80'), choices = facefusion.choices.output_image_quality_range, metavar = create_int_metavar(facefusion.choices.output_image_quality_range))
|
||||||
group_output_creation.add_argument('--output-image-resolution', help = wording.get('help.output_image_resolution'), default = config.get_str_value('output_creation.output_image_resolution'))
|
group_output_creation.add_argument('--output-image-resolution', help = wording.get('help.output_image_resolution'), default = config.get_str_value('output_creation', 'output_image_resolution'))
|
||||||
group_output_creation.add_argument('--output-audio-encoder', help = wording.get('help.output_audio_encoder'), default = config.get_str_value('output_creation.output_audio_encoder', 'aac'), choices = facefusion.choices.output_audio_encoders)
|
group_output_creation.add_argument('--output-audio-encoder', help = wording.get('help.output_audio_encoder'), default = config.get_str_value('output_creation', 'output_audio_encoder', get_first(available_encoder_set.get('audio'))), choices = available_encoder_set.get('audio'))
|
||||||
group_output_creation.add_argument('--output-video-encoder', help = wording.get('help.output_video_encoder'), default = config.get_str_value('output_creation.output_video_encoder', 'libx264'), choices = facefusion.choices.output_video_encoders)
|
group_output_creation.add_argument('--output-audio-quality', help = wording.get('help.output_audio_quality'), type = int, default = config.get_int_value('output_creation', 'output_audio_quality', '80'), choices = facefusion.choices.output_audio_quality_range, metavar = create_int_metavar(facefusion.choices.output_audio_quality_range))
|
||||||
group_output_creation.add_argument('--output-video-preset', help = wording.get('help.output_video_preset'), default = config.get_str_value('output_creation.output_video_preset', 'veryfast'), choices = facefusion.choices.output_video_presets)
|
group_output_creation.add_argument('--output-audio-volume', help = wording.get('help.output_audio_volume'), type = int, default = config.get_int_value('output_creation', 'output_audio_volume', '100'), choices = facefusion.choices.output_audio_volume_range, metavar = create_int_metavar(facefusion.choices.output_audio_volume_range))
|
||||||
group_output_creation.add_argument('--output-video-quality', help = wording.get('help.output_video_quality'), type = int, default = config.get_int_value('output_creation.output_video_quality', '80'), choices = facefusion.choices.output_video_quality_range, metavar = create_int_metavar(facefusion.choices.output_video_quality_range))
|
group_output_creation.add_argument('--output-video-encoder', help = wording.get('help.output_video_encoder'), default = config.get_str_value('output_creation', 'output_video_encoder', get_first(available_encoder_set.get('video'))), choices = available_encoder_set.get('video'))
|
||||||
group_output_creation.add_argument('--output-video-resolution', help = wording.get('help.output_video_resolution'), default = config.get_str_value('output_creation.output_video_resolution'))
|
group_output_creation.add_argument('--output-video-preset', help = wording.get('help.output_video_preset'), default = config.get_str_value('output_creation', 'output_video_preset', 'veryfast'), choices = facefusion.choices.output_video_presets)
|
||||||
group_output_creation.add_argument('--output-video-fps', help = wording.get('help.output_video_fps'), type = float, default = config.get_str_value('output_creation.output_video_fps'))
|
group_output_creation.add_argument('--output-video-quality', help = wording.get('help.output_video_quality'), type = int, default = config.get_int_value('output_creation', 'output_video_quality', '80'), choices = facefusion.choices.output_video_quality_range, metavar = create_int_metavar(facefusion.choices.output_video_quality_range))
|
||||||
group_output_creation.add_argument('--skip-audio', help = wording.get('help.skip_audio'), action = 'store_true', default = config.get_bool_value('output_creation.skip_audio'))
|
group_output_creation.add_argument('--output-video-resolution', help = wording.get('help.output_video_resolution'), default = config.get_str_value('output_creation', 'output_video_resolution'))
|
||||||
job_store.register_step_keys([ 'output_image_quality', 'output_image_resolution', 'output_audio_encoder', 'output_video_encoder', 'output_video_preset', 'output_video_quality', 'output_video_resolution', 'output_video_fps', 'skip_audio' ])
|
group_output_creation.add_argument('--output-video-fps', help = wording.get('help.output_video_fps'), type = float, default = config.get_str_value('output_creation', 'output_video_fps'))
|
||||||
|
job_store.register_step_keys([ 'output_image_quality', 'output_image_resolution', 'output_audio_encoder', 'output_audio_quality', 'output_audio_volume', 'output_video_encoder', 'output_video_preset', 'output_video_quality', 'output_video_resolution', 'output_video_fps' ])
|
||||||
return program
|
return program
|
||||||
|
|
||||||
|
|
||||||
def create_processors_program() -> ArgumentParser:
|
def create_processors_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
available_processors = list_directory('facefusion/processors/modules')
|
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
||||||
group_processors = program.add_argument_group('processors')
|
group_processors = program.add_argument_group('processors')
|
||||||
group_processors.add_argument('--processors', help = wording.get('help.processors').format(choices = ', '.join(available_processors)), default = config.get_str_list('processors.processors', 'face_swapper'), nargs = '+')
|
group_processors.add_argument('--processors', help = wording.get('help.processors').format(choices = ', '.join(available_processors)), default = config.get_str_list('processors', 'processors', 'face_swapper'), nargs = '+')
|
||||||
job_store.register_step_keys([ 'processors' ])
|
job_store.register_step_keys([ 'processors' ])
|
||||||
for processor_module in get_processors_modules(available_processors):
|
for processor_module in get_processors_modules(available_processors):
|
||||||
processor_module.register_args(program)
|
processor_module.register_args(program)
|
||||||
@@ -132,51 +185,67 @@ def create_processors_program() -> ArgumentParser:
|
|||||||
|
|
||||||
def create_uis_program() -> ArgumentParser:
|
def create_uis_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
available_ui_layouts = list_directory('facefusion/uis/layouts')
|
available_ui_layouts = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/uis/layouts') ]
|
||||||
group_uis = program.add_argument_group('uis')
|
group_uis = program.add_argument_group('uis')
|
||||||
group_uis.add_argument('--open-browser', help = wording.get('help.open_browser'), action = 'store_true', default = config.get_bool_value('uis.open_browser'))
|
group_uis.add_argument('--open-browser', help = wording.get('help.open_browser'), action = 'store_true', default = config.get_bool_value('uis', 'open_browser'))
|
||||||
group_uis.add_argument('--ui-layouts', help = wording.get('help.ui_layouts').format(choices = ', '.join(available_ui_layouts)), default = config.get_str_list('uis.ui_layouts', 'default'), nargs = '+')
|
group_uis.add_argument('--ui-layouts', help = wording.get('help.ui_layouts').format(choices = ', '.join(available_ui_layouts)), default = config.get_str_list('uis', 'ui_layouts', 'default'), nargs = '+')
|
||||||
group_uis.add_argument('--ui-workflow', help = wording.get('help.ui_workflow'), default = config.get_str_value('uis.ui_workflow', 'instant_runner'), choices = facefusion.choices.ui_workflows)
|
group_uis.add_argument('--ui-workflow', help = wording.get('help.ui_workflow'), default = config.get_str_value('uis', 'ui_workflow', 'instant_runner'), choices = facefusion.choices.ui_workflows)
|
||||||
return program
|
return program
|
||||||
|
|
||||||
|
|
||||||
def create_execution_program() -> ArgumentParser:
|
def create_execution_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
execution_providers = get_execution_provider_choices()
|
available_execution_providers = get_available_execution_providers()
|
||||||
group_execution = program.add_argument_group('execution')
|
group_execution = program.add_argument_group('execution')
|
||||||
group_execution.add_argument('--execution-device-id', help = wording.get('help.execution_device_id'), default = config.get_str_value('execution.execution_device_id', '0'))
|
group_execution.add_argument('--execution-device-id', help = wording.get('help.execution_device_id'), default = config.get_str_value('execution', 'execution_device_id', '0'))
|
||||||
group_execution.add_argument('--execution-providers', help = wording.get('help.execution_providers').format(choices = ', '.join(execution_providers)), default = config.get_str_list('execution.execution_providers', 'cpu'), choices = execution_providers, nargs = '+', metavar = 'EXECUTION_PROVIDERS')
|
group_execution.add_argument('--execution-providers', help = wording.get('help.execution_providers').format(choices = ', '.join(available_execution_providers)), default = config.get_str_list('execution', 'execution_providers', get_first(available_execution_providers)), choices = available_execution_providers, nargs = '+', metavar = 'EXECUTION_PROVIDERS')
|
||||||
group_execution.add_argument('--execution-thread-count', help = wording.get('help.execution_thread_count'), type = int, default = config.get_int_value('execution.execution_thread_count', '4'), choices = facefusion.choices.execution_thread_count_range, metavar = create_int_metavar(facefusion.choices.execution_thread_count_range))
|
group_execution.add_argument('--execution-thread-count', help = wording.get('help.execution_thread_count'), type = int, default = config.get_int_value('execution', 'execution_thread_count', '4'), choices = facefusion.choices.execution_thread_count_range, metavar = create_int_metavar(facefusion.choices.execution_thread_count_range))
|
||||||
group_execution.add_argument('--execution-queue-count', help = wording.get('help.execution_queue_count'), type = int, default = config.get_int_value('execution.execution_queue_count', '1'), choices = facefusion.choices.execution_queue_count_range, metavar = create_int_metavar(facefusion.choices.execution_queue_count_range))
|
group_execution.add_argument('--execution-queue-count', help = wording.get('help.execution_queue_count'), type = int, default = config.get_int_value('execution', 'execution_queue_count', '1'), choices = facefusion.choices.execution_queue_count_range, metavar = create_int_metavar(facefusion.choices.execution_queue_count_range))
|
||||||
job_store.register_job_keys([ 'execution_device_id', 'execution_providers', 'execution_thread_count', 'execution_queue_count' ])
|
job_store.register_job_keys([ 'execution_device_id', 'execution_providers', 'execution_thread_count', 'execution_queue_count' ])
|
||||||
return program
|
return program
|
||||||
|
|
||||||
|
|
||||||
|
def create_download_providers_program() -> ArgumentParser:
|
||||||
|
program = ArgumentParser(add_help = False)
|
||||||
|
group_download = program.add_argument_group('download')
|
||||||
|
group_download.add_argument('--download-providers', help = wording.get('help.download_providers').format(choices = ', '.join(facefusion.choices.download_providers)), default = config.get_str_list('download', 'download_providers', ' '.join(facefusion.choices.download_providers)), choices = facefusion.choices.download_providers, nargs = '+', metavar = 'DOWNLOAD_PROVIDERS')
|
||||||
|
job_store.register_job_keys([ 'download_providers' ])
|
||||||
|
return program
|
||||||
|
|
||||||
|
|
||||||
|
def create_download_scope_program() -> ArgumentParser:
|
||||||
|
program = ArgumentParser(add_help = False)
|
||||||
|
group_download = program.add_argument_group('download')
|
||||||
|
group_download.add_argument('--download-scope', help = wording.get('help.download_scope'), default = config.get_str_value('download', 'download_scope', 'lite'), choices = facefusion.choices.download_scopes)
|
||||||
|
job_store.register_job_keys([ 'download_scope' ])
|
||||||
|
return program
|
||||||
|
|
||||||
|
|
||||||
def create_memory_program() -> ArgumentParser:
|
def create_memory_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
group_memory = program.add_argument_group('memory')
|
group_memory = program.add_argument_group('memory')
|
||||||
group_memory.add_argument('--video-memory-strategy', help = wording.get('help.video_memory_strategy'), default = config.get_str_value('memory.video_memory_strategy', 'strict'), choices = facefusion.choices.video_memory_strategies)
|
group_memory.add_argument('--video-memory-strategy', help = wording.get('help.video_memory_strategy'), default = config.get_str_value('memory', 'video_memory_strategy', 'strict'), choices = facefusion.choices.video_memory_strategies)
|
||||||
group_memory.add_argument('--system-memory-limit', help = wording.get('help.system_memory_limit'), type = int, default = config.get_int_value('memory.system_memory_limit', '0'), choices = facefusion.choices.system_memory_limit_range, metavar = create_int_metavar(facefusion.choices.system_memory_limit_range))
|
group_memory.add_argument('--system-memory-limit', help = wording.get('help.system_memory_limit'), type = int, default = config.get_int_value('memory', 'system_memory_limit', '0'), choices = facefusion.choices.system_memory_limit_range, metavar = create_int_metavar(facefusion.choices.system_memory_limit_range))
|
||||||
job_store.register_job_keys([ 'video_memory_strategy', 'system_memory_limit' ])
|
job_store.register_job_keys([ 'video_memory_strategy', 'system_memory_limit' ])
|
||||||
return program
|
return program
|
||||||
|
|
||||||
|
|
||||||
def create_skip_download_program() -> ArgumentParser:
|
|
||||||
program = ArgumentParser(add_help = False)
|
|
||||||
group_misc = program.add_argument_group('misc')
|
|
||||||
group_misc.add_argument('--skip-download', help = wording.get('help.skip_download'), action = 'store_true', default = config.get_bool_value('misc.skip_download'))
|
|
||||||
job_store.register_job_keys([ 'skip_download' ])
|
|
||||||
return program
|
|
||||||
|
|
||||||
|
|
||||||
def create_log_level_program() -> ArgumentParser:
|
def create_log_level_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
group_misc = program.add_argument_group('misc')
|
group_misc = program.add_argument_group('misc')
|
||||||
group_misc.add_argument('--log-level', help = wording.get('help.log_level'), default = config.get_str_value('misc.log_level', 'info'), choices = facefusion.choices.log_level_set.keys())
|
group_misc.add_argument('--log-level', help = wording.get('help.log_level'), default = config.get_str_value('misc', 'log_level', 'info'), choices = facefusion.choices.log_levels)
|
||||||
job_store.register_job_keys([ 'log_level' ])
|
job_store.register_job_keys([ 'log_level' ])
|
||||||
return program
|
return program
|
||||||
|
|
||||||
|
|
||||||
|
def create_halt_on_error_program() -> ArgumentParser:
|
||||||
|
program = ArgumentParser(add_help = False)
|
||||||
|
group_misc = program.add_argument_group('misc')
|
||||||
|
group_misc.add_argument('--halt-on-error', help = wording.get('help.halt_on_error'), action = 'store_true', default = config.get_bool_value('misc', 'halt_on_error'))
|
||||||
|
job_store.register_job_keys([ 'halt_on_error' ])
|
||||||
|
return program
|
||||||
|
|
||||||
|
|
||||||
def create_job_id_program() -> ArgumentParser:
|
def create_job_id_program() -> ArgumentParser:
|
||||||
program = ArgumentParser(add_help = False)
|
program = ArgumentParser(add_help = False)
|
||||||
program.add_argument('job_id', help = wording.get('help.job_id'))
|
program.add_argument('job_id', help = wording.get('help.job_id'))
|
||||||
@@ -197,11 +266,11 @@ def create_step_index_program() -> ArgumentParser:
|
|||||||
|
|
||||||
|
|
||||||
def collect_step_program() -> ArgumentParser:
|
def collect_step_program() -> ArgumentParser:
|
||||||
return ArgumentParser(parents= [ create_config_program(), create_jobs_path_program(), create_paths_program(), create_face_detector_program(), create_face_landmarker_program(), create_face_selector_program(), create_face_masker_program(), create_frame_extraction_program(), create_output_creation_program(), create_processors_program() ], add_help = False)
|
return ArgumentParser(parents = [ create_face_detector_program(), create_face_landmarker_program(), create_face_selector_program(), create_face_masker_program(), create_frame_extraction_program(), create_output_creation_program(), create_processors_program() ], add_help = False)
|
||||||
|
|
||||||
|
|
||||||
def collect_job_program() -> ArgumentParser:
|
def collect_job_program() -> ArgumentParser:
|
||||||
return ArgumentParser(parents= [ create_execution_program(), create_memory_program(), create_skip_download_program(), create_log_level_program() ], add_help = False)
|
return ArgumentParser(parents = [ create_execution_program(), create_download_providers_program(), create_memory_program(), create_log_level_program() ], add_help = False)
|
||||||
|
|
||||||
|
|
||||||
def create_program() -> ArgumentParser:
|
def create_program() -> ArgumentParser:
|
||||||
@@ -210,26 +279,27 @@ def create_program() -> ArgumentParser:
|
|||||||
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')
|
||||||
sub_program = program.add_subparsers(dest = 'command')
|
sub_program = program.add_subparsers(dest = 'command')
|
||||||
# general
|
# general
|
||||||
sub_program.add_parser('run', help = wording.get('help.run'), parents = [ collect_step_program(), create_uis_program(), collect_job_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('run', help = wording.get('help.run'), parents = [ create_config_path_program(), create_temp_path_program(), create_jobs_path_program(), create_source_paths_program(), create_target_path_program(), create_output_path_program(), collect_step_program(), create_uis_program(), collect_job_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('headless-run', help = wording.get('help.headless_run'), parents = [ collect_step_program(), collect_job_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('headless-run', help = wording.get('help.headless_run'), parents = [ create_config_path_program(), create_temp_path_program(), create_jobs_path_program(), create_source_paths_program(), create_target_path_program(), create_output_path_program(), collect_step_program(), collect_job_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('force-download', help = wording.get('help.force_download'), parents = [ create_log_level_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('batch-run', help = wording.get('help.batch_run'), parents = [ create_config_path_program(), create_temp_path_program(), create_jobs_path_program(), create_source_pattern_program(), create_target_pattern_program(), create_output_pattern_program(), collect_step_program(), collect_job_program() ], formatter_class = create_help_formatter_large)
|
||||||
|
sub_program.add_parser('force-download', help = wording.get('help.force_download'), parents = [ create_download_providers_program(), create_download_scope_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
||||||
# job manager
|
# job manager
|
||||||
sub_program.add_parser('job-list', help = wording.get('help.job_list'), parents = [ create_job_status_program(), create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-list', help = wording.get('help.job_list'), parents = [ create_job_status_program(), create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-create', help = wording.get('help.job_create'), parents = [ create_job_id_program(), create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-create', help = wording.get('help.job_create'), parents = [ create_job_id_program(), create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-submit', help = wording.get('help.job_submit'), parents = [ create_job_id_program(), create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-submit', help = wording.get('help.job_submit'), parents = [ create_job_id_program(), create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-submit-all', help = wording.get('help.job_submit_all'), parents = [ create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-submit-all', help = wording.get('help.job_submit_all'), parents = [ create_jobs_path_program(), create_log_level_program(), create_halt_on_error_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-delete', help = wording.get('help.job_delete'), parents = [ create_job_id_program(), create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-delete', help = wording.get('help.job_delete'), parents = [ create_job_id_program(), create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-delete-all', help = wording.get('help.job_delete_all'), parents = [ create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-delete-all', help = wording.get('help.job_delete_all'), parents = [ create_jobs_path_program(), create_log_level_program(), create_halt_on_error_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-add-step', help = wording.get('help.job_add_step'), parents = [ create_job_id_program(), collect_step_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-add-step', help = wording.get('help.job_add_step'), parents = [ create_job_id_program(), create_config_path_program(), create_jobs_path_program(), create_source_paths_program(), create_target_path_program(), create_output_path_program(), collect_step_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-remix-step', help = wording.get('help.job_remix_step'), parents = [ create_job_id_program(), create_step_index_program(), remove_args(collect_step_program(), [ 'target_path' ]), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-remix-step', help = wording.get('help.job_remix_step'), parents = [ create_job_id_program(), create_step_index_program(), create_config_path_program(), create_jobs_path_program(), create_source_paths_program(), create_output_path_program(), collect_step_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-insert-step', help = wording.get('help.job_insert_step'), parents = [ create_job_id_program(), create_step_index_program(), collect_step_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-insert-step', help = wording.get('help.job_insert_step'), parents = [ create_job_id_program(), create_step_index_program(), create_config_path_program(), create_jobs_path_program(), create_source_paths_program(), create_target_path_program(), create_output_path_program(), collect_step_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-remove-step', help = wording.get('help.job_remove_step'), parents = [ create_job_id_program(), create_step_index_program(), create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-remove-step', help = wording.get('help.job_remove_step'), parents = [ create_job_id_program(), create_step_index_program(), create_jobs_path_program(), create_log_level_program() ], formatter_class = create_help_formatter_large)
|
||||||
# job runner
|
# job runner
|
||||||
sub_program.add_parser('job-run', help = wording.get('help.job_run'), parents = [ create_job_id_program(), create_config_program(), create_jobs_path_program(), collect_job_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-run', help = wording.get('help.job_run'), parents = [ create_job_id_program(), create_config_path_program(), create_temp_path_program(), create_jobs_path_program(), collect_job_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-run-all', help = wording.get('help.job_run_all'), parents = [ create_config_program(), create_jobs_path_program(), collect_job_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-run-all', help = wording.get('help.job_run_all'), parents = [ create_config_path_program(), create_temp_path_program(), create_jobs_path_program(), collect_job_program(), create_halt_on_error_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-retry', help = wording.get('help.job_retry'), parents = [ create_job_id_program(), create_config_program(), create_jobs_path_program(), collect_job_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-retry', help = wording.get('help.job_retry'), parents = [ create_job_id_program(), create_config_path_program(), create_temp_path_program(), create_jobs_path_program(), collect_job_program() ], formatter_class = create_help_formatter_large)
|
||||||
sub_program.add_parser('job-retry-all', help = wording.get('help.job_retry_all'), parents = [ create_config_program(), create_jobs_path_program(), collect_job_program() ], formatter_class = create_help_formatter_large)
|
sub_program.add_parser('job-retry-all', help = wording.get('help.job_retry_all'), parents = [ create_config_path_program(), create_temp_path_program(), create_jobs_path_program(), collect_job_program(), create_halt_on_error_program() ], formatter_class = create_help_formatter_large)
|
||||||
return ArgumentParser(parents = [ program ], formatter_class = create_help_formatter_small, add_help = True)
|
return ArgumentParser(parents = [ program ], formatter_class = create_help_formatter_small)
|
||||||
|
|
||||||
|
|
||||||
def apply_config_path(program : ArgumentParser) -> None:
|
def apply_config_path(program : ArgumentParser) -> None:
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
from argparse import ArgumentParser, _ArgumentGroup, _SubParsersAction
|
from argparse import ArgumentParser, _ArgumentGroup, _SubParsersAction
|
||||||
from typing import List, Optional
|
from typing import Optional
|
||||||
|
|
||||||
import facefusion.choices
|
|
||||||
from facefusion.processors import choices as processors_choices
|
|
||||||
|
|
||||||
|
|
||||||
def find_argument_group(program : ArgumentParser, group_name : str) -> Optional[_ArgumentGroup]:
|
def find_argument_group(program : ArgumentParser, group_name : str) -> Optional[_ArgumentGroup]:
|
||||||
@@ -32,21 +29,3 @@ def validate_actions(program : ArgumentParser) -> bool:
|
|||||||
elif action.default not in action.choices:
|
elif action.default not in action.choices:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def remove_args(program : ArgumentParser, remove_names : List[str]) -> ArgumentParser:
|
|
||||||
actions = [ action for action in program._actions if action.dest in remove_names ]
|
|
||||||
|
|
||||||
for action in actions:
|
|
||||||
program._actions.remove(action)
|
|
||||||
return program
|
|
||||||
|
|
||||||
|
|
||||||
def suggest_face_detector_choices(program : ArgumentParser) -> List[str]:
|
|
||||||
known_args, _ = program.parse_known_args()
|
|
||||||
return facefusion.choices.face_detector_set.get(known_args.face_detector_model) #type:ignore[call-overload]
|
|
||||||
|
|
||||||
|
|
||||||
def suggest_face_swapper_pixel_boost_choices(program : ArgumentParser) -> List[str]:
|
|
||||||
known_args, _ = program.parse_known_args()
|
|
||||||
return processors_choices.face_swapper_set.get(known_args.face_swapper_model) #type:ignore[call-overload]
|
|
||||||
|
|||||||
+11
-11
@@ -1,37 +1,37 @@
|
|||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
|
||||||
from facefusion.app_context import detect_app_context
|
from facefusion.app_context import detect_app_context
|
||||||
from facefusion.processors.typing import ProcessorState, ProcessorStateKey
|
from facefusion.processors.types import ProcessorState, ProcessorStateKey, ProcessorStateSet
|
||||||
from facefusion.typing import State, StateKey, StateSet
|
from facefusion.types import State, StateKey, StateSet
|
||||||
|
|
||||||
STATES : Union[StateSet, ProcessorState] =\
|
STATE_SET : Union[StateSet, ProcessorStateSet] =\
|
||||||
{
|
{
|
||||||
'cli': {}, #type:ignore[typeddict-item]
|
'cli': {}, #type:ignore[assignment]
|
||||||
'ui': {} #type:ignore[typeddict-item]
|
'ui': {} #type:ignore[assignment]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_state() -> Union[State, ProcessorState]:
|
def get_state() -> Union[State, ProcessorState]:
|
||||||
app_context = detect_app_context()
|
app_context = detect_app_context()
|
||||||
return STATES.get(app_context) #type:ignore
|
return STATE_SET.get(app_context)
|
||||||
|
|
||||||
|
|
||||||
def init_item(key : Union[StateKey, ProcessorStateKey], value : Any) -> None:
|
def init_item(key : Union[StateKey, ProcessorStateKey], value : Any) -> None:
|
||||||
STATES['cli'][key] = value #type:ignore
|
STATE_SET['cli'][key] = value #type:ignore[literal-required]
|
||||||
STATES['ui'][key] = value #type:ignore
|
STATE_SET['ui'][key] = value #type:ignore[literal-required]
|
||||||
|
|
||||||
|
|
||||||
def get_item(key : Union[StateKey, ProcessorStateKey]) -> Any:
|
def get_item(key : Union[StateKey, ProcessorStateKey]) -> Any:
|
||||||
return get_state().get(key) #type:ignore
|
return get_state().get(key) #type:ignore[literal-required]
|
||||||
|
|
||||||
|
|
||||||
def set_item(key : Union[StateKey, ProcessorStateKey], value : Any) -> None:
|
def set_item(key : Union[StateKey, ProcessorStateKey], value : Any) -> None:
|
||||||
app_context = detect_app_context()
|
app_context = detect_app_context()
|
||||||
STATES[app_context][key] = value #type:ignore
|
STATE_SET[app_context][key] = value #type:ignore[literal-required]
|
||||||
|
|
||||||
|
|
||||||
def sync_item(key : Union[StateKey, ProcessorStateKey]) -> None:
|
def sync_item(key : Union[StateKey, ProcessorStateKey]) -> None:
|
||||||
STATES['cli'][key] = STATES.get('ui').get(key) #type:ignore
|
STATE_SET['cli'][key] = STATE_SET.get('ui').get(key) #type:ignore[literal-required]
|
||||||
|
|
||||||
|
|
||||||
def clear_item(key : Union[StateKey, ProcessorStateKey]) -> None:
|
def clear_item(key : Union[StateKey, ProcessorStateKey]) -> None:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import numpy
|
|||||||
|
|
||||||
from facefusion import logger, state_manager
|
from facefusion import logger, state_manager
|
||||||
from facefusion.face_store import get_face_store
|
from facefusion.face_store import get_face_store
|
||||||
from facefusion.typing import FaceSet
|
from facefusion.types import FaceSet
|
||||||
|
|
||||||
|
|
||||||
def create_statistics(static_faces : FaceSet) -> Dict[str, Any]:
|
def create_statistics(static_faces : FaceSet) -> Dict[str, Any]:
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
import glob
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from facefusion import state_manager
|
from facefusion import state_manager
|
||||||
from facefusion.filesystem import create_directory, move_file, remove_directory
|
from facefusion.filesystem import create_directory, get_file_extension, get_file_name, move_file, remove_directory, resolve_file_pattern
|
||||||
|
|
||||||
|
|
||||||
def get_temp_file_path(file_path : str) -> str:
|
def get_temp_file_path(file_path : str) -> str:
|
||||||
_, temp_file_extension = os.path.splitext(os.path.basename(file_path))
|
|
||||||
temp_directory_path = get_temp_directory_path(file_path)
|
temp_directory_path = get_temp_directory_path(file_path)
|
||||||
|
temp_file_extension = get_file_extension(file_path)
|
||||||
return os.path.join(temp_directory_path, 'temp' + temp_file_extension)
|
return os.path.join(temp_directory_path, 'temp' + temp_file_extension)
|
||||||
|
|
||||||
|
|
||||||
@@ -18,9 +16,9 @@ def move_temp_file(file_path : str, move_path : str) -> bool:
|
|||||||
return move_file(temp_file_path, move_path)
|
return move_file(temp_file_path, move_path)
|
||||||
|
|
||||||
|
|
||||||
def get_temp_frame_paths(target_path : str) -> List[str]:
|
def resolve_temp_frame_paths(target_path : str) -> List[str]:
|
||||||
temp_frames_pattern = get_temp_frames_pattern(target_path, '*')
|
temp_frames_pattern = get_temp_frames_pattern(target_path, '*')
|
||||||
return sorted(glob.glob(temp_frames_pattern))
|
return resolve_file_pattern(temp_frames_pattern)
|
||||||
|
|
||||||
|
|
||||||
def get_temp_frames_pattern(target_path : str, temp_frame_prefix : str) -> str:
|
def get_temp_frames_pattern(target_path : str, temp_frame_prefix : str) -> str:
|
||||||
@@ -28,24 +26,9 @@ def get_temp_frames_pattern(target_path : str, temp_frame_prefix : str) -> str:
|
|||||||
return os.path.join(temp_directory_path, temp_frame_prefix + '.' + state_manager.get_item('temp_frame_format'))
|
return os.path.join(temp_directory_path, temp_frame_prefix + '.' + state_manager.get_item('temp_frame_format'))
|
||||||
|
|
||||||
|
|
||||||
def get_base_directory_path() -> str:
|
|
||||||
return os.path.join(tempfile.gettempdir(), 'facefusion')
|
|
||||||
|
|
||||||
|
|
||||||
def create_base_directory() -> bool:
|
|
||||||
base_directory_path = get_base_directory_path()
|
|
||||||
return create_directory(base_directory_path)
|
|
||||||
|
|
||||||
|
|
||||||
def clear_base_directory() -> bool:
|
|
||||||
base_directory_path = get_base_directory_path()
|
|
||||||
return remove_directory(base_directory_path)
|
|
||||||
|
|
||||||
|
|
||||||
def get_temp_directory_path(file_path : str) -> str:
|
def get_temp_directory_path(file_path : str) -> str:
|
||||||
temp_file_name, _ = os.path.splitext(os.path.basename(file_path))
|
temp_file_name = get_file_name(file_path)
|
||||||
base_directory_path = get_base_directory_path()
|
return os.path.join(state_manager.get_item('temp_path'), 'facefusion', temp_file_name)
|
||||||
return os.path.join(base_directory_path, temp_file_name)
|
|
||||||
|
|
||||||
|
|
||||||
def create_temp_directory(file_path : str) -> bool:
|
def create_temp_directory(file_path : str) -> bool:
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, TypedDict
|
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, TypeAlias, TypedDict
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
from numpy.typing import NDArray
|
from numpy.typing import NDArray
|
||||||
from onnxruntime import InferenceSession
|
from onnxruntime import InferenceSession
|
||||||
|
|
||||||
Scale = float
|
Scale : TypeAlias = float
|
||||||
Score = float
|
Score : TypeAlias = float
|
||||||
Angle = int
|
Angle : TypeAlias = int
|
||||||
|
|
||||||
Detection = NDArray[Any]
|
Detection : TypeAlias = NDArray[Any]
|
||||||
Prediction = NDArray[Any]
|
Prediction : TypeAlias = NDArray[Any]
|
||||||
|
|
||||||
BoundingBox = NDArray[Any]
|
BoundingBox : TypeAlias = NDArray[Any]
|
||||||
FaceLandmark5 = NDArray[Any]
|
FaceLandmark5 : TypeAlias = NDArray[Any]
|
||||||
FaceLandmark68 = NDArray[Any]
|
FaceLandmark68 : TypeAlias = NDArray[Any]
|
||||||
FaceLandmarkSet = TypedDict('FaceLandmarkSet',
|
FaceLandmarkSet = TypedDict('FaceLandmarkSet',
|
||||||
{
|
{
|
||||||
'5' : FaceLandmark5, #type:ignore[valid-type]
|
'5' : FaceLandmark5, #type:ignore[valid-type]
|
||||||
@@ -27,9 +27,9 @@ FaceScoreSet = TypedDict('FaceScoreSet',
|
|||||||
'detector' : Score,
|
'detector' : Score,
|
||||||
'landmarker' : Score
|
'landmarker' : Score
|
||||||
})
|
})
|
||||||
Embedding = NDArray[numpy.float64]
|
Embedding : TypeAlias = NDArray[numpy.float64]
|
||||||
Gender = Literal['female', 'male']
|
Gender = Literal['female', 'male']
|
||||||
Age = range
|
Age : TypeAlias = range
|
||||||
Race = Literal['white', 'black', 'latino', 'asian', 'indian', 'arabic']
|
Race = Literal['white', 'black', 'latino', 'asian', 'indian', 'arabic']
|
||||||
Face = namedtuple('Face',
|
Face = namedtuple('Face',
|
||||||
[
|
[
|
||||||
@@ -43,33 +43,34 @@ Face = namedtuple('Face',
|
|||||||
'age',
|
'age',
|
||||||
'race'
|
'race'
|
||||||
])
|
])
|
||||||
FaceSet = Dict[str, List[Face]]
|
FaceSet : TypeAlias = Dict[str, List[Face]]
|
||||||
FaceStore = TypedDict('FaceStore',
|
FaceStore = TypedDict('FaceStore',
|
||||||
{
|
{
|
||||||
'static_faces' : FaceSet,
|
'static_faces' : FaceSet,
|
||||||
'reference_faces' : FaceSet
|
'reference_faces' : FaceSet
|
||||||
})
|
})
|
||||||
|
|
||||||
VisionFrame = NDArray[Any]
|
VisionFrame : TypeAlias = NDArray[Any]
|
||||||
Mask = NDArray[Any]
|
Mask : TypeAlias = NDArray[Any]
|
||||||
Points = NDArray[Any]
|
Points : TypeAlias = NDArray[Any]
|
||||||
Distance = NDArray[Any]
|
Distance : TypeAlias = NDArray[Any]
|
||||||
Matrix = NDArray[Any]
|
Matrix : TypeAlias = NDArray[Any]
|
||||||
Anchors = NDArray[Any]
|
Anchors : TypeAlias = NDArray[Any]
|
||||||
Translation = NDArray[Any]
|
Translation : TypeAlias = NDArray[Any]
|
||||||
|
|
||||||
AudioBuffer = bytes
|
AudioBuffer : TypeAlias = bytes
|
||||||
Audio = NDArray[Any]
|
Audio : TypeAlias = NDArray[Any]
|
||||||
AudioChunk = NDArray[Any]
|
AudioChunk : TypeAlias = NDArray[Any]
|
||||||
AudioFrame = NDArray[Any]
|
AudioFrame : TypeAlias = NDArray[Any]
|
||||||
Spectrogram = NDArray[Any]
|
Spectrogram : TypeAlias = NDArray[Any]
|
||||||
Mel = NDArray[Any]
|
Mel : TypeAlias = NDArray[Any]
|
||||||
MelFilterBank = NDArray[Any]
|
MelFilterBank : TypeAlias = NDArray[Any]
|
||||||
|
|
||||||
Fps = float
|
Fps : TypeAlias = float
|
||||||
Padding = Tuple[int, int, int, int]
|
Duration : TypeAlias = float
|
||||||
|
Padding : TypeAlias = Tuple[int, int, int, int]
|
||||||
Orientation = Literal['landscape', 'portrait']
|
Orientation = Literal['landscape', 'portrait']
|
||||||
Resolution = Tuple[int, int]
|
Resolution : TypeAlias = Tuple[int, int]
|
||||||
|
|
||||||
ProcessState = Literal['checking', 'processing', 'stopping', 'pending']
|
ProcessState = Literal['checking', 'processing', 'stopping', 'pending']
|
||||||
QueuePayload = TypedDict('QueuePayload',
|
QueuePayload = TypedDict('QueuePayload',
|
||||||
@@ -77,52 +78,65 @@ QueuePayload = TypedDict('QueuePayload',
|
|||||||
'frame_number' : int,
|
'frame_number' : int,
|
||||||
'frame_path' : str
|
'frame_path' : str
|
||||||
})
|
})
|
||||||
Args = Dict[str, Any]
|
Args : TypeAlias = Dict[str, Any]
|
||||||
UpdateProgress = Callable[[int], None]
|
UpdateProgress : TypeAlias = Callable[[int], None]
|
||||||
ProcessFrames = Callable[[List[str], List[QueuePayload], UpdateProgress], None]
|
ProcessFrames : TypeAlias = Callable[[List[str], List[QueuePayload], UpdateProgress], None]
|
||||||
ProcessStep = Callable[[str, int, Args], bool]
|
ProcessStep : TypeAlias = Callable[[str, int, Args], bool]
|
||||||
|
|
||||||
Content = Dict[str, Any]
|
Content : TypeAlias = Dict[str, Any]
|
||||||
|
|
||||||
WarpTemplate = Literal['arcface_112_v1', 'arcface_112_v2', 'arcface_128_v2', 'ffhq_512']
|
Commands : TypeAlias = List[str]
|
||||||
WarpTemplateSet = Dict[WarpTemplate, NDArray[Any]]
|
|
||||||
|
WarpTemplate = Literal['arcface_112_v1', 'arcface_112_v2', 'arcface_128', 'dfl_whole_face', 'ffhq_512', 'mtcnn_512', 'styleganex_384']
|
||||||
|
WarpTemplateSet : TypeAlias = Dict[WarpTemplate, NDArray[Any]]
|
||||||
ProcessMode = Literal['output', 'preview', 'stream']
|
ProcessMode = Literal['output', 'preview', 'stream']
|
||||||
|
|
||||||
ErrorCode = Literal[0, 1, 2, 3, 4]
|
ErrorCode = Literal[0, 1, 2, 3, 4]
|
||||||
LogLevel = Literal['error', 'warn', 'info', 'debug']
|
LogLevel = Literal['error', 'warn', 'info', 'debug']
|
||||||
LogLevelSet = Dict[LogLevel, int]
|
LogLevelSet : TypeAlias = Dict[LogLevel, int]
|
||||||
|
|
||||||
TableHeaders = List[str]
|
TableHeaders = List[str]
|
||||||
TableContents = List[List[Any]]
|
TableContents = List[List[Any]]
|
||||||
|
|
||||||
VideoMemoryStrategy = Literal['strict', 'moderate', 'tolerant']
|
FaceDetectorModel = Literal['many', 'retinaface', 'scrfd', 'yolo_face']
|
||||||
FaceDetectorModel = Literal['many', 'retinaface', 'scrfd', 'yoloface']
|
|
||||||
FaceLandmarkerModel = Literal['many', '2dfan4', 'peppa_wutz']
|
FaceLandmarkerModel = Literal['many', '2dfan4', 'peppa_wutz']
|
||||||
FaceDetectorSet = Dict[FaceDetectorModel, List[str]]
|
FaceDetectorSet : TypeAlias = Dict[FaceDetectorModel, List[str]]
|
||||||
FaceSelectorMode = Literal['many', 'one', 'reference']
|
FaceSelectorMode = Literal['many', 'one', 'reference']
|
||||||
FaceSelectorOrder = Literal['left-right', 'right-left', 'top-bottom', 'bottom-top', 'small-large', 'large-small', 'best-worst', 'worst-best']
|
FaceSelectorOrder = Literal['left-right', 'right-left', 'top-bottom', 'bottom-top', 'small-large', 'large-small', 'best-worst', 'worst-best']
|
||||||
|
FaceOccluderModel = Literal['xseg_1', 'xseg_2', 'xseg_3']
|
||||||
|
FaceParserModel = Literal['bisenet_resnet_18', 'bisenet_resnet_34']
|
||||||
FaceMaskType = Literal['box', 'occlusion', 'region']
|
FaceMaskType = Literal['box', 'occlusion', 'region']
|
||||||
FaceMaskRegion = Literal['skin', 'left-eyebrow', 'right-eyebrow', 'left-eye', 'right-eye', 'glasses', 'nose', 'mouth', 'upper-lip', 'lower-lip']
|
FaceMaskRegion = Literal['skin', 'left-eyebrow', 'right-eyebrow', 'left-eye', 'right-eye', 'glasses', 'nose', 'mouth', 'upper-lip', 'lower-lip']
|
||||||
TempFrameFormat = Literal['jpg', 'png', 'bmp']
|
FaceMaskRegionSet : TypeAlias = Dict[FaceMaskRegion, int]
|
||||||
OutputAudioEncoder = Literal['aac', 'libmp3lame', 'libopus', 'libvorbis']
|
|
||||||
OutputVideoEncoder = Literal['libx264', 'libx265', 'libvpx-vp9', 'h264_nvenc', 'hevc_nvenc', 'h264_amf', 'hevc_amf', 'h264_videotoolbox', 'hevc_videotoolbox']
|
|
||||||
OutputVideoPreset = Literal['ultrafast', 'superfast', 'veryfast', 'faster', 'fast', 'medium', 'slow', 'slower', 'veryslow']
|
|
||||||
|
|
||||||
Download = TypedDict('Download',
|
AudioFormat = Literal['flac', 'm4a', 'mp3', 'ogg', 'opus', 'wav']
|
||||||
|
ImageFormat = Literal['bmp', 'jpeg', 'png', 'tiff', 'webp']
|
||||||
|
VideoFormat = Literal['avi', 'm4v', 'mkv', 'mov', 'mp4', 'webm']
|
||||||
|
TempFrameFormat = Literal['bmp', 'jpeg', 'png', 'tiff']
|
||||||
|
AudioTypeSet : TypeAlias = Dict[AudioFormat, str]
|
||||||
|
ImageTypeSet : TypeAlias = Dict[ImageFormat, str]
|
||||||
|
VideoTypeSet : TypeAlias = Dict[VideoFormat, str]
|
||||||
|
|
||||||
|
AudioEncoder = Literal['flac', 'aac', 'libmp3lame', 'libopus', 'libvorbis', 'pcm_s16le', 'pcm_s32le']
|
||||||
|
VideoEncoder = Literal['libx264', 'libx265', 'libvpx-vp9', 'h264_nvenc', 'hevc_nvenc', 'h264_amf', 'hevc_amf', 'h264_qsv', 'hevc_qsv', 'h264_videotoolbox', 'hevc_videotoolbox', 'rawvideo']
|
||||||
|
EncoderSet = TypedDict('EncoderSet',
|
||||||
{
|
{
|
||||||
'url' : str,
|
'audio' : List[AudioEncoder],
|
||||||
'path' : str
|
'video' : List[VideoEncoder]
|
||||||
})
|
})
|
||||||
DownloadSet = Dict[str, Download]
|
VideoPreset = Literal['ultrafast', 'superfast', 'veryfast', 'faster', 'fast', 'medium', 'slow', 'slower', 'veryslow']
|
||||||
|
|
||||||
ModelOptions = Dict[str, Any]
|
WebcamMode = Literal['inline', 'udp', 'v4l2']
|
||||||
ModelSet = Dict[str, ModelOptions]
|
StreamMode = Literal['udp', 'v4l2']
|
||||||
ModelInitializer = NDArray[Any]
|
|
||||||
|
|
||||||
ExecutionProviderKey = Literal['cpu', 'coreml', 'cuda', 'directml', 'openvino', 'rocm', 'tensorrt']
|
ModelOptions : TypeAlias = Dict[str, Any]
|
||||||
|
ModelSet : TypeAlias = Dict[str, ModelOptions]
|
||||||
|
ModelInitializer : TypeAlias = NDArray[Any]
|
||||||
|
|
||||||
|
ExecutionProvider = Literal['cpu', 'coreml', 'cuda', 'directml', 'openvino', 'rocm', 'tensorrt']
|
||||||
ExecutionProviderValue = Literal['CPUExecutionProvider', 'CoreMLExecutionProvider', 'CUDAExecutionProvider', 'DmlExecutionProvider', 'OpenVINOExecutionProvider', 'ROCMExecutionProvider', 'TensorrtExecutionProvider']
|
ExecutionProviderValue = Literal['CPUExecutionProvider', 'CoreMLExecutionProvider', 'CUDAExecutionProvider', 'DmlExecutionProvider', 'OpenVINOExecutionProvider', 'ROCMExecutionProvider', 'TensorrtExecutionProvider']
|
||||||
ExecutionProviderSet = Dict[ExecutionProviderKey, ExecutionProviderValue]
|
ExecutionProviderSet : TypeAlias = Dict[ExecutionProvider, ExecutionProviderValue]
|
||||||
|
InferenceSessionProvider : TypeAlias = Any
|
||||||
ValueAndUnit = TypedDict('ValueAndUnit',
|
ValueAndUnit = TypedDict('ValueAndUnit',
|
||||||
{
|
{
|
||||||
'value' : int,
|
'value' : int,
|
||||||
@@ -140,13 +154,18 @@ ExecutionDeviceProduct = TypedDict('ExecutionDeviceProduct',
|
|||||||
})
|
})
|
||||||
ExecutionDeviceVideoMemory = TypedDict('ExecutionDeviceVideoMemory',
|
ExecutionDeviceVideoMemory = TypedDict('ExecutionDeviceVideoMemory',
|
||||||
{
|
{
|
||||||
'total' : ValueAndUnit,
|
'total' : Optional[ValueAndUnit],
|
||||||
'free' : ValueAndUnit
|
'free' : Optional[ValueAndUnit]
|
||||||
|
})
|
||||||
|
ExecutionDeviceTemperature = TypedDict('ExecutionDeviceTemperature',
|
||||||
|
{
|
||||||
|
'gpu' : Optional[ValueAndUnit],
|
||||||
|
'memory' : Optional[ValueAndUnit]
|
||||||
})
|
})
|
||||||
ExecutionDeviceUtilization = TypedDict('ExecutionDeviceUtilization',
|
ExecutionDeviceUtilization = TypedDict('ExecutionDeviceUtilization',
|
||||||
{
|
{
|
||||||
'gpu' : ValueAndUnit,
|
'gpu' : Optional[ValueAndUnit],
|
||||||
'memory' : ValueAndUnit
|
'memory' : Optional[ValueAndUnit]
|
||||||
})
|
})
|
||||||
ExecutionDevice = TypedDict('ExecutionDevice',
|
ExecutionDevice = TypedDict('ExecutionDevice',
|
||||||
{
|
{
|
||||||
@@ -154,13 +173,30 @@ ExecutionDevice = TypedDict('ExecutionDevice',
|
|||||||
'framework' : ExecutionDeviceFramework,
|
'framework' : ExecutionDeviceFramework,
|
||||||
'product' : ExecutionDeviceProduct,
|
'product' : ExecutionDeviceProduct,
|
||||||
'video_memory' : ExecutionDeviceVideoMemory,
|
'video_memory' : ExecutionDeviceVideoMemory,
|
||||||
|
'temperature': ExecutionDeviceTemperature,
|
||||||
'utilization' : ExecutionDeviceUtilization
|
'utilization' : ExecutionDeviceUtilization
|
||||||
})
|
})
|
||||||
|
|
||||||
|
DownloadProvider = Literal['github', 'huggingface']
|
||||||
|
DownloadProviderValue = TypedDict('DownloadProviderValue',
|
||||||
|
{
|
||||||
|
'urls' : List[str],
|
||||||
|
'path' : str
|
||||||
|
})
|
||||||
|
DownloadProviderSet : TypeAlias = Dict[DownloadProvider, DownloadProviderValue]
|
||||||
|
DownloadScope = Literal['lite', 'full']
|
||||||
|
Download = TypedDict('Download',
|
||||||
|
{
|
||||||
|
'url' : str,
|
||||||
|
'path' : str
|
||||||
|
})
|
||||||
|
DownloadSet : TypeAlias = Dict[str, Download]
|
||||||
|
|
||||||
|
VideoMemoryStrategy = Literal['strict', 'moderate', 'tolerant']
|
||||||
AppContext = Literal['cli', 'ui']
|
AppContext = Literal['cli', 'ui']
|
||||||
|
|
||||||
InferencePool = Dict[str, InferenceSession]
|
InferencePool : TypeAlias = Dict[str, InferenceSession]
|
||||||
InferencePoolSet = Dict[AppContext, Dict[str, InferencePool]]
|
InferencePoolSet : TypeAlias = Dict[AppContext, Dict[str, InferencePool]]
|
||||||
|
|
||||||
UiWorkflow = Literal['instant_runner', 'job_runner', 'job_manager']
|
UiWorkflow = Literal['instant_runner', 'job_runner', 'job_manager']
|
||||||
|
|
||||||
@@ -169,7 +205,7 @@ JobStore = TypedDict('JobStore',
|
|||||||
'job_keys' : List[str],
|
'job_keys' : List[str],
|
||||||
'step_keys' : List[str]
|
'step_keys' : List[str]
|
||||||
})
|
})
|
||||||
JobOutputSet = Dict[str, List[str]]
|
JobOutputSet : TypeAlias = Dict[str, List[str]]
|
||||||
JobStatus = Literal['drafted', 'queued', 'completed', 'failed']
|
JobStatus = Literal['drafted', 'queued', 'completed', 'failed']
|
||||||
JobStepStatus = Literal['drafted', 'queued', 'started', 'completed', 'failed']
|
JobStepStatus = Literal['drafted', 'queued', 'started', 'completed', 'failed']
|
||||||
JobStep = TypedDict('JobStep',
|
JobStep = TypedDict('JobStep',
|
||||||
@@ -184,17 +220,21 @@ Job = TypedDict('Job',
|
|||||||
'date_updated' : Optional[str],
|
'date_updated' : Optional[str],
|
||||||
'steps' : List[JobStep]
|
'steps' : List[JobStep]
|
||||||
})
|
})
|
||||||
JobSet = Dict[str, Job]
|
JobSet : TypeAlias = Dict[str, Job]
|
||||||
|
|
||||||
ApplyStateItem = Callable[[Any, Any], None]
|
ApplyStateItem : TypeAlias = Callable[[Any, Any], None]
|
||||||
StateKey = Literal\
|
StateKey = Literal\
|
||||||
[
|
[
|
||||||
'command',
|
'command',
|
||||||
'config_path',
|
'config_path',
|
||||||
|
'temp_path',
|
||||||
'jobs_path',
|
'jobs_path',
|
||||||
'source_paths',
|
'source_paths',
|
||||||
'target_path',
|
'target_path',
|
||||||
'output_path',
|
'output_path',
|
||||||
|
'source_pattern',
|
||||||
|
'target_pattern',
|
||||||
|
'output_pattern',
|
||||||
'face_detector_model',
|
'face_detector_model',
|
||||||
'face_detector_size',
|
'face_detector_size',
|
||||||
'face_detector_angles',
|
'face_detector_angles',
|
||||||
@@ -210,6 +250,8 @@ StateKey = Literal\
|
|||||||
'reference_face_position',
|
'reference_face_position',
|
||||||
'reference_face_distance',
|
'reference_face_distance',
|
||||||
'reference_frame_number',
|
'reference_frame_number',
|
||||||
|
'face_occluder_model',
|
||||||
|
'face_parser_model',
|
||||||
'face_mask_types',
|
'face_mask_types',
|
||||||
'face_mask_blur',
|
'face_mask_blur',
|
||||||
'face_mask_padding',
|
'face_mask_padding',
|
||||||
@@ -221,12 +263,13 @@ StateKey = Literal\
|
|||||||
'output_image_quality',
|
'output_image_quality',
|
||||||
'output_image_resolution',
|
'output_image_resolution',
|
||||||
'output_audio_encoder',
|
'output_audio_encoder',
|
||||||
|
'output_audio_quality',
|
||||||
|
'output_audio_volume',
|
||||||
'output_video_encoder',
|
'output_video_encoder',
|
||||||
'output_video_preset',
|
'output_video_preset',
|
||||||
'output_video_quality',
|
'output_video_quality',
|
||||||
'output_video_resolution',
|
'output_video_resolution',
|
||||||
'output_video_fps',
|
'output_video_fps',
|
||||||
'skip_audio',
|
|
||||||
'processors',
|
'processors',
|
||||||
'open_browser',
|
'open_browser',
|
||||||
'ui_layouts',
|
'ui_layouts',
|
||||||
@@ -235,10 +278,12 @@ StateKey = Literal\
|
|||||||
'execution_providers',
|
'execution_providers',
|
||||||
'execution_thread_count',
|
'execution_thread_count',
|
||||||
'execution_queue_count',
|
'execution_queue_count',
|
||||||
|
'download_providers',
|
||||||
|
'download_scope',
|
||||||
'video_memory_strategy',
|
'video_memory_strategy',
|
||||||
'system_memory_limit',
|
'system_memory_limit',
|
||||||
'skip_download',
|
|
||||||
'log_level',
|
'log_level',
|
||||||
|
'halt_on_error',
|
||||||
'job_id',
|
'job_id',
|
||||||
'job_status',
|
'job_status',
|
||||||
'step_index'
|
'step_index'
|
||||||
@@ -247,10 +292,14 @@ State = TypedDict('State',
|
|||||||
{
|
{
|
||||||
'command' : str,
|
'command' : str,
|
||||||
'config_path' : str,
|
'config_path' : str,
|
||||||
|
'temp_path' : str,
|
||||||
'jobs_path' : str,
|
'jobs_path' : str,
|
||||||
'source_paths' : List[str],
|
'source_paths' : List[str],
|
||||||
'target_path' : str,
|
'target_path' : str,
|
||||||
'output_path' : str,
|
'output_path' : str,
|
||||||
|
'source_pattern' : str,
|
||||||
|
'target_pattern' : str,
|
||||||
|
'output_pattern' : str,
|
||||||
'face_detector_model' : FaceDetectorModel,
|
'face_detector_model' : FaceDetectorModel,
|
||||||
'face_detector_size' : str,
|
'face_detector_size' : str,
|
||||||
'face_detector_angles' : List[Angle],
|
'face_detector_angles' : List[Angle],
|
||||||
@@ -266,6 +315,8 @@ State = TypedDict('State',
|
|||||||
'reference_face_position' : int,
|
'reference_face_position' : int,
|
||||||
'reference_face_distance' : float,
|
'reference_face_distance' : float,
|
||||||
'reference_frame_number' : int,
|
'reference_frame_number' : int,
|
||||||
|
'face_occluder_model' : FaceOccluderModel,
|
||||||
|
'face_parser_model' : FaceParserModel,
|
||||||
'face_mask_types' : List[FaceMaskType],
|
'face_mask_types' : List[FaceMaskType],
|
||||||
'face_mask_blur' : float,
|
'face_mask_blur' : float,
|
||||||
'face_mask_padding' : Padding,
|
'face_mask_padding' : Padding,
|
||||||
@@ -276,27 +327,31 @@ State = TypedDict('State',
|
|||||||
'keep_temp' : bool,
|
'keep_temp' : bool,
|
||||||
'output_image_quality' : int,
|
'output_image_quality' : int,
|
||||||
'output_image_resolution' : str,
|
'output_image_resolution' : str,
|
||||||
'output_audio_encoder' : OutputAudioEncoder,
|
'output_audio_encoder' : AudioEncoder,
|
||||||
'output_video_encoder' : OutputVideoEncoder,
|
'output_audio_quality' : int,
|
||||||
'output_video_preset' : OutputVideoPreset,
|
'output_audio_volume' : int,
|
||||||
|
'output_video_encoder' : VideoEncoder,
|
||||||
|
'output_video_preset' : VideoPreset,
|
||||||
'output_video_quality' : int,
|
'output_video_quality' : int,
|
||||||
'output_video_resolution' : str,
|
'output_video_resolution' : str,
|
||||||
'output_video_fps' : float,
|
'output_video_fps' : float,
|
||||||
'skip_audio' : bool,
|
|
||||||
'processors' : List[str],
|
'processors' : List[str],
|
||||||
'open_browser' : bool,
|
'open_browser' : bool,
|
||||||
'ui_layouts' : List[str],
|
'ui_layouts' : List[str],
|
||||||
'ui_workflow' : UiWorkflow,
|
'ui_workflow' : UiWorkflow,
|
||||||
'execution_device_id' : str,
|
'execution_device_id' : str,
|
||||||
'execution_providers' : List[ExecutionProviderKey],
|
'execution_providers' : List[ExecutionProvider],
|
||||||
'execution_thread_count' : int,
|
'execution_thread_count' : int,
|
||||||
'execution_queue_count' : int,
|
'execution_queue_count' : int,
|
||||||
|
'download_providers' : List[DownloadProvider],
|
||||||
|
'download_scope' : DownloadScope,
|
||||||
'video_memory_strategy' : VideoMemoryStrategy,
|
'video_memory_strategy' : VideoMemoryStrategy,
|
||||||
'system_memory_limit' : int,
|
'system_memory_limit' : int,
|
||||||
'skip_download' : bool,
|
|
||||||
'log_level' : LogLevel,
|
'log_level' : LogLevel,
|
||||||
|
'halt_on_error' : bool,
|
||||||
'job_id' : str,
|
'job_id' : str,
|
||||||
'job_status' : JobStatus,
|
'job_status' : JobStatus,
|
||||||
'step_index' : int
|
'step_index' : int
|
||||||
})
|
})
|
||||||
StateSet = Dict[AppContext, State]
|
StateSet : TypeAlias = Dict[AppContext, State]
|
||||||
|
|
||||||
@@ -1,12 +1,38 @@
|
|||||||
:root:root:root:root .gradio-container
|
:root:root:root:root .gradio-container
|
||||||
{
|
{
|
||||||
max-width: 110em;
|
|
||||||
overflow: unset;
|
overflow: unset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:root:root:root:root main
|
||||||
|
{
|
||||||
|
max-width: 110em;
|
||||||
|
}
|
||||||
|
|
||||||
:root:root:root:root input[type="number"]
|
:root:root:root:root input[type="number"]
|
||||||
{
|
{
|
||||||
max-width: 6rem;
|
appearance: textfield;
|
||||||
|
border-radius: unset;
|
||||||
|
text-align: center;
|
||||||
|
order: 1;
|
||||||
|
padding: unset
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:root:root:root input[type="number"]::-webkit-inner-spin-button
|
||||||
|
{
|
||||||
|
appearance: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:root:root:root input[type="number"]:focus
|
||||||
|
{
|
||||||
|
outline: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:root:root:root .reset-button
|
||||||
|
{
|
||||||
|
background: var(--background-fill-secondary);
|
||||||
|
border: unset;
|
||||||
|
font-size: unset;
|
||||||
|
padding: unset;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root:root:root:root [type="checkbox"],
|
:root:root:root:root [type="checkbox"],
|
||||||
@@ -17,39 +43,25 @@
|
|||||||
width: 1.125rem;
|
width: 1.125rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root:root:root:root input[type="range"],
|
:root:root:root:root input[type="range"]
|
||||||
:root:root:root:root .range-slider div
|
|
||||||
{
|
{
|
||||||
height: 0.5rem;
|
background: transparent;
|
||||||
border-radius: 0.5rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:root:root:root:root input[type="range"]::-moz-range-thumb,
|
:root:root:root:root input[type="range"]::-moz-range-thumb,
|
||||||
:root:root:root:root input[type="range"]::-webkit-slider-thumb
|
:root:root:root:root input[type="range"]::-webkit-slider-thumb
|
||||||
{
|
{
|
||||||
background: var(--neutral-300);
|
background: var(--neutral-300);
|
||||||
border: unset;
|
box-shadow: unset;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
height: 1.125rem;
|
height: 1.125rem;
|
||||||
width: 1.125rem;
|
width: 1.125rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root:root:root:root input[type="range"]::-webkit-slider-thumb
|
:root:root:root:root .thumbnail-item
|
||||||
{
|
{
|
||||||
margin-top: 0.375rem;
|
border: unset;
|
||||||
}
|
box-shadow: unset;
|
||||||
|
|
||||||
:root:root:root:root .range-slider input[type="range"]::-webkit-slider-thumb
|
|
||||||
{
|
|
||||||
margin-top: 0.125rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
:root:root:root:root .range-slider div,
|
|
||||||
:root:root:root:root .range-slider input[type="range"]
|
|
||||||
{
|
|
||||||
bottom: 50%;
|
|
||||||
margin-top: -0.25rem;
|
|
||||||
top: 50%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:root:root:root:root .grid-wrap.fixed-height
|
:root:root:root:root .grid-wrap.fixed-height
|
||||||
@@ -57,27 +69,67 @@
|
|||||||
min-height: unset;
|
min-height: unset;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root:root:root:root .generating,
|
:root:root:root:root .box-face-selector .empty,
|
||||||
:root:root:root:root .thumbnail-item
|
:root:root:root:root .box-face-selector .gallery-container
|
||||||
{
|
{
|
||||||
border: unset;
|
min-height: 7.375rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:root:root:root:root .tab-wrapper
|
||||||
|
{
|
||||||
|
padding: 0 0.625rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:root:root:root .tab-container
|
||||||
|
{
|
||||||
|
gap: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:root:root:root .tab-container button
|
||||||
|
{
|
||||||
|
background: unset;
|
||||||
|
border-bottom: 0.125rem solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:root:root:root .tab-container button.selected
|
||||||
|
{
|
||||||
|
color: var(--primary-500)
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:root:root:root .toast-body
|
||||||
|
{
|
||||||
|
background: white;
|
||||||
|
color: var(--primary-500);
|
||||||
|
border: unset;
|
||||||
|
border-radius: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:root:root:root .dark .toast-body
|
||||||
|
{
|
||||||
|
background: var(--neutral-900);
|
||||||
|
color: var(--primary-600);
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:root:root:root .toast-icon,
|
||||||
|
:root:root:root:root .toast-title,
|
||||||
|
:root:root:root:root .toast-text,
|
||||||
|
:root:root:root:root .toast-close
|
||||||
|
{
|
||||||
|
color: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:root:root:root .toast-body .timer
|
||||||
|
{
|
||||||
|
background: currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:root:root:root .slider_input_container > span,
|
||||||
:root:root:root:root .feather-upload,
|
:root:root:root:root .feather-upload,
|
||||||
:root:root:root:root footer
|
:root:root:root:root footer
|
||||||
{
|
{
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root:root:root:root .tab-nav > button
|
|
||||||
{
|
|
||||||
border: unset;
|
|
||||||
box-shadow: 0 0.125rem;
|
|
||||||
font-size: 1.125em;
|
|
||||||
margin: 0.5rem 0.75rem;
|
|
||||||
padding: unset;
|
|
||||||
}
|
|
||||||
|
|
||||||
:root:root:root:root .image-frame
|
:root:root:root:root .image-frame
|
||||||
{
|
{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -94,3 +146,11 @@
|
|||||||
top: 0;
|
top: 0;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:root:root:root:root .block .error
|
||||||
|
{
|
||||||
|
border: 0.125rem solid;
|
||||||
|
padding: 0.375rem 0.75rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from facefusion.uis.typing import JobManagerAction, JobRunnerAction, WebcamMode
|
from facefusion.uis.types import JobManagerAction, JobRunnerAction
|
||||||
|
|
||||||
job_manager_actions : List[JobManagerAction] = [ 'job-create', 'job-submit', 'job-delete', 'job-add-step', 'job-remix-step', 'job-insert-step', 'job-remove-step' ]
|
job_manager_actions : List[JobManagerAction] = [ 'job-create', 'job-submit', 'job-delete', 'job-add-step', 'job-remix-step', 'job-insert-step', 'job-remove-step' ]
|
||||||
job_runner_actions : List[JobRunnerAction] = [ 'job-run', 'job-run-all', 'job-retry', 'job-retry-all' ]
|
job_runner_actions : List[JobRunnerAction] = [ 'job-run', 'job-run-all', 'job-retry', 'job-retry-all' ]
|
||||||
|
|
||||||
common_options : List[str] = [ 'keep-temp', 'skip-audio', 'skip-download' ]
|
common_options : List[str] = [ 'keep-temp' ]
|
||||||
|
|
||||||
webcam_modes : List[WebcamMode] = [ 'inline', 'udp', 'v4l2' ]
|
|
||||||
webcam_resolutions : List[str] = [ '320x240', '640x480', '800x600', '1024x768', '1280x720', '1280x960', '1920x1080', '2560x1440', '3840x2160' ]
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from facefusion import state_manager, wording
|
|||||||
from facefusion.common_helper import calc_float_step
|
from facefusion.common_helper import calc_float_step
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.core import load_processor_module
|
from facefusion.processors.core import load_processor_module
|
||||||
from facefusion.processors.typing import AgeModifierModel
|
from facefusion.processors.types import AgeModifierModel
|
||||||
from facefusion.uis.core import get_ui_component, register_ui_component
|
from facefusion.uis.core import get_ui_component, register_ui_component
|
||||||
|
|
||||||
AGE_MODIFIER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
AGE_MODIFIER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
@@ -17,11 +17,12 @@ def render() -> None:
|
|||||||
global AGE_MODIFIER_MODEL_DROPDOWN
|
global AGE_MODIFIER_MODEL_DROPDOWN
|
||||||
global AGE_MODIFIER_DIRECTION_SLIDER
|
global AGE_MODIFIER_DIRECTION_SLIDER
|
||||||
|
|
||||||
|
has_age_modifier = 'age_modifier' in state_manager.get_item('processors')
|
||||||
AGE_MODIFIER_MODEL_DROPDOWN = gradio.Dropdown(
|
AGE_MODIFIER_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.age_modifier_model_dropdown'),
|
label = wording.get('uis.age_modifier_model_dropdown'),
|
||||||
choices = processors_choices.age_modifier_models,
|
choices = processors_choices.age_modifier_models,
|
||||||
value = state_manager.get_item('age_modifier_model'),
|
value = state_manager.get_item('age_modifier_model'),
|
||||||
visible = 'age_modifier' in state_manager.get_item('processors')
|
visible = has_age_modifier
|
||||||
)
|
)
|
||||||
AGE_MODIFIER_DIRECTION_SLIDER = gradio.Slider(
|
AGE_MODIFIER_DIRECTION_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.age_modifier_direction_slider'),
|
label = wording.get('uis.age_modifier_direction_slider'),
|
||||||
@@ -29,7 +30,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.age_modifier_direction_range),
|
step = calc_float_step(processors_choices.age_modifier_direction_range),
|
||||||
minimum = processors_choices.age_modifier_direction_range[0],
|
minimum = processors_choices.age_modifier_direction_range[0],
|
||||||
maximum = processors_choices.age_modifier_direction_range[-1],
|
maximum = processors_choices.age_modifier_direction_range[-1],
|
||||||
visible = 'age_modifier' in state_manager.get_item('processors')
|
visible = has_age_modifier
|
||||||
)
|
)
|
||||||
register_ui_component('age_modifier_model_dropdown', AGE_MODIFIER_MODEL_DROPDOWN)
|
register_ui_component('age_modifier_model_dropdown', AGE_MODIFIER_MODEL_DROPDOWN)
|
||||||
register_ui_component('age_modifier_direction_slider', AGE_MODIFIER_DIRECTION_SLIDER)
|
register_ui_component('age_modifier_direction_slider', AGE_MODIFIER_DIRECTION_SLIDER)
|
||||||
|
|||||||
@@ -9,14 +9,13 @@ import gradio
|
|||||||
|
|
||||||
from facefusion import state_manager, wording
|
from facefusion import state_manager, wording
|
||||||
from facefusion.core import conditional_process
|
from facefusion.core import conditional_process
|
||||||
from facefusion.filesystem import is_video
|
from facefusion.filesystem import get_file_extension, is_video
|
||||||
from facefusion.memory import limit_system_memory
|
from facefusion.memory import limit_system_memory
|
||||||
from facefusion.uis.core import get_ui_component
|
from facefusion.uis.core import get_ui_component
|
||||||
from facefusion.vision import count_video_frame_total, detect_video_fps, detect_video_resolution, pack_resolution
|
from facefusion.vision import count_video_frame_total, detect_video_fps, detect_video_resolution, pack_resolution
|
||||||
|
|
||||||
BENCHMARK_BENCHMARKS_DATAFRAME : Optional[gradio.Dataframe] = None
|
BENCHMARK_BENCHMARKS_DATAFRAME : Optional[gradio.Dataframe] = None
|
||||||
BENCHMARK_START_BUTTON : Optional[gradio.Button] = None
|
BENCHMARK_START_BUTTON : Optional[gradio.Button] = None
|
||||||
BENCHMARK_CLEAR_BUTTON : Optional[gradio.Button] = None
|
|
||||||
BENCHMARKS : Dict[str, str] =\
|
BENCHMARKS : Dict[str, str] =\
|
||||||
{
|
{
|
||||||
'240p': '.assets/examples/target-240p.mp4',
|
'240p': '.assets/examples/target-240p.mp4',
|
||||||
@@ -32,7 +31,6 @@ BENCHMARKS : Dict[str, str] =\
|
|||||||
def render() -> None:
|
def render() -> None:
|
||||||
global BENCHMARK_BENCHMARKS_DATAFRAME
|
global BENCHMARK_BENCHMARKS_DATAFRAME
|
||||||
global BENCHMARK_START_BUTTON
|
global BENCHMARK_START_BUTTON
|
||||||
global BENCHMARK_CLEAR_BUTTON
|
|
||||||
|
|
||||||
BENCHMARK_BENCHMARKS_DATAFRAME = gradio.Dataframe(
|
BENCHMARK_BENCHMARKS_DATAFRAME = gradio.Dataframe(
|
||||||
headers =
|
headers =
|
||||||
@@ -72,8 +70,8 @@ def listen() -> None:
|
|||||||
|
|
||||||
def suggest_output_path(target_path : str) -> Optional[str]:
|
def suggest_output_path(target_path : str) -> Optional[str]:
|
||||||
if is_video(target_path):
|
if is_video(target_path):
|
||||||
_, target_extension = os.path.splitext(target_path)
|
target_file_extension = get_file_extension(target_path)
|
||||||
return os.path.join(tempfile.gettempdir(), hashlib.sha1().hexdigest()[:8] + target_extension)
|
return os.path.join(tempfile.gettempdir(), hashlib.sha1().hexdigest()[:8] + target_file_extension)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -81,8 +79,8 @@ def start(benchmark_runs : List[str], benchmark_cycles : int) -> Generator[List[
|
|||||||
state_manager.init_item('source_paths', [ '.assets/examples/source.jpg', '.assets/examples/source.mp3' ])
|
state_manager.init_item('source_paths', [ '.assets/examples/source.jpg', '.assets/examples/source.mp3' ])
|
||||||
state_manager.init_item('face_landmarker_score', 0)
|
state_manager.init_item('face_landmarker_score', 0)
|
||||||
state_manager.init_item('temp_frame_format', 'bmp')
|
state_manager.init_item('temp_frame_format', 'bmp')
|
||||||
|
state_manager.init_item('output_audio_volume', 0)
|
||||||
state_manager.init_item('output_video_preset', 'ultrafast')
|
state_manager.init_item('output_video_preset', 'ultrafast')
|
||||||
state_manager.init_item('skip_audio', True)
|
|
||||||
state_manager.sync_item('execution_providers')
|
state_manager.sync_item('execution_providers')
|
||||||
state_manager.sync_item('execution_thread_count')
|
state_manager.sync_item('execution_thread_count')
|
||||||
state_manager.sync_item('execution_queue_count')
|
state_manager.sync_item('execution_queue_count')
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ def render() -> None:
|
|||||||
|
|
||||||
BENCHMARK_RUNS_CHECKBOX_GROUP = gradio.CheckboxGroup(
|
BENCHMARK_RUNS_CHECKBOX_GROUP = gradio.CheckboxGroup(
|
||||||
label = wording.get('uis.benchmark_runs_checkbox_group'),
|
label = wording.get('uis.benchmark_runs_checkbox_group'),
|
||||||
value = list(BENCHMARKS.keys()),
|
choices = list(BENCHMARKS.keys()),
|
||||||
choices = list(BENCHMARKS.keys())
|
value = list(BENCHMARKS.keys())
|
||||||
)
|
)
|
||||||
BENCHMARK_CYCLES_SLIDER = gradio.Slider(
|
BENCHMARK_CYCLES_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.benchmark_cycles_slider'),
|
label = wording.get('uis.benchmark_cycles_slider'),
|
||||||
|
|||||||
@@ -13,12 +13,8 @@ def render() -> None:
|
|||||||
|
|
||||||
common_options = []
|
common_options = []
|
||||||
|
|
||||||
if state_manager.get_item('skip_download'):
|
|
||||||
common_options.append('skip-download')
|
|
||||||
if state_manager.get_item('keep_temp'):
|
if state_manager.get_item('keep_temp'):
|
||||||
common_options.append('keep-temp')
|
common_options.append('keep-temp')
|
||||||
if state_manager.get_item('skip_audio'):
|
|
||||||
common_options.append('skip-audio')
|
|
||||||
|
|
||||||
COMMON_OPTIONS_CHECKBOX_GROUP = gradio.Checkboxgroup(
|
COMMON_OPTIONS_CHECKBOX_GROUP = gradio.Checkboxgroup(
|
||||||
label = wording.get('uis.common_options_checkbox_group'),
|
label = wording.get('uis.common_options_checkbox_group'),
|
||||||
@@ -32,9 +28,5 @@ def listen() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def update(common_options : List[str]) -> None:
|
def update(common_options : List[str]) -> None:
|
||||||
skip_temp = 'skip-download' in common_options
|
|
||||||
keep_temp = 'keep-temp' in common_options
|
keep_temp = 'keep-temp' in common_options
|
||||||
skip_audio = 'skip-audio' in common_options
|
|
||||||
state_manager.set_item('skip_download', skip_temp)
|
|
||||||
state_manager.set_item('keep_temp', keep_temp)
|
state_manager.set_item('keep_temp', keep_temp)
|
||||||
state_manager.set_item('skip_audio', skip_audio)
|
|
||||||
|
|||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
from typing import List, Optional, Tuple
|
||||||
|
|
||||||
|
import gradio
|
||||||
|
|
||||||
|
from facefusion import state_manager, wording
|
||||||
|
from facefusion.common_helper import calc_int_step
|
||||||
|
from facefusion.processors import choices as processors_choices
|
||||||
|
from facefusion.processors.core import load_processor_module
|
||||||
|
from facefusion.processors.types import DeepSwapperModel
|
||||||
|
from facefusion.uis.core import get_ui_component, register_ui_component
|
||||||
|
|
||||||
|
DEEP_SWAPPER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
|
DEEP_SWAPPER_MORPH_SLIDER : Optional[gradio.Slider] = None
|
||||||
|
|
||||||
|
|
||||||
|
def render() -> None:
|
||||||
|
global DEEP_SWAPPER_MODEL_DROPDOWN
|
||||||
|
global DEEP_SWAPPER_MORPH_SLIDER
|
||||||
|
|
||||||
|
has_deep_swapper = 'deep_swapper' in state_manager.get_item('processors')
|
||||||
|
DEEP_SWAPPER_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
|
label = wording.get('uis.deep_swapper_model_dropdown'),
|
||||||
|
choices = processors_choices.deep_swapper_models,
|
||||||
|
value = state_manager.get_item('deep_swapper_model'),
|
||||||
|
visible = has_deep_swapper
|
||||||
|
)
|
||||||
|
DEEP_SWAPPER_MORPH_SLIDER = gradio.Slider(
|
||||||
|
label = wording.get('uis.deep_swapper_morph_slider'),
|
||||||
|
value = state_manager.get_item('deep_swapper_morph'),
|
||||||
|
step = calc_int_step(processors_choices.deep_swapper_morph_range),
|
||||||
|
minimum = processors_choices.deep_swapper_morph_range[0],
|
||||||
|
maximum = processors_choices.deep_swapper_morph_range[-1],
|
||||||
|
visible = has_deep_swapper and load_processor_module('deep_swapper').get_inference_pool() and load_processor_module('deep_swapper').has_morph_input()
|
||||||
|
)
|
||||||
|
register_ui_component('deep_swapper_model_dropdown', DEEP_SWAPPER_MODEL_DROPDOWN)
|
||||||
|
register_ui_component('deep_swapper_morph_slider', DEEP_SWAPPER_MORPH_SLIDER)
|
||||||
|
|
||||||
|
|
||||||
|
def listen() -> None:
|
||||||
|
DEEP_SWAPPER_MODEL_DROPDOWN.change(update_deep_swapper_model, inputs = DEEP_SWAPPER_MODEL_DROPDOWN, outputs = [ DEEP_SWAPPER_MODEL_DROPDOWN, DEEP_SWAPPER_MORPH_SLIDER ])
|
||||||
|
DEEP_SWAPPER_MORPH_SLIDER.release(update_deep_swapper_morph, inputs = DEEP_SWAPPER_MORPH_SLIDER)
|
||||||
|
|
||||||
|
processors_checkbox_group = get_ui_component('processors_checkbox_group')
|
||||||
|
if processors_checkbox_group:
|
||||||
|
processors_checkbox_group.change(remote_update, inputs = processors_checkbox_group, outputs = [ DEEP_SWAPPER_MODEL_DROPDOWN, DEEP_SWAPPER_MORPH_SLIDER ])
|
||||||
|
|
||||||
|
|
||||||
|
def remote_update(processors : List[str]) -> Tuple[gradio.Dropdown, gradio.Slider]:
|
||||||
|
has_deep_swapper = 'deep_swapper' in processors
|
||||||
|
return gradio.Dropdown(visible = has_deep_swapper), gradio.Slider(visible = has_deep_swapper and load_processor_module('deep_swapper').get_inference_pool() and load_processor_module('deep_swapper').has_morph_input())
|
||||||
|
|
||||||
|
|
||||||
|
def update_deep_swapper_model(deep_swapper_model : DeepSwapperModel) -> Tuple[gradio.Dropdown, gradio.Slider]:
|
||||||
|
deep_swapper_module = load_processor_module('deep_swapper')
|
||||||
|
deep_swapper_module.clear_inference_pool()
|
||||||
|
state_manager.set_item('deep_swapper_model', deep_swapper_model)
|
||||||
|
|
||||||
|
if deep_swapper_module.pre_check():
|
||||||
|
return gradio.Dropdown(value = state_manager.get_item('deep_swapper_model')), gradio.Slider(visible = deep_swapper_module.has_morph_input())
|
||||||
|
return gradio.Dropdown(), gradio.Slider()
|
||||||
|
|
||||||
|
|
||||||
|
def update_deep_swapper_morph(deep_swapper_morph : int) -> None:
|
||||||
|
state_manager.set_item('deep_swapper_morph', deep_swapper_morph)
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
import gradio
|
||||||
|
|
||||||
|
import facefusion.choices
|
||||||
|
from facefusion import content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, state_manager, voice_extractor, wording
|
||||||
|
from facefusion.filesystem import get_file_name, resolve_file_paths
|
||||||
|
from facefusion.processors.core import get_processors_modules
|
||||||
|
from facefusion.types import DownloadProvider
|
||||||
|
|
||||||
|
DOWNLOAD_PROVIDERS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
||||||
|
|
||||||
|
|
||||||
|
def render() -> None:
|
||||||
|
global DOWNLOAD_PROVIDERS_CHECKBOX_GROUP
|
||||||
|
|
||||||
|
DOWNLOAD_PROVIDERS_CHECKBOX_GROUP = gradio.CheckboxGroup(
|
||||||
|
label = wording.get('uis.download_providers_checkbox_group'),
|
||||||
|
choices = facefusion.choices.download_providers,
|
||||||
|
value = state_manager.get_item('download_providers')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def listen() -> None:
|
||||||
|
DOWNLOAD_PROVIDERS_CHECKBOX_GROUP.change(update_download_providers, inputs = DOWNLOAD_PROVIDERS_CHECKBOX_GROUP, outputs = DOWNLOAD_PROVIDERS_CHECKBOX_GROUP)
|
||||||
|
|
||||||
|
|
||||||
|
def update_download_providers(download_providers : List[DownloadProvider]) -> gradio.CheckboxGroup:
|
||||||
|
common_modules =\
|
||||||
|
[
|
||||||
|
content_analyser,
|
||||||
|
face_classifier,
|
||||||
|
face_detector,
|
||||||
|
face_landmarker,
|
||||||
|
face_recognizer,
|
||||||
|
face_masker,
|
||||||
|
voice_extractor
|
||||||
|
]
|
||||||
|
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
||||||
|
processor_modules = get_processors_modules(available_processors)
|
||||||
|
|
||||||
|
for module in common_modules + processor_modules:
|
||||||
|
if hasattr(module, 'create_static_model_set'):
|
||||||
|
module.create_static_model_set.cache_clear()
|
||||||
|
|
||||||
|
download_providers = download_providers or facefusion.choices.download_providers
|
||||||
|
state_manager.set_item('download_providers', download_providers)
|
||||||
|
return gradio.CheckboxGroup(value = state_manager.get_item('download_providers'))
|
||||||
@@ -3,9 +3,10 @@ from typing import List, Optional
|
|||||||
import gradio
|
import gradio
|
||||||
|
|
||||||
from facefusion import content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, state_manager, voice_extractor, wording
|
from facefusion import content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, state_manager, voice_extractor, wording
|
||||||
from facefusion.execution import get_execution_provider_choices
|
from facefusion.execution import get_available_execution_providers
|
||||||
from facefusion.processors.core import clear_processors_modules
|
from facefusion.filesystem import get_file_name, resolve_file_paths
|
||||||
from facefusion.typing import ExecutionProviderKey
|
from facefusion.processors.core import get_processors_modules
|
||||||
|
from facefusion.types import ExecutionProvider
|
||||||
|
|
||||||
EXECUTION_PROVIDERS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
EXECUTION_PROVIDERS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ def render() -> None:
|
|||||||
|
|
||||||
EXECUTION_PROVIDERS_CHECKBOX_GROUP = gradio.CheckboxGroup(
|
EXECUTION_PROVIDERS_CHECKBOX_GROUP = gradio.CheckboxGroup(
|
||||||
label = wording.get('uis.execution_providers_checkbox_group'),
|
label = wording.get('uis.execution_providers_checkbox_group'),
|
||||||
choices = get_execution_provider_choices(),
|
choices = get_available_execution_providers(),
|
||||||
value = state_manager.get_item('execution_providers')
|
value = state_manager.get_item('execution_providers')
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,15 +25,24 @@ def listen() -> None:
|
|||||||
EXECUTION_PROVIDERS_CHECKBOX_GROUP.change(update_execution_providers, inputs = EXECUTION_PROVIDERS_CHECKBOX_GROUP, outputs = EXECUTION_PROVIDERS_CHECKBOX_GROUP)
|
EXECUTION_PROVIDERS_CHECKBOX_GROUP.change(update_execution_providers, inputs = EXECUTION_PROVIDERS_CHECKBOX_GROUP, outputs = EXECUTION_PROVIDERS_CHECKBOX_GROUP)
|
||||||
|
|
||||||
|
|
||||||
def update_execution_providers(execution_providers : List[ExecutionProviderKey]) -> gradio.CheckboxGroup:
|
def update_execution_providers(execution_providers : List[ExecutionProvider]) -> gradio.CheckboxGroup:
|
||||||
content_analyser.clear_inference_pool()
|
common_modules =\
|
||||||
face_classifier.clear_inference_pool()
|
[
|
||||||
face_detector.clear_inference_pool()
|
content_analyser,
|
||||||
face_landmarker.clear_inference_pool()
|
face_classifier,
|
||||||
face_masker.clear_inference_pool()
|
face_detector,
|
||||||
face_recognizer.clear_inference_pool()
|
face_landmarker,
|
||||||
voice_extractor.clear_inference_pool()
|
face_masker,
|
||||||
clear_processors_modules(state_manager.get_item('processors'))
|
face_recognizer,
|
||||||
execution_providers = execution_providers or get_execution_provider_choices()
|
voice_extractor
|
||||||
|
]
|
||||||
|
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
||||||
|
processor_modules = get_processors_modules(available_processors)
|
||||||
|
|
||||||
|
for module in common_modules + processor_modules:
|
||||||
|
if hasattr(module, 'clear_inference_pool'):
|
||||||
|
module.clear_inference_pool()
|
||||||
|
|
||||||
|
execution_providers = execution_providers or get_available_execution_providers()
|
||||||
state_manager.set_item('execution_providers', execution_providers)
|
state_manager.set_item('execution_providers', execution_providers)
|
||||||
return gradio.CheckboxGroup(value = state_manager.get_item('execution_providers'))
|
return gradio.CheckboxGroup(value = state_manager.get_item('execution_providers'))
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from facefusion import state_manager, wording
|
|||||||
from facefusion.common_helper import calc_float_step
|
from facefusion.common_helper import calc_float_step
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.core import load_processor_module
|
from facefusion.processors.core import load_processor_module
|
||||||
from facefusion.processors.typing import ExpressionRestorerModel
|
from facefusion.processors.types import ExpressionRestorerModel
|
||||||
from facefusion.uis.core import get_ui_component, register_ui_component
|
from facefusion.uis.core import get_ui_component, register_ui_component
|
||||||
|
|
||||||
EXPRESSION_RESTORER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
EXPRESSION_RESTORER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
@@ -17,11 +17,12 @@ def render() -> None:
|
|||||||
global EXPRESSION_RESTORER_MODEL_DROPDOWN
|
global EXPRESSION_RESTORER_MODEL_DROPDOWN
|
||||||
global EXPRESSION_RESTORER_FACTOR_SLIDER
|
global EXPRESSION_RESTORER_FACTOR_SLIDER
|
||||||
|
|
||||||
|
has_expression_restorer = 'expression_restorer' in state_manager.get_item('processors')
|
||||||
EXPRESSION_RESTORER_MODEL_DROPDOWN = gradio.Dropdown(
|
EXPRESSION_RESTORER_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.expression_restorer_model_dropdown'),
|
label = wording.get('uis.expression_restorer_model_dropdown'),
|
||||||
choices = processors_choices.expression_restorer_models,
|
choices = processors_choices.expression_restorer_models,
|
||||||
value = state_manager.get_item('expression_restorer_model'),
|
value = state_manager.get_item('expression_restorer_model'),
|
||||||
visible = 'expression_restorer' in state_manager.get_item('processors')
|
visible = has_expression_restorer
|
||||||
)
|
)
|
||||||
EXPRESSION_RESTORER_FACTOR_SLIDER = gradio.Slider(
|
EXPRESSION_RESTORER_FACTOR_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.expression_restorer_factor_slider'),
|
label = wording.get('uis.expression_restorer_factor_slider'),
|
||||||
@@ -29,7 +30,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.expression_restorer_factor_range),
|
step = calc_float_step(processors_choices.expression_restorer_factor_range),
|
||||||
minimum = processors_choices.expression_restorer_factor_range[0],
|
minimum = processors_choices.expression_restorer_factor_range[0],
|
||||||
maximum = processors_choices.expression_restorer_factor_range[-1],
|
maximum = processors_choices.expression_restorer_factor_range[-1],
|
||||||
visible = 'expression_restorer' in state_manager.get_item('processors'),
|
visible = has_expression_restorer
|
||||||
)
|
)
|
||||||
register_ui_component('expression_restorer_model_dropdown', EXPRESSION_RESTORER_MODEL_DROPDOWN)
|
register_ui_component('expression_restorer_model_dropdown', EXPRESSION_RESTORER_MODEL_DROPDOWN)
|
||||||
register_ui_component('expression_restorer_factor_slider', EXPRESSION_RESTORER_FACTOR_SLIDER)
|
register_ui_component('expression_restorer_factor_slider', EXPRESSION_RESTORER_FACTOR_SLIDER)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import gradio
|
|||||||
|
|
||||||
from facefusion import state_manager, wording
|
from facefusion import state_manager, wording
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.typing import FaceDebuggerItem
|
from facefusion.processors.types import FaceDebuggerItem
|
||||||
from facefusion.uis.core import get_ui_component, register_ui_component
|
from facefusion.uis.core import get_ui_component, register_ui_component
|
||||||
|
|
||||||
FACE_DEBUGGER_ITEMS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
FACE_DEBUGGER_ITEMS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
||||||
@@ -13,11 +13,12 @@ FACE_DEBUGGER_ITEMS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
|||||||
def render() -> None:
|
def render() -> None:
|
||||||
global FACE_DEBUGGER_ITEMS_CHECKBOX_GROUP
|
global FACE_DEBUGGER_ITEMS_CHECKBOX_GROUP
|
||||||
|
|
||||||
|
has_face_debugger = 'face_debugger' in state_manager.get_item('processors')
|
||||||
FACE_DEBUGGER_ITEMS_CHECKBOX_GROUP = gradio.CheckboxGroup(
|
FACE_DEBUGGER_ITEMS_CHECKBOX_GROUP = gradio.CheckboxGroup(
|
||||||
label = wording.get('uis.face_debugger_items_checkbox_group'),
|
label = wording.get('uis.face_debugger_items_checkbox_group'),
|
||||||
choices = processors_choices.face_debugger_items,
|
choices = processors_choices.face_debugger_items,
|
||||||
value = state_manager.get_item('face_debugger_items'),
|
value = state_manager.get_item('face_debugger_items'),
|
||||||
visible = 'face_debugger' in state_manager.get_item('processors')
|
visible = has_face_debugger
|
||||||
)
|
)
|
||||||
register_ui_component('face_debugger_items_checkbox_group', FACE_DEBUGGER_ITEMS_CHECKBOX_GROUP)
|
register_ui_component('face_debugger_items_checkbox_group', FACE_DEBUGGER_ITEMS_CHECKBOX_GROUP)
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ from typing import Optional, Sequence, Tuple
|
|||||||
import gradio
|
import gradio
|
||||||
|
|
||||||
import facefusion.choices
|
import facefusion.choices
|
||||||
from facefusion import choices, face_detector, state_manager, wording
|
from facefusion import face_detector, state_manager, wording
|
||||||
from facefusion.common_helper import calc_float_step, get_last
|
from facefusion.common_helper import calc_float_step, get_last
|
||||||
from facefusion.typing import Angle, FaceDetectorModel, Score
|
from facefusion.types import Angle, FaceDetectorModel, Score
|
||||||
from facefusion.uis.core import register_ui_component
|
from facefusion.uis.core import register_ui_component
|
||||||
from facefusion.uis.typing import ComponentOptions
|
from facefusion.uis.types import ComponentOptions
|
||||||
|
|
||||||
FACE_DETECTOR_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
FACE_DETECTOR_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
FACE_DETECTOR_SIZE_DROPDOWN : Optional[gradio.Dropdown] = None
|
FACE_DETECTOR_SIZE_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
@@ -31,7 +31,7 @@ def render() -> None:
|
|||||||
with gradio.Row():
|
with gradio.Row():
|
||||||
FACE_DETECTOR_MODEL_DROPDOWN = gradio.Dropdown(
|
FACE_DETECTOR_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.face_detector_model_dropdown'),
|
label = wording.get('uis.face_detector_model_dropdown'),
|
||||||
choices = facefusion.choices.face_detector_set.keys(),
|
choices = facefusion.choices.face_detector_models,
|
||||||
value = state_manager.get_item('face_detector_model')
|
value = state_manager.get_item('face_detector_model')
|
||||||
)
|
)
|
||||||
FACE_DETECTOR_SIZE_DROPDOWN = gradio.Dropdown(**face_detector_size_dropdown_options)
|
FACE_DETECTOR_SIZE_DROPDOWN = gradio.Dropdown(**face_detector_size_dropdown_options)
|
||||||
@@ -65,7 +65,7 @@ def update_face_detector_model(face_detector_model : FaceDetectorModel) -> Tuple
|
|||||||
state_manager.set_item('face_detector_model', face_detector_model)
|
state_manager.set_item('face_detector_model', face_detector_model)
|
||||||
|
|
||||||
if face_detector.pre_check():
|
if face_detector.pre_check():
|
||||||
face_detector_size_choices = choices.face_detector_set.get(state_manager.get_item('face_detector_model'))
|
face_detector_size_choices = facefusion.choices.face_detector_set.get(state_manager.get_item('face_detector_model'))
|
||||||
state_manager.set_item('face_detector_size', get_last(face_detector_size_choices))
|
state_manager.set_item('face_detector_size', get_last(face_detector_size_choices))
|
||||||
return gradio.Dropdown(value = state_manager.get_item('face_detector_model')), gradio.Dropdown(value = state_manager.get_item('face_detector_size'), choices = face_detector_size_choices)
|
return gradio.Dropdown(value = state_manager.get_item('face_detector_model')), gradio.Dropdown(value = state_manager.get_item('face_detector_size'), choices = face_detector_size_choices)
|
||||||
return gradio.Dropdown(), gradio.Dropdown()
|
return gradio.Dropdown(), gradio.Dropdown()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from facefusion import state_manager, wording
|
|||||||
from facefusion.common_helper import calc_float_step
|
from facefusion.common_helper import calc_float_step
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.core import load_processor_module
|
from facefusion.processors.core import load_processor_module
|
||||||
from facefusion.processors.typing import FaceEditorModel
|
from facefusion.processors.types import FaceEditorModel
|
||||||
from facefusion.uis.core import get_ui_component, register_ui_component
|
from facefusion.uis.core import get_ui_component, register_ui_component
|
||||||
|
|
||||||
FACE_EDITOR_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
FACE_EDITOR_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
@@ -43,11 +43,12 @@ def render() -> None:
|
|||||||
global FACE_EDITOR_HEAD_YAW_SLIDER
|
global FACE_EDITOR_HEAD_YAW_SLIDER
|
||||||
global FACE_EDITOR_HEAD_ROLL_SLIDER
|
global FACE_EDITOR_HEAD_ROLL_SLIDER
|
||||||
|
|
||||||
|
has_face_editor = 'face_editor' in state_manager.get_item('processors')
|
||||||
FACE_EDITOR_MODEL_DROPDOWN = gradio.Dropdown(
|
FACE_EDITOR_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.face_editor_model_dropdown'),
|
label = wording.get('uis.face_editor_model_dropdown'),
|
||||||
choices = processors_choices.face_editor_models,
|
choices = processors_choices.face_editor_models,
|
||||||
value = state_manager.get_item('face_editor_model'),
|
value = state_manager.get_item('face_editor_model'),
|
||||||
visible = 'face_editor' in state_manager.get_item('processors')
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_EYEBROW_DIRECTION_SLIDER = gradio.Slider(
|
FACE_EDITOR_EYEBROW_DIRECTION_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_eyebrow_direction_slider'),
|
label = wording.get('uis.face_editor_eyebrow_direction_slider'),
|
||||||
@@ -55,7 +56,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_eyebrow_direction_range),
|
step = calc_float_step(processors_choices.face_editor_eyebrow_direction_range),
|
||||||
minimum = processors_choices.face_editor_eyebrow_direction_range[0],
|
minimum = processors_choices.face_editor_eyebrow_direction_range[0],
|
||||||
maximum = processors_choices.face_editor_eyebrow_direction_range[-1],
|
maximum = processors_choices.face_editor_eyebrow_direction_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_EYE_GAZE_HORIZONTAL_SLIDER = gradio.Slider(
|
FACE_EDITOR_EYE_GAZE_HORIZONTAL_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_eye_gaze_horizontal_slider'),
|
label = wording.get('uis.face_editor_eye_gaze_horizontal_slider'),
|
||||||
@@ -63,7 +64,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_eye_gaze_horizontal_range),
|
step = calc_float_step(processors_choices.face_editor_eye_gaze_horizontal_range),
|
||||||
minimum = processors_choices.face_editor_eye_gaze_horizontal_range[0],
|
minimum = processors_choices.face_editor_eye_gaze_horizontal_range[0],
|
||||||
maximum = processors_choices.face_editor_eye_gaze_horizontal_range[-1],
|
maximum = processors_choices.face_editor_eye_gaze_horizontal_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_EYE_GAZE_VERTICAL_SLIDER = gradio.Slider(
|
FACE_EDITOR_EYE_GAZE_VERTICAL_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_eye_gaze_vertical_slider'),
|
label = wording.get('uis.face_editor_eye_gaze_vertical_slider'),
|
||||||
@@ -71,7 +72,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_eye_gaze_vertical_range),
|
step = calc_float_step(processors_choices.face_editor_eye_gaze_vertical_range),
|
||||||
minimum = processors_choices.face_editor_eye_gaze_vertical_range[0],
|
minimum = processors_choices.face_editor_eye_gaze_vertical_range[0],
|
||||||
maximum = processors_choices.face_editor_eye_gaze_vertical_range[-1],
|
maximum = processors_choices.face_editor_eye_gaze_vertical_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_EYE_OPEN_RATIO_SLIDER = gradio.Slider(
|
FACE_EDITOR_EYE_OPEN_RATIO_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_eye_open_ratio_slider'),
|
label = wording.get('uis.face_editor_eye_open_ratio_slider'),
|
||||||
@@ -79,7 +80,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_eye_open_ratio_range),
|
step = calc_float_step(processors_choices.face_editor_eye_open_ratio_range),
|
||||||
minimum = processors_choices.face_editor_eye_open_ratio_range[0],
|
minimum = processors_choices.face_editor_eye_open_ratio_range[0],
|
||||||
maximum = processors_choices.face_editor_eye_open_ratio_range[-1],
|
maximum = processors_choices.face_editor_eye_open_ratio_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_LIP_OPEN_RATIO_SLIDER = gradio.Slider(
|
FACE_EDITOR_LIP_OPEN_RATIO_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_lip_open_ratio_slider'),
|
label = wording.get('uis.face_editor_lip_open_ratio_slider'),
|
||||||
@@ -87,7 +88,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_lip_open_ratio_range),
|
step = calc_float_step(processors_choices.face_editor_lip_open_ratio_range),
|
||||||
minimum = processors_choices.face_editor_lip_open_ratio_range[0],
|
minimum = processors_choices.face_editor_lip_open_ratio_range[0],
|
||||||
maximum = processors_choices.face_editor_lip_open_ratio_range[-1],
|
maximum = processors_choices.face_editor_lip_open_ratio_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_MOUTH_GRIM_SLIDER = gradio.Slider(
|
FACE_EDITOR_MOUTH_GRIM_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_mouth_grim_slider'),
|
label = wording.get('uis.face_editor_mouth_grim_slider'),
|
||||||
@@ -95,7 +96,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_mouth_grim_range),
|
step = calc_float_step(processors_choices.face_editor_mouth_grim_range),
|
||||||
minimum = processors_choices.face_editor_mouth_grim_range[0],
|
minimum = processors_choices.face_editor_mouth_grim_range[0],
|
||||||
maximum = processors_choices.face_editor_mouth_grim_range[-1],
|
maximum = processors_choices.face_editor_mouth_grim_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_MOUTH_POUT_SLIDER = gradio.Slider(
|
FACE_EDITOR_MOUTH_POUT_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_mouth_pout_slider'),
|
label = wording.get('uis.face_editor_mouth_pout_slider'),
|
||||||
@@ -103,7 +104,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_mouth_pout_range),
|
step = calc_float_step(processors_choices.face_editor_mouth_pout_range),
|
||||||
minimum = processors_choices.face_editor_mouth_pout_range[0],
|
minimum = processors_choices.face_editor_mouth_pout_range[0],
|
||||||
maximum = processors_choices.face_editor_mouth_pout_range[-1],
|
maximum = processors_choices.face_editor_mouth_pout_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_MOUTH_PURSE_SLIDER = gradio.Slider(
|
FACE_EDITOR_MOUTH_PURSE_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_mouth_purse_slider'),
|
label = wording.get('uis.face_editor_mouth_purse_slider'),
|
||||||
@@ -111,7 +112,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_mouth_purse_range),
|
step = calc_float_step(processors_choices.face_editor_mouth_purse_range),
|
||||||
minimum = processors_choices.face_editor_mouth_purse_range[0],
|
minimum = processors_choices.face_editor_mouth_purse_range[0],
|
||||||
maximum = processors_choices.face_editor_mouth_purse_range[-1],
|
maximum = processors_choices.face_editor_mouth_purse_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_MOUTH_SMILE_SLIDER = gradio.Slider(
|
FACE_EDITOR_MOUTH_SMILE_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_mouth_smile_slider'),
|
label = wording.get('uis.face_editor_mouth_smile_slider'),
|
||||||
@@ -119,7 +120,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_mouth_smile_range),
|
step = calc_float_step(processors_choices.face_editor_mouth_smile_range),
|
||||||
minimum = processors_choices.face_editor_mouth_smile_range[0],
|
minimum = processors_choices.face_editor_mouth_smile_range[0],
|
||||||
maximum = processors_choices.face_editor_mouth_smile_range[-1],
|
maximum = processors_choices.face_editor_mouth_smile_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_MOUTH_POSITION_HORIZONTAL_SLIDER = gradio.Slider(
|
FACE_EDITOR_MOUTH_POSITION_HORIZONTAL_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_mouth_position_horizontal_slider'),
|
label = wording.get('uis.face_editor_mouth_position_horizontal_slider'),
|
||||||
@@ -127,7 +128,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_mouth_position_horizontal_range),
|
step = calc_float_step(processors_choices.face_editor_mouth_position_horizontal_range),
|
||||||
minimum = processors_choices.face_editor_mouth_position_horizontal_range[0],
|
minimum = processors_choices.face_editor_mouth_position_horizontal_range[0],
|
||||||
maximum = processors_choices.face_editor_mouth_position_horizontal_range[-1],
|
maximum = processors_choices.face_editor_mouth_position_horizontal_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_MOUTH_POSITION_VERTICAL_SLIDER = gradio.Slider(
|
FACE_EDITOR_MOUTH_POSITION_VERTICAL_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_mouth_position_vertical_slider'),
|
label = wording.get('uis.face_editor_mouth_position_vertical_slider'),
|
||||||
@@ -135,7 +136,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_mouth_position_vertical_range),
|
step = calc_float_step(processors_choices.face_editor_mouth_position_vertical_range),
|
||||||
minimum = processors_choices.face_editor_mouth_position_vertical_range[0],
|
minimum = processors_choices.face_editor_mouth_position_vertical_range[0],
|
||||||
maximum = processors_choices.face_editor_mouth_position_vertical_range[-1],
|
maximum = processors_choices.face_editor_mouth_position_vertical_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_HEAD_PITCH_SLIDER = gradio.Slider(
|
FACE_EDITOR_HEAD_PITCH_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_head_pitch_slider'),
|
label = wording.get('uis.face_editor_head_pitch_slider'),
|
||||||
@@ -143,7 +144,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_head_pitch_range),
|
step = calc_float_step(processors_choices.face_editor_head_pitch_range),
|
||||||
minimum = processors_choices.face_editor_head_pitch_range[0],
|
minimum = processors_choices.face_editor_head_pitch_range[0],
|
||||||
maximum = processors_choices.face_editor_head_pitch_range[-1],
|
maximum = processors_choices.face_editor_head_pitch_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_HEAD_YAW_SLIDER = gradio.Slider(
|
FACE_EDITOR_HEAD_YAW_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_head_yaw_slider'),
|
label = wording.get('uis.face_editor_head_yaw_slider'),
|
||||||
@@ -151,7 +152,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_head_yaw_range),
|
step = calc_float_step(processors_choices.face_editor_head_yaw_range),
|
||||||
minimum = processors_choices.face_editor_head_yaw_range[0],
|
minimum = processors_choices.face_editor_head_yaw_range[0],
|
||||||
maximum = processors_choices.face_editor_head_yaw_range[-1],
|
maximum = processors_choices.face_editor_head_yaw_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
FACE_EDITOR_HEAD_ROLL_SLIDER = gradio.Slider(
|
FACE_EDITOR_HEAD_ROLL_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_editor_head_roll_slider'),
|
label = wording.get('uis.face_editor_head_roll_slider'),
|
||||||
@@ -159,7 +160,7 @@ def render() -> None:
|
|||||||
step = calc_float_step(processors_choices.face_editor_head_roll_range),
|
step = calc_float_step(processors_choices.face_editor_head_roll_range),
|
||||||
minimum = processors_choices.face_editor_head_roll_range[0],
|
minimum = processors_choices.face_editor_head_roll_range[0],
|
||||||
maximum = processors_choices.face_editor_head_roll_range[-1],
|
maximum = processors_choices.face_editor_head_roll_range[-1],
|
||||||
visible = 'face_editor' in state_manager.get_item('processors'),
|
visible = has_face_editor
|
||||||
)
|
)
|
||||||
register_ui_component('face_editor_model_dropdown', FACE_EDITOR_MODEL_DROPDOWN)
|
register_ui_component('face_editor_model_dropdown', FACE_EDITOR_MODEL_DROPDOWN)
|
||||||
register_ui_component('face_editor_eyebrow_direction_slider', FACE_EDITOR_EYEBROW_DIRECTION_SLIDER)
|
register_ui_component('face_editor_eyebrow_direction_slider', FACE_EDITOR_EYEBROW_DIRECTION_SLIDER)
|
||||||
|
|||||||
@@ -3,25 +3,28 @@ from typing import List, Optional, Tuple
|
|||||||
import gradio
|
import gradio
|
||||||
|
|
||||||
from facefusion import state_manager, wording
|
from facefusion import state_manager, wording
|
||||||
from facefusion.common_helper import calc_int_step
|
from facefusion.common_helper import calc_float_step, calc_int_step
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.core import load_processor_module
|
from facefusion.processors.core import load_processor_module
|
||||||
from facefusion.processors.typing import FaceEnhancerModel
|
from facefusion.processors.types import FaceEnhancerModel
|
||||||
from facefusion.uis.core import get_ui_component, register_ui_component
|
from facefusion.uis.core import get_ui_component, register_ui_component
|
||||||
|
|
||||||
FACE_ENHANCER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
FACE_ENHANCER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
FACE_ENHANCER_BLEND_SLIDER : Optional[gradio.Slider] = None
|
FACE_ENHANCER_BLEND_SLIDER : Optional[gradio.Slider] = None
|
||||||
|
FACE_ENHANCER_WEIGHT_SLIDER : Optional[gradio.Slider] = None
|
||||||
|
|
||||||
|
|
||||||
def render() -> None:
|
def render() -> None:
|
||||||
global FACE_ENHANCER_MODEL_DROPDOWN
|
global FACE_ENHANCER_MODEL_DROPDOWN
|
||||||
global FACE_ENHANCER_BLEND_SLIDER
|
global FACE_ENHANCER_BLEND_SLIDER
|
||||||
|
global FACE_ENHANCER_WEIGHT_SLIDER
|
||||||
|
|
||||||
|
has_face_enhancer = 'face_enhancer' in state_manager.get_item('processors')
|
||||||
FACE_ENHANCER_MODEL_DROPDOWN = gradio.Dropdown(
|
FACE_ENHANCER_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.face_enhancer_model_dropdown'),
|
label = wording.get('uis.face_enhancer_model_dropdown'),
|
||||||
choices = processors_choices.face_enhancer_models,
|
choices = processors_choices.face_enhancer_models,
|
||||||
value = state_manager.get_item('face_enhancer_model'),
|
value = state_manager.get_item('face_enhancer_model'),
|
||||||
visible = 'face_enhancer' in state_manager.get_item('processors')
|
visible = has_face_enhancer
|
||||||
)
|
)
|
||||||
FACE_ENHANCER_BLEND_SLIDER = gradio.Slider(
|
FACE_ENHANCER_BLEND_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.face_enhancer_blend_slider'),
|
label = wording.get('uis.face_enhancer_blend_slider'),
|
||||||
@@ -29,35 +32,50 @@ def render() -> None:
|
|||||||
step = calc_int_step(processors_choices.face_enhancer_blend_range),
|
step = calc_int_step(processors_choices.face_enhancer_blend_range),
|
||||||
minimum = processors_choices.face_enhancer_blend_range[0],
|
minimum = processors_choices.face_enhancer_blend_range[0],
|
||||||
maximum = processors_choices.face_enhancer_blend_range[-1],
|
maximum = processors_choices.face_enhancer_blend_range[-1],
|
||||||
visible = 'face_enhancer' in state_manager.get_item('processors')
|
visible = has_face_enhancer
|
||||||
|
)
|
||||||
|
FACE_ENHANCER_WEIGHT_SLIDER = gradio.Slider(
|
||||||
|
label = wording.get('uis.face_enhancer_weight_slider'),
|
||||||
|
value = state_manager.get_item('face_enhancer_weight'),
|
||||||
|
step = calc_float_step(processors_choices.face_enhancer_weight_range),
|
||||||
|
minimum = processors_choices.face_enhancer_weight_range[0],
|
||||||
|
maximum = processors_choices.face_enhancer_weight_range[-1],
|
||||||
|
visible = has_face_enhancer and load_processor_module('face_enhancer').get_inference_pool() and load_processor_module('face_enhancer').has_weight_input()
|
||||||
)
|
)
|
||||||
register_ui_component('face_enhancer_model_dropdown', FACE_ENHANCER_MODEL_DROPDOWN)
|
register_ui_component('face_enhancer_model_dropdown', FACE_ENHANCER_MODEL_DROPDOWN)
|
||||||
register_ui_component('face_enhancer_blend_slider', FACE_ENHANCER_BLEND_SLIDER)
|
register_ui_component('face_enhancer_blend_slider', FACE_ENHANCER_BLEND_SLIDER)
|
||||||
|
register_ui_component('face_enhancer_weight_slider', FACE_ENHANCER_WEIGHT_SLIDER)
|
||||||
|
|
||||||
|
|
||||||
def listen() -> None:
|
def listen() -> None:
|
||||||
FACE_ENHANCER_MODEL_DROPDOWN.change(update_face_enhancer_model, inputs = FACE_ENHANCER_MODEL_DROPDOWN, outputs = FACE_ENHANCER_MODEL_DROPDOWN)
|
FACE_ENHANCER_MODEL_DROPDOWN.change(update_face_enhancer_model, inputs = FACE_ENHANCER_MODEL_DROPDOWN, outputs = [ FACE_ENHANCER_MODEL_DROPDOWN, FACE_ENHANCER_WEIGHT_SLIDER ])
|
||||||
FACE_ENHANCER_BLEND_SLIDER.release(update_face_enhancer_blend, inputs = FACE_ENHANCER_BLEND_SLIDER)
|
FACE_ENHANCER_BLEND_SLIDER.release(update_face_enhancer_blend, inputs = FACE_ENHANCER_BLEND_SLIDER)
|
||||||
|
FACE_ENHANCER_WEIGHT_SLIDER.release(update_face_enhancer_weight, inputs = FACE_ENHANCER_WEIGHT_SLIDER)
|
||||||
|
|
||||||
processors_checkbox_group = get_ui_component('processors_checkbox_group')
|
processors_checkbox_group = get_ui_component('processors_checkbox_group')
|
||||||
if processors_checkbox_group:
|
if processors_checkbox_group:
|
||||||
processors_checkbox_group.change(remote_update, inputs = processors_checkbox_group, outputs = [ FACE_ENHANCER_MODEL_DROPDOWN, FACE_ENHANCER_BLEND_SLIDER ])
|
processors_checkbox_group.change(remote_update, inputs = processors_checkbox_group, outputs = [ FACE_ENHANCER_MODEL_DROPDOWN, FACE_ENHANCER_BLEND_SLIDER, FACE_ENHANCER_WEIGHT_SLIDER ])
|
||||||
|
|
||||||
|
|
||||||
def remote_update(processors : List[str]) -> Tuple[gradio.Dropdown, gradio.Slider]:
|
def remote_update(processors : List[str]) -> Tuple[gradio.Dropdown, gradio.Slider, gradio.Slider]:
|
||||||
has_face_enhancer = 'face_enhancer' in processors
|
has_face_enhancer = 'face_enhancer' in processors
|
||||||
return gradio.Dropdown(visible = has_face_enhancer), gradio.Slider(visible = has_face_enhancer)
|
return gradio.Dropdown(visible = has_face_enhancer), gradio.Slider(visible = has_face_enhancer), gradio.Slider(visible = has_face_enhancer and load_processor_module('face_enhancer').get_inference_pool() and load_processor_module('face_enhancer').has_weight_input())
|
||||||
|
|
||||||
|
|
||||||
def update_face_enhancer_model(face_enhancer_model : FaceEnhancerModel) -> gradio.Dropdown:
|
def update_face_enhancer_model(face_enhancer_model : FaceEnhancerModel) -> Tuple[gradio.Dropdown, gradio.Slider]:
|
||||||
face_enhancer_module = load_processor_module('face_enhancer')
|
face_enhancer_module = load_processor_module('face_enhancer')
|
||||||
face_enhancer_module.clear_inference_pool()
|
face_enhancer_module.clear_inference_pool()
|
||||||
state_manager.set_item('face_enhancer_model', face_enhancer_model)
|
state_manager.set_item('face_enhancer_model', face_enhancer_model)
|
||||||
|
|
||||||
if face_enhancer_module.pre_check():
|
if face_enhancer_module.pre_check():
|
||||||
return gradio.Dropdown(value = state_manager.get_item('face_enhancer_model'))
|
return gradio.Dropdown(value = state_manager.get_item('face_enhancer_model')), gradio.Slider(visible = face_enhancer_module.has_weight_input())
|
||||||
return gradio.Dropdown()
|
return gradio.Dropdown(), gradio.Slider()
|
||||||
|
|
||||||
|
|
||||||
def update_face_enhancer_blend(face_enhancer_blend : float) -> None:
|
def update_face_enhancer_blend(face_enhancer_blend : float) -> None:
|
||||||
state_manager.set_item('face_enhancer_blend', int(face_enhancer_blend))
|
state_manager.set_item('face_enhancer_blend', int(face_enhancer_blend))
|
||||||
|
|
||||||
|
|
||||||
|
def update_face_enhancer_weight(face_enhancer_weight : float) -> None:
|
||||||
|
state_manager.set_item('face_enhancer_weight', face_enhancer_weight)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import gradio
|
|||||||
import facefusion.choices
|
import facefusion.choices
|
||||||
from facefusion import face_landmarker, state_manager, wording
|
from facefusion import face_landmarker, state_manager, wording
|
||||||
from facefusion.common_helper import calc_float_step
|
from facefusion.common_helper import calc_float_step
|
||||||
from facefusion.typing import FaceLandmarkerModel, Score
|
from facefusion.types import FaceLandmarkerModel, Score
|
||||||
from facefusion.uis.core import register_ui_component
|
from facefusion.uis.core import register_ui_component
|
||||||
|
|
||||||
FACE_LANDMARKER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
FACE_LANDMARKER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ from typing import List, Optional, Tuple
|
|||||||
import gradio
|
import gradio
|
||||||
|
|
||||||
import facefusion.choices
|
import facefusion.choices
|
||||||
from facefusion import state_manager, wording
|
from facefusion import face_masker, state_manager, wording
|
||||||
from facefusion.common_helper import calc_float_step, calc_int_step
|
from facefusion.common_helper import calc_float_step, calc_int_step
|
||||||
from facefusion.typing import FaceMaskRegion, FaceMaskType
|
from facefusion.types import FaceMaskRegion, FaceMaskType, FaceOccluderModel, FaceParserModel
|
||||||
from facefusion.uis.core import register_ui_component
|
from facefusion.uis.core import register_ui_component
|
||||||
|
|
||||||
|
FACE_OCCLUDER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
|
FACE_PARSER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
FACE_MASK_TYPES_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
FACE_MASK_TYPES_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
||||||
FACE_MASK_REGIONS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
FACE_MASK_REGIONS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
||||||
FACE_MASK_BLUR_SLIDER : Optional[gradio.Slider] = None
|
FACE_MASK_BLUR_SLIDER : Optional[gradio.Slider] = None
|
||||||
@@ -18,6 +20,8 @@ FACE_MASK_PADDING_LEFT_SLIDER : Optional[gradio.Slider] = None
|
|||||||
|
|
||||||
|
|
||||||
def render() -> None:
|
def render() -> None:
|
||||||
|
global FACE_OCCLUDER_MODEL_DROPDOWN
|
||||||
|
global FACE_PARSER_MODEL_DROPDOWN
|
||||||
global FACE_MASK_TYPES_CHECKBOX_GROUP
|
global FACE_MASK_TYPES_CHECKBOX_GROUP
|
||||||
global FACE_MASK_REGIONS_CHECKBOX_GROUP
|
global FACE_MASK_REGIONS_CHECKBOX_GROUP
|
||||||
global FACE_MASK_BLUR_SLIDER
|
global FACE_MASK_BLUR_SLIDER
|
||||||
@@ -28,6 +32,17 @@ def render() -> None:
|
|||||||
|
|
||||||
has_box_mask = 'box' in state_manager.get_item('face_mask_types')
|
has_box_mask = 'box' in state_manager.get_item('face_mask_types')
|
||||||
has_region_mask = 'region' in state_manager.get_item('face_mask_types')
|
has_region_mask = 'region' in state_manager.get_item('face_mask_types')
|
||||||
|
with gradio.Row():
|
||||||
|
FACE_OCCLUDER_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
|
label = wording.get('uis.face_occluder_model_dropdown'),
|
||||||
|
choices = facefusion.choices.face_occluder_models,
|
||||||
|
value = state_manager.get_item('face_occluder_model')
|
||||||
|
)
|
||||||
|
FACE_PARSER_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
|
label = wording.get('uis.face_parser_model_dropdown'),
|
||||||
|
choices = facefusion.choices.face_parser_models,
|
||||||
|
value = state_manager.get_item('face_parser_model')
|
||||||
|
)
|
||||||
FACE_MASK_TYPES_CHECKBOX_GROUP = gradio.CheckboxGroup(
|
FACE_MASK_TYPES_CHECKBOX_GROUP = gradio.CheckboxGroup(
|
||||||
label = wording.get('uis.face_mask_types_checkbox_group'),
|
label = wording.get('uis.face_mask_types_checkbox_group'),
|
||||||
choices = facefusion.choices.face_mask_types,
|
choices = facefusion.choices.face_mask_types,
|
||||||
@@ -82,6 +97,8 @@ def render() -> None:
|
|||||||
value = state_manager.get_item('face_mask_padding')[3],
|
value = state_manager.get_item('face_mask_padding')[3],
|
||||||
visible = has_box_mask
|
visible = has_box_mask
|
||||||
)
|
)
|
||||||
|
register_ui_component('face_occluder_model_dropdown', FACE_OCCLUDER_MODEL_DROPDOWN)
|
||||||
|
register_ui_component('face_parser_model_dropdown', FACE_PARSER_MODEL_DROPDOWN)
|
||||||
register_ui_component('face_mask_types_checkbox_group', FACE_MASK_TYPES_CHECKBOX_GROUP)
|
register_ui_component('face_mask_types_checkbox_group', FACE_MASK_TYPES_CHECKBOX_GROUP)
|
||||||
register_ui_component('face_mask_regions_checkbox_group', FACE_MASK_REGIONS_CHECKBOX_GROUP)
|
register_ui_component('face_mask_regions_checkbox_group', FACE_MASK_REGIONS_CHECKBOX_GROUP)
|
||||||
register_ui_component('face_mask_blur_slider', FACE_MASK_BLUR_SLIDER)
|
register_ui_component('face_mask_blur_slider', FACE_MASK_BLUR_SLIDER)
|
||||||
@@ -92,6 +109,8 @@ def render() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def listen() -> None:
|
def listen() -> None:
|
||||||
|
FACE_OCCLUDER_MODEL_DROPDOWN.change(update_face_occluder_model, inputs = FACE_OCCLUDER_MODEL_DROPDOWN)
|
||||||
|
FACE_PARSER_MODEL_DROPDOWN.change(update_face_parser_model, inputs = FACE_PARSER_MODEL_DROPDOWN)
|
||||||
FACE_MASK_TYPES_CHECKBOX_GROUP.change(update_face_mask_types, inputs = FACE_MASK_TYPES_CHECKBOX_GROUP, outputs = [ FACE_MASK_TYPES_CHECKBOX_GROUP, FACE_MASK_REGIONS_CHECKBOX_GROUP, FACE_MASK_BLUR_SLIDER, FACE_MASK_PADDING_TOP_SLIDER, FACE_MASK_PADDING_RIGHT_SLIDER, FACE_MASK_PADDING_BOTTOM_SLIDER, FACE_MASK_PADDING_LEFT_SLIDER ])
|
FACE_MASK_TYPES_CHECKBOX_GROUP.change(update_face_mask_types, inputs = FACE_MASK_TYPES_CHECKBOX_GROUP, outputs = [ FACE_MASK_TYPES_CHECKBOX_GROUP, FACE_MASK_REGIONS_CHECKBOX_GROUP, FACE_MASK_BLUR_SLIDER, FACE_MASK_PADDING_TOP_SLIDER, FACE_MASK_PADDING_RIGHT_SLIDER, FACE_MASK_PADDING_BOTTOM_SLIDER, FACE_MASK_PADDING_LEFT_SLIDER ])
|
||||||
FACE_MASK_REGIONS_CHECKBOX_GROUP.change(update_face_mask_regions, inputs = FACE_MASK_REGIONS_CHECKBOX_GROUP, outputs = FACE_MASK_REGIONS_CHECKBOX_GROUP)
|
FACE_MASK_REGIONS_CHECKBOX_GROUP.change(update_face_mask_regions, inputs = FACE_MASK_REGIONS_CHECKBOX_GROUP, outputs = FACE_MASK_REGIONS_CHECKBOX_GROUP)
|
||||||
FACE_MASK_BLUR_SLIDER.release(update_face_mask_blur, inputs = FACE_MASK_BLUR_SLIDER)
|
FACE_MASK_BLUR_SLIDER.release(update_face_mask_blur, inputs = FACE_MASK_BLUR_SLIDER)
|
||||||
@@ -100,6 +119,24 @@ def listen() -> None:
|
|||||||
face_mask_padding_slider.release(update_face_mask_padding, inputs = face_mask_padding_sliders)
|
face_mask_padding_slider.release(update_face_mask_padding, inputs = face_mask_padding_sliders)
|
||||||
|
|
||||||
|
|
||||||
|
def update_face_occluder_model(face_occluder_model : FaceOccluderModel) -> gradio.Dropdown:
|
||||||
|
face_masker.clear_inference_pool()
|
||||||
|
state_manager.set_item('face_occluder_model', face_occluder_model)
|
||||||
|
|
||||||
|
if face_masker.pre_check():
|
||||||
|
return gradio.Dropdown(value = state_manager.get_item('face_occluder_model'))
|
||||||
|
return gradio.Dropdown()
|
||||||
|
|
||||||
|
|
||||||
|
def update_face_parser_model(face_parser_model : FaceParserModel) -> gradio.Dropdown:
|
||||||
|
face_masker.clear_inference_pool()
|
||||||
|
state_manager.set_item('face_parser_model', face_parser_model)
|
||||||
|
|
||||||
|
if face_masker.pre_check():
|
||||||
|
return gradio.Dropdown(value = state_manager.get_item('face_parser_model'))
|
||||||
|
return gradio.Dropdown()
|
||||||
|
|
||||||
|
|
||||||
def update_face_mask_types(face_mask_types : List[FaceMaskType]) -> Tuple[gradio.CheckboxGroup, gradio.CheckboxGroup, gradio.Slider, gradio.Slider, gradio.Slider, gradio.Slider, gradio.Slider]:
|
def update_face_mask_types(face_mask_types : List[FaceMaskType]) -> Tuple[gradio.CheckboxGroup, gradio.CheckboxGroup, gradio.Slider, gradio.Slider, gradio.Slider, gradio.Slider, gradio.Slider]:
|
||||||
face_mask_types = face_mask_types or facefusion.choices.face_mask_types
|
face_mask_types = face_mask_types or facefusion.choices.face_mask_types
|
||||||
state_manager.set_item('face_mask_types', face_mask_types)
|
state_manager.set_item('face_mask_types', face_mask_types)
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ from facefusion.face_analyser import get_many_faces
|
|||||||
from facefusion.face_selector import sort_and_filter_faces
|
from facefusion.face_selector import sort_and_filter_faces
|
||||||
from facefusion.face_store import clear_reference_faces, clear_static_faces
|
from facefusion.face_store import clear_reference_faces, clear_static_faces
|
||||||
from facefusion.filesystem import is_image, is_video
|
from facefusion.filesystem import is_image, is_video
|
||||||
from facefusion.typing import FaceSelectorMode, FaceSelectorOrder, Gender, Race, VisionFrame
|
from facefusion.types import FaceSelectorMode, FaceSelectorOrder, Gender, Race, VisionFrame
|
||||||
from facefusion.uis.core import get_ui_component, get_ui_components, register_ui_component
|
from facefusion.uis.core import get_ui_component, get_ui_components, register_ui_component
|
||||||
from facefusion.uis.typing import ComponentOptions
|
from facefusion.uis.types import ComponentOptions
|
||||||
from facefusion.uis.ui_helper import convert_str_none
|
from facefusion.uis.ui_helper import convert_str_none
|
||||||
from facefusion.vision import get_video_frame, normalize_frame_color, read_static_image
|
from facefusion.vision import normalize_frame_color, read_static_image, read_video_frame
|
||||||
|
|
||||||
FACE_SELECTOR_MODE_DROPDOWN : Optional[gradio.Dropdown] = None
|
FACE_SELECTOR_MODE_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
FACE_SELECTOR_ORDER_DROPDOWN : Optional[gradio.Dropdown] = None
|
FACE_SELECTOR_ORDER_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
@@ -38,15 +38,16 @@ def render() -> None:
|
|||||||
{
|
{
|
||||||
'label': wording.get('uis.reference_face_gallery'),
|
'label': wording.get('uis.reference_face_gallery'),
|
||||||
'object_fit': 'cover',
|
'object_fit': 'cover',
|
||||||
'columns': 8,
|
'columns': 7,
|
||||||
'allow_preview': False,
|
'allow_preview': False,
|
||||||
|
'elem_classes': 'box-face-selector',
|
||||||
'visible': 'reference' in state_manager.get_item('face_selector_mode')
|
'visible': 'reference' in state_manager.get_item('face_selector_mode')
|
||||||
}
|
}
|
||||||
if is_image(state_manager.get_item('target_path')):
|
if is_image(state_manager.get_item('target_path')):
|
||||||
reference_frame = read_static_image(state_manager.get_item('target_path'))
|
reference_frame = read_static_image(state_manager.get_item('target_path'))
|
||||||
reference_face_gallery_options['value'] = extract_gallery_frames(reference_frame)
|
reference_face_gallery_options['value'] = extract_gallery_frames(reference_frame)
|
||||||
if is_video(state_manager.get_item('target_path')):
|
if is_video(state_manager.get_item('target_path')):
|
||||||
reference_frame = get_video_frame(state_manager.get_item('target_path'), state_manager.get_item('reference_frame_number'))
|
reference_frame = read_video_frame(state_manager.get_item('target_path'), state_manager.get_item('reference_frame_number'))
|
||||||
reference_face_gallery_options['value'] = extract_gallery_frames(reference_frame)
|
reference_face_gallery_options['value'] = extract_gallery_frames(reference_frame)
|
||||||
FACE_SELECTOR_MODE_DROPDOWN = gradio.Dropdown(
|
FACE_SELECTOR_MODE_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.face_selector_mode_dropdown'),
|
label = wording.get('uis.face_selector_mode_dropdown'),
|
||||||
@@ -112,7 +113,7 @@ def listen() -> None:
|
|||||||
'target_image',
|
'target_image',
|
||||||
'target_video'
|
'target_video'
|
||||||
]):
|
]):
|
||||||
for method in [ 'upload', 'change', 'clear' ]:
|
for method in [ 'change', 'clear' ]:
|
||||||
getattr(ui_component, method)(update_reference_face_position)
|
getattr(ui_component, method)(update_reference_face_position)
|
||||||
getattr(ui_component, method)(update_reference_position_gallery, outputs = REFERENCE_FACE_POSITION_GALLERY)
|
getattr(ui_component, method)(update_reference_position_gallery, outputs = REFERENCE_FACE_POSITION_GALLERY)
|
||||||
|
|
||||||
@@ -130,8 +131,9 @@ def listen() -> None:
|
|||||||
|
|
||||||
preview_frame_slider = get_ui_component('preview_frame_slider')
|
preview_frame_slider = get_ui_component('preview_frame_slider')
|
||||||
if preview_frame_slider:
|
if preview_frame_slider:
|
||||||
preview_frame_slider.release(update_reference_frame_number, inputs = preview_frame_slider)
|
for method in [ 'change', 'release' ]:
|
||||||
preview_frame_slider.release(update_reference_position_gallery, outputs = REFERENCE_FACE_POSITION_GALLERY)
|
getattr(preview_frame_slider, method)(update_reference_frame_number, inputs = preview_frame_slider, show_progress = 'hidden')
|
||||||
|
getattr(preview_frame_slider, method)(update_reference_position_gallery, outputs = REFERENCE_FACE_POSITION_GALLERY, show_progress = 'hidden')
|
||||||
|
|
||||||
|
|
||||||
def update_face_selector_mode(face_selector_mode : FaceSelectorMode) -> Tuple[gradio.Gallery, gradio.Slider]:
|
def update_face_selector_mode(face_selector_mode : FaceSelectorMode) -> Tuple[gradio.Gallery, gradio.Slider]:
|
||||||
@@ -197,7 +199,7 @@ def update_reference_position_gallery() -> gradio.Gallery:
|
|||||||
temp_vision_frame = read_static_image(state_manager.get_item('target_path'))
|
temp_vision_frame = read_static_image(state_manager.get_item('target_path'))
|
||||||
gallery_vision_frames = extract_gallery_frames(temp_vision_frame)
|
gallery_vision_frames = extract_gallery_frames(temp_vision_frame)
|
||||||
if is_video(state_manager.get_item('target_path')):
|
if is_video(state_manager.get_item('target_path')):
|
||||||
temp_vision_frame = get_video_frame(state_manager.get_item('target_path'), state_manager.get_item('reference_frame_number'))
|
temp_vision_frame = read_video_frame(state_manager.get_item('target_path'), state_manager.get_item('reference_frame_number'))
|
||||||
gallery_vision_frames = extract_gallery_frames(temp_vision_frame)
|
gallery_vision_frames = extract_gallery_frames(temp_vision_frame)
|
||||||
if gallery_vision_frames:
|
if gallery_vision_frames:
|
||||||
return gradio.Gallery(value = gallery_vision_frames)
|
return gradio.Gallery(value = gallery_vision_frames)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from facefusion import state_manager, wording
|
|||||||
from facefusion.common_helper import get_first
|
from facefusion.common_helper import get_first
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.core import load_processor_module
|
from facefusion.processors.core import load_processor_module
|
||||||
from facefusion.processors.typing import FaceSwapperModel
|
from facefusion.processors.types import FaceSwapperModel
|
||||||
from facefusion.uis.core import get_ui_component, register_ui_component
|
from facefusion.uis.core import get_ui_component, register_ui_component
|
||||||
|
|
||||||
FACE_SWAPPER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
FACE_SWAPPER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
@@ -17,17 +17,18 @@ def render() -> None:
|
|||||||
global FACE_SWAPPER_MODEL_DROPDOWN
|
global FACE_SWAPPER_MODEL_DROPDOWN
|
||||||
global FACE_SWAPPER_PIXEL_BOOST_DROPDOWN
|
global FACE_SWAPPER_PIXEL_BOOST_DROPDOWN
|
||||||
|
|
||||||
|
has_face_swapper = 'face_swapper' in state_manager.get_item('processors')
|
||||||
FACE_SWAPPER_MODEL_DROPDOWN = gradio.Dropdown(
|
FACE_SWAPPER_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.face_swapper_model_dropdown'),
|
label = wording.get('uis.face_swapper_model_dropdown'),
|
||||||
choices = processors_choices.face_swapper_set.keys(),
|
choices = processors_choices.face_swapper_models,
|
||||||
value = state_manager.get_item('face_swapper_model'),
|
value = state_manager.get_item('face_swapper_model'),
|
||||||
visible = 'face_swapper' in state_manager.get_item('processors')
|
visible = has_face_swapper
|
||||||
)
|
)
|
||||||
FACE_SWAPPER_PIXEL_BOOST_DROPDOWN = gradio.Dropdown(
|
FACE_SWAPPER_PIXEL_BOOST_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.face_swapper_pixel_boost_dropdown'),
|
label = wording.get('uis.face_swapper_pixel_boost_dropdown'),
|
||||||
choices = processors_choices.face_swapper_set.get(state_manager.get_item('face_swapper_model')),
|
choices = processors_choices.face_swapper_set.get(state_manager.get_item('face_swapper_model')),
|
||||||
value = state_manager.get_item('face_swapper_pixel_boost'),
|
value = state_manager.get_item('face_swapper_pixel_boost'),
|
||||||
visible = 'face_swapper' in state_manager.get_item('processors')
|
visible = has_face_swapper
|
||||||
)
|
)
|
||||||
register_ui_component('face_swapper_model_dropdown', FACE_SWAPPER_MODEL_DROPDOWN)
|
register_ui_component('face_swapper_model_dropdown', FACE_SWAPPER_MODEL_DROPDOWN)
|
||||||
register_ui_component('face_swapper_pixel_boost_dropdown', FACE_SWAPPER_PIXEL_BOOST_DROPDOWN)
|
register_ui_component('face_swapper_pixel_boost_dropdown', FACE_SWAPPER_PIXEL_BOOST_DROPDOWN)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from facefusion import state_manager, wording
|
|||||||
from facefusion.common_helper import calc_int_step
|
from facefusion.common_helper import calc_int_step
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.core import load_processor_module
|
from facefusion.processors.core import load_processor_module
|
||||||
from facefusion.processors.typing import FrameColorizerModel
|
from facefusion.processors.types import FrameColorizerModel
|
||||||
from facefusion.uis.core import get_ui_component, register_ui_component
|
from facefusion.uis.core import get_ui_component, register_ui_component
|
||||||
|
|
||||||
FRAME_COLORIZER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
FRAME_COLORIZER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
@@ -19,17 +19,18 @@ def render() -> None:
|
|||||||
global FRAME_COLORIZER_SIZE_DROPDOWN
|
global FRAME_COLORIZER_SIZE_DROPDOWN
|
||||||
global FRAME_COLORIZER_BLEND_SLIDER
|
global FRAME_COLORIZER_BLEND_SLIDER
|
||||||
|
|
||||||
|
has_frame_colorizer = 'frame_colorizer' in state_manager.get_item('processors')
|
||||||
FRAME_COLORIZER_MODEL_DROPDOWN = gradio.Dropdown(
|
FRAME_COLORIZER_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.frame_colorizer_model_dropdown'),
|
label = wording.get('uis.frame_colorizer_model_dropdown'),
|
||||||
choices = processors_choices.frame_colorizer_models,
|
choices = processors_choices.frame_colorizer_models,
|
||||||
value = state_manager.get_item('frame_colorizer_model'),
|
value = state_manager.get_item('frame_colorizer_model'),
|
||||||
visible = 'frame_colorizer' in state_manager.get_item('processors')
|
visible = has_frame_colorizer
|
||||||
)
|
)
|
||||||
FRAME_COLORIZER_SIZE_DROPDOWN = gradio.Dropdown(
|
FRAME_COLORIZER_SIZE_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.frame_colorizer_size_dropdown'),
|
label = wording.get('uis.frame_colorizer_size_dropdown'),
|
||||||
choices = processors_choices.frame_colorizer_sizes,
|
choices = processors_choices.frame_colorizer_sizes,
|
||||||
value = state_manager.get_item('frame_colorizer_size'),
|
value = state_manager.get_item('frame_colorizer_size'),
|
||||||
visible = 'frame_colorizer' in state_manager.get_item('processors')
|
visible = has_frame_colorizer
|
||||||
)
|
)
|
||||||
FRAME_COLORIZER_BLEND_SLIDER = gradio.Slider(
|
FRAME_COLORIZER_BLEND_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.frame_colorizer_blend_slider'),
|
label = wording.get('uis.frame_colorizer_blend_slider'),
|
||||||
@@ -37,7 +38,7 @@ def render() -> None:
|
|||||||
step = calc_int_step(processors_choices.frame_colorizer_blend_range),
|
step = calc_int_step(processors_choices.frame_colorizer_blend_range),
|
||||||
minimum = processors_choices.frame_colorizer_blend_range[0],
|
minimum = processors_choices.frame_colorizer_blend_range[0],
|
||||||
maximum = processors_choices.frame_colorizer_blend_range[-1],
|
maximum = processors_choices.frame_colorizer_blend_range[-1],
|
||||||
visible = 'frame_colorizer' in state_manager.get_item('processors')
|
visible = has_frame_colorizer
|
||||||
)
|
)
|
||||||
register_ui_component('frame_colorizer_model_dropdown', FRAME_COLORIZER_MODEL_DROPDOWN)
|
register_ui_component('frame_colorizer_model_dropdown', FRAME_COLORIZER_MODEL_DROPDOWN)
|
||||||
register_ui_component('frame_colorizer_size_dropdown', FRAME_COLORIZER_SIZE_DROPDOWN)
|
register_ui_component('frame_colorizer_size_dropdown', FRAME_COLORIZER_SIZE_DROPDOWN)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from facefusion import state_manager, wording
|
|||||||
from facefusion.common_helper import calc_int_step
|
from facefusion.common_helper import calc_int_step
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.core import load_processor_module
|
from facefusion.processors.core import load_processor_module
|
||||||
from facefusion.processors.typing import FrameEnhancerModel
|
from facefusion.processors.types import FrameEnhancerModel
|
||||||
from facefusion.uis.core import get_ui_component, register_ui_component
|
from facefusion.uis.core import get_ui_component, register_ui_component
|
||||||
|
|
||||||
FRAME_ENHANCER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
FRAME_ENHANCER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
@@ -17,11 +17,12 @@ def render() -> None:
|
|||||||
global FRAME_ENHANCER_MODEL_DROPDOWN
|
global FRAME_ENHANCER_MODEL_DROPDOWN
|
||||||
global FRAME_ENHANCER_BLEND_SLIDER
|
global FRAME_ENHANCER_BLEND_SLIDER
|
||||||
|
|
||||||
|
has_frame_enhancer = 'frame_enhancer' in state_manager.get_item('processors')
|
||||||
FRAME_ENHANCER_MODEL_DROPDOWN = gradio.Dropdown(
|
FRAME_ENHANCER_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.frame_enhancer_model_dropdown'),
|
label = wording.get('uis.frame_enhancer_model_dropdown'),
|
||||||
choices = processors_choices.frame_enhancer_models,
|
choices = processors_choices.frame_enhancer_models,
|
||||||
value = state_manager.get_item('frame_enhancer_model'),
|
value = state_manager.get_item('frame_enhancer_model'),
|
||||||
visible = 'frame_enhancer' in state_manager.get_item('processors')
|
visible = has_frame_enhancer
|
||||||
)
|
)
|
||||||
FRAME_ENHANCER_BLEND_SLIDER = gradio.Slider(
|
FRAME_ENHANCER_BLEND_SLIDER = gradio.Slider(
|
||||||
label = wording.get('uis.frame_enhancer_blend_slider'),
|
label = wording.get('uis.frame_enhancer_blend_slider'),
|
||||||
@@ -29,7 +30,7 @@ def render() -> None:
|
|||||||
step = calc_int_step(processors_choices.frame_enhancer_blend_range),
|
step = calc_int_step(processors_choices.frame_enhancer_blend_range),
|
||||||
minimum = processors_choices.frame_enhancer_blend_range[0],
|
minimum = processors_choices.frame_enhancer_blend_range[0],
|
||||||
maximum = processors_choices.frame_enhancer_blend_range[-1],
|
maximum = processors_choices.frame_enhancer_blend_range[-1],
|
||||||
visible = 'frame_enhancer' in state_manager.get_item('processors')
|
visible = has_frame_enhancer
|
||||||
)
|
)
|
||||||
register_ui_component('frame_enhancer_model_dropdown', FRAME_ENHANCER_MODEL_DROPDOWN)
|
register_ui_component('frame_enhancer_model_dropdown', FRAME_ENHANCER_MODEL_DROPDOWN)
|
||||||
register_ui_component('frame_enhancer_blend_slider', FRAME_ENHANCER_BLEND_SLIDER)
|
register_ui_component('frame_enhancer_blend_slider', FRAME_ENHANCER_BLEND_SLIDER)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from facefusion.core import process_step
|
|||||||
from facefusion.filesystem import is_directory, is_image, is_video
|
from facefusion.filesystem import is_directory, is_image, is_video
|
||||||
from facefusion.jobs import job_helper, job_manager, job_runner, job_store
|
from facefusion.jobs import job_helper, job_manager, job_runner, job_store
|
||||||
from facefusion.temp_helper import clear_temp_directory
|
from facefusion.temp_helper import clear_temp_directory
|
||||||
from facefusion.typing import Args, UiWorkflow
|
from facefusion.types import Args, UiWorkflow
|
||||||
from facefusion.uis.core import get_ui_component
|
from facefusion.uis.core import get_ui_component
|
||||||
from facefusion.uis.ui_helper import suggest_output_path
|
from facefusion.uis.ui_helper import suggest_output_path
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ def create_and_run_job(step_args : Args) -> bool:
|
|||||||
job_id = job_helper.suggest_job_id('ui')
|
job_id = job_helper.suggest_job_id('ui')
|
||||||
|
|
||||||
for key in job_store.get_job_keys():
|
for key in job_store.get_job_keys():
|
||||||
state_manager.sync_item(key) #type:ignore
|
state_manager.sync_item(key) #type:ignore[arg-type]
|
||||||
|
|
||||||
return job_manager.create_job(job_id) and job_manager.add_step(job_id, step_args) and job_manager.submit_job(job_id) and job_runner.run_job(job_id, process_step)
|
return job_manager.create_job(job_id) and job_manager.add_step(job_id, step_args) and job_manager.submit_job(job_id) and job_runner.run_job(job_id, process_step)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import facefusion.choices
|
|||||||
from facefusion import state_manager, wording
|
from facefusion import state_manager, wording
|
||||||
from facefusion.common_helper import get_first
|
from facefusion.common_helper import get_first
|
||||||
from facefusion.jobs import job_list, job_manager
|
from facefusion.jobs import job_list, job_manager
|
||||||
from facefusion.typing import JobStatus
|
from facefusion.types import JobStatus
|
||||||
from facefusion.uis.core import get_ui_component
|
from facefusion.uis.core import get_ui_component
|
||||||
|
|
||||||
JOB_LIST_JOBS_DATAFRAME : Optional[gradio.Dataframe] = None
|
JOB_LIST_JOBS_DATAFRAME : Optional[gradio.Dataframe] = None
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import facefusion.choices
|
|||||||
from facefusion import state_manager, wording
|
from facefusion import state_manager, wording
|
||||||
from facefusion.common_helper import get_first
|
from facefusion.common_helper import get_first
|
||||||
from facefusion.jobs import job_manager
|
from facefusion.jobs import job_manager
|
||||||
from facefusion.typing import JobStatus
|
from facefusion.types import JobStatus
|
||||||
from facefusion.uis.core import register_ui_component
|
from facefusion.uis.core import register_ui_component
|
||||||
|
|
||||||
JOB_LIST_JOB_STATUS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
JOB_LIST_JOB_STATUS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ from facefusion.args import collect_step_args
|
|||||||
from facefusion.common_helper import get_first, get_last
|
from facefusion.common_helper import get_first, get_last
|
||||||
from facefusion.filesystem import is_directory
|
from facefusion.filesystem import is_directory
|
||||||
from facefusion.jobs import job_manager
|
from facefusion.jobs import job_manager
|
||||||
from facefusion.typing import UiWorkflow
|
from facefusion.types import UiWorkflow
|
||||||
from facefusion.uis import choices as uis_choices
|
from facefusion.uis import choices as uis_choices
|
||||||
from facefusion.uis.core import get_ui_component
|
from facefusion.uis.core import get_ui_component
|
||||||
from facefusion.uis.typing import JobManagerAction
|
from facefusion.uis.types import JobManagerAction
|
||||||
from facefusion.uis.ui_helper import convert_int_none, convert_str_none, suggest_output_path
|
from facefusion.uis.ui_helper import convert_int_none, convert_str_none, suggest_output_path
|
||||||
|
|
||||||
JOB_MANAGER_WRAPPER : Optional[gradio.Column] = None
|
JOB_MANAGER_WRAPPER : Optional[gradio.Column] = None
|
||||||
@@ -89,6 +89,7 @@ def apply(job_action : JobManagerAction, created_job_id : str, selected_job_id :
|
|||||||
|
|
||||||
if is_directory(step_args.get('output_path')):
|
if is_directory(step_args.get('output_path')):
|
||||||
step_args['output_path'] = suggest_output_path(step_args.get('output_path'), state_manager.get_item('target_path'))
|
step_args['output_path'] = suggest_output_path(step_args.get('output_path'), state_manager.get_item('target_path'))
|
||||||
|
|
||||||
if job_action == 'job-create':
|
if job_action == 'job-create':
|
||||||
if created_job_id and job_manager.create_job(created_job_id):
|
if created_job_id and job_manager.create_job(created_job_id):
|
||||||
updated_job_ids = job_manager.find_job_ids('drafted') or [ 'none' ]
|
updated_job_ids = job_manager.find_job_ids('drafted') or [ 'none' ]
|
||||||
@@ -97,6 +98,7 @@ def apply(job_action : JobManagerAction, created_job_id : str, selected_job_id :
|
|||||||
return gradio.Dropdown(value = 'job-add-step'), gradio.Textbox(visible = False), gradio.Dropdown(value = created_job_id, choices = updated_job_ids, visible = True), gradio.Dropdown()
|
return gradio.Dropdown(value = 'job-add-step'), gradio.Textbox(visible = False), gradio.Dropdown(value = created_job_id, choices = updated_job_ids, visible = True), gradio.Dropdown()
|
||||||
else:
|
else:
|
||||||
logger.error(wording.get('job_not_created').format(job_id = created_job_id), __name__)
|
logger.error(wording.get('job_not_created').format(job_id = created_job_id), __name__)
|
||||||
|
|
||||||
if job_action == 'job-submit':
|
if job_action == 'job-submit':
|
||||||
if selected_job_id and job_manager.submit_job(selected_job_id):
|
if selected_job_id and job_manager.submit_job(selected_job_id):
|
||||||
updated_job_ids = job_manager.find_job_ids('drafted') or [ 'none' ]
|
updated_job_ids = job_manager.find_job_ids('drafted') or [ 'none' ]
|
||||||
@@ -105,6 +107,7 @@ def apply(job_action : JobManagerAction, created_job_id : str, selected_job_id :
|
|||||||
return gradio.Dropdown(), gradio.Textbox(), gradio.Dropdown(value = get_last(updated_job_ids), choices = updated_job_ids, visible = True), gradio.Dropdown()
|
return gradio.Dropdown(), gradio.Textbox(), gradio.Dropdown(value = get_last(updated_job_ids), choices = updated_job_ids, visible = True), gradio.Dropdown()
|
||||||
else:
|
else:
|
||||||
logger.error(wording.get('job_not_submitted').format(job_id = selected_job_id), __name__)
|
logger.error(wording.get('job_not_submitted').format(job_id = selected_job_id), __name__)
|
||||||
|
|
||||||
if job_action == 'job-delete':
|
if job_action == 'job-delete':
|
||||||
if selected_job_id and job_manager.delete_job(selected_job_id):
|
if selected_job_id and job_manager.delete_job(selected_job_id):
|
||||||
updated_job_ids = job_manager.find_job_ids('drafted') + job_manager.find_job_ids('queued') + job_manager.find_job_ids('failed') + job_manager.find_job_ids('completed') or [ 'none' ]
|
updated_job_ids = job_manager.find_job_ids('drafted') + job_manager.find_job_ids('queued') + job_manager.find_job_ids('failed') + job_manager.find_job_ids('completed') or [ 'none' ]
|
||||||
@@ -113,6 +116,7 @@ def apply(job_action : JobManagerAction, created_job_id : str, selected_job_id :
|
|||||||
return gradio.Dropdown(), gradio.Textbox(), gradio.Dropdown(value = get_last(updated_job_ids), choices = updated_job_ids, visible = True), gradio.Dropdown()
|
return gradio.Dropdown(), gradio.Textbox(), gradio.Dropdown(value = get_last(updated_job_ids), choices = updated_job_ids, visible = True), gradio.Dropdown()
|
||||||
else:
|
else:
|
||||||
logger.error(wording.get('job_not_deleted').format(job_id = selected_job_id), __name__)
|
logger.error(wording.get('job_not_deleted').format(job_id = selected_job_id), __name__)
|
||||||
|
|
||||||
if job_action == 'job-add-step':
|
if job_action == 'job-add-step':
|
||||||
if selected_job_id and job_manager.add_step(selected_job_id, step_args):
|
if selected_job_id and job_manager.add_step(selected_job_id, step_args):
|
||||||
state_manager.set_item('output_path', output_path)
|
state_manager.set_item('output_path', output_path)
|
||||||
@@ -121,6 +125,7 @@ def apply(job_action : JobManagerAction, created_job_id : str, selected_job_id :
|
|||||||
else:
|
else:
|
||||||
state_manager.set_item('output_path', output_path)
|
state_manager.set_item('output_path', output_path)
|
||||||
logger.error(wording.get('job_step_not_added').format(job_id = selected_job_id), __name__)
|
logger.error(wording.get('job_step_not_added').format(job_id = selected_job_id), __name__)
|
||||||
|
|
||||||
if job_action == 'job-remix-step':
|
if job_action == 'job-remix-step':
|
||||||
if selected_job_id and job_manager.has_step(selected_job_id, selected_step_index) and job_manager.remix_step(selected_job_id, selected_step_index, step_args):
|
if selected_job_id and job_manager.has_step(selected_job_id, selected_step_index) and job_manager.remix_step(selected_job_id, selected_step_index, step_args):
|
||||||
updated_step_choices = get_step_choices(selected_job_id) or [ 'none' ] #type:ignore[list-item]
|
updated_step_choices = get_step_choices(selected_job_id) or [ 'none' ] #type:ignore[list-item]
|
||||||
@@ -131,6 +136,7 @@ def apply(job_action : JobManagerAction, created_job_id : str, selected_job_id :
|
|||||||
else:
|
else:
|
||||||
state_manager.set_item('output_path', output_path)
|
state_manager.set_item('output_path', output_path)
|
||||||
logger.error(wording.get('job_remix_step_not_added').format(job_id = selected_job_id, step_index = selected_step_index), __name__)
|
logger.error(wording.get('job_remix_step_not_added').format(job_id = selected_job_id, step_index = selected_step_index), __name__)
|
||||||
|
|
||||||
if job_action == 'job-insert-step':
|
if job_action == 'job-insert-step':
|
||||||
if selected_job_id and job_manager.has_step(selected_job_id, selected_step_index) and job_manager.insert_step(selected_job_id, selected_step_index, step_args):
|
if selected_job_id and job_manager.has_step(selected_job_id, selected_step_index) and job_manager.insert_step(selected_job_id, selected_step_index, step_args):
|
||||||
updated_step_choices = get_step_choices(selected_job_id) or [ 'none' ] #type:ignore[list-item]
|
updated_step_choices = get_step_choices(selected_job_id) or [ 'none' ] #type:ignore[list-item]
|
||||||
@@ -141,6 +147,7 @@ def apply(job_action : JobManagerAction, created_job_id : str, selected_job_id :
|
|||||||
else:
|
else:
|
||||||
state_manager.set_item('output_path', output_path)
|
state_manager.set_item('output_path', output_path)
|
||||||
logger.error(wording.get('job_step_not_inserted').format(job_id = selected_job_id, step_index = selected_step_index), __name__)
|
logger.error(wording.get('job_step_not_inserted').format(job_id = selected_job_id, step_index = selected_step_index), __name__)
|
||||||
|
|
||||||
if job_action == 'job-remove-step':
|
if job_action == 'job-remove-step':
|
||||||
if selected_job_id and job_manager.has_step(selected_job_id, selected_step_index) and job_manager.remove_step(selected_job_id, selected_step_index):
|
if selected_job_id and job_manager.has_step(selected_job_id, selected_step_index) and job_manager.remove_step(selected_job_id, selected_step_index):
|
||||||
updated_step_choices = get_step_choices(selected_job_id) or [ 'none' ] #type:ignore[list-item]
|
updated_step_choices = get_step_choices(selected_job_id) or [ 'none' ] #type:ignore[list-item]
|
||||||
@@ -160,16 +167,19 @@ def get_step_choices(job_id : str) -> List[int]:
|
|||||||
def update(job_action : JobManagerAction, selected_job_id : str) -> Tuple[gradio.Textbox, gradio.Dropdown, gradio.Dropdown]:
|
def update(job_action : JobManagerAction, selected_job_id : str) -> Tuple[gradio.Textbox, gradio.Dropdown, gradio.Dropdown]:
|
||||||
if job_action == 'job-create':
|
if job_action == 'job-create':
|
||||||
return gradio.Textbox(value = None, visible = True), gradio.Dropdown(visible = False), gradio.Dropdown(visible = False)
|
return gradio.Textbox(value = None, visible = True), gradio.Dropdown(visible = False), gradio.Dropdown(visible = False)
|
||||||
|
|
||||||
if job_action == 'job-delete':
|
if job_action == 'job-delete':
|
||||||
updated_job_ids = job_manager.find_job_ids('drafted') + job_manager.find_job_ids('queued') + job_manager.find_job_ids('failed') + job_manager.find_job_ids('completed') or [ 'none' ]
|
updated_job_ids = job_manager.find_job_ids('drafted') + job_manager.find_job_ids('queued') + job_manager.find_job_ids('failed') + job_manager.find_job_ids('completed') or [ 'none' ]
|
||||||
updated_job_id = selected_job_id if selected_job_id in updated_job_ids else get_last(updated_job_ids)
|
updated_job_id = selected_job_id if selected_job_id in updated_job_ids else get_last(updated_job_ids)
|
||||||
|
|
||||||
return gradio.Textbox(visible = False), gradio.Dropdown(value = updated_job_id, choices = updated_job_ids, visible = True), gradio.Dropdown(visible = False)
|
return gradio.Textbox(visible = False), gradio.Dropdown(value = updated_job_id, choices = updated_job_ids, visible = True), gradio.Dropdown(visible = False)
|
||||||
|
|
||||||
if job_action in [ 'job-submit', 'job-add-step' ]:
|
if job_action in [ 'job-submit', 'job-add-step' ]:
|
||||||
updated_job_ids = job_manager.find_job_ids('drafted') or [ 'none' ]
|
updated_job_ids = job_manager.find_job_ids('drafted') or [ 'none' ]
|
||||||
updated_job_id = selected_job_id if selected_job_id in updated_job_ids else get_last(updated_job_ids)
|
updated_job_id = selected_job_id if selected_job_id in updated_job_ids else get_last(updated_job_ids)
|
||||||
|
|
||||||
return gradio.Textbox(visible = False), gradio.Dropdown(value = updated_job_id, choices = updated_job_ids, visible = True), gradio.Dropdown(visible = False)
|
return gradio.Textbox(visible = False), gradio.Dropdown(value = updated_job_id, choices = updated_job_ids, visible = True), gradio.Dropdown(visible = False)
|
||||||
|
|
||||||
if job_action in [ 'job-remix-step', 'job-insert-step', 'job-remove-step' ]:
|
if job_action in [ 'job-remix-step', 'job-insert-step', 'job-remove-step' ]:
|
||||||
updated_job_ids = job_manager.find_job_ids('drafted') or [ 'none' ]
|
updated_job_ids = job_manager.find_job_ids('drafted') or [ 'none' ]
|
||||||
updated_job_id = selected_job_id if selected_job_id in updated_job_ids else get_last(updated_job_ids)
|
updated_job_id = selected_job_id if selected_job_id in updated_job_ids else get_last(updated_job_ids)
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ from facefusion import logger, process_manager, state_manager, wording
|
|||||||
from facefusion.common_helper import get_first, get_last
|
from facefusion.common_helper import get_first, get_last
|
||||||
from facefusion.core import process_step
|
from facefusion.core import process_step
|
||||||
from facefusion.jobs import job_manager, job_runner, job_store
|
from facefusion.jobs import job_manager, job_runner, job_store
|
||||||
from facefusion.typing import UiWorkflow
|
from facefusion.types import UiWorkflow
|
||||||
from facefusion.uis import choices as uis_choices
|
from facefusion.uis import choices as uis_choices
|
||||||
from facefusion.uis.core import get_ui_component
|
from facefusion.uis.core import get_ui_component
|
||||||
from facefusion.uis.typing import JobRunnerAction
|
from facefusion.uis.types import JobRunnerAction
|
||||||
from facefusion.uis.ui_helper import convert_str_none
|
from facefusion.uis.ui_helper import convert_str_none
|
||||||
|
|
||||||
JOB_RUNNER_WRAPPER : Optional[gradio.Column] = None
|
JOB_RUNNER_WRAPPER : Optional[gradio.Column] = None
|
||||||
@@ -84,7 +84,7 @@ def run(job_action : JobRunnerAction, job_id : str) -> Tuple[gradio.Button, grad
|
|||||||
job_id = convert_str_none(job_id)
|
job_id = convert_str_none(job_id)
|
||||||
|
|
||||||
for key in job_store.get_job_keys():
|
for key in job_store.get_job_keys():
|
||||||
state_manager.sync_item(key) #type:ignore
|
state_manager.sync_item(key) #type:ignore[arg-type]
|
||||||
|
|
||||||
if job_action == 'job-run':
|
if job_action == 'job-run':
|
||||||
logger.info(wording.get('running_job').format(job_id = job_id), __name__)
|
logger.info(wording.get('running_job').format(job_id = job_id), __name__)
|
||||||
@@ -95,12 +95,15 @@ def run(job_action : JobRunnerAction, job_id : str) -> Tuple[gradio.Button, grad
|
|||||||
updated_job_ids = job_manager.find_job_ids('queued') or [ 'none' ]
|
updated_job_ids = job_manager.find_job_ids('queued') or [ 'none' ]
|
||||||
|
|
||||||
return gradio.Button(visible = True), gradio.Button(visible = False), gradio.Dropdown(value = get_last(updated_job_ids), choices = updated_job_ids)
|
return gradio.Button(visible = True), gradio.Button(visible = False), gradio.Dropdown(value = get_last(updated_job_ids), choices = updated_job_ids)
|
||||||
|
|
||||||
if job_action == 'job-run-all':
|
if job_action == 'job-run-all':
|
||||||
logger.info(wording.get('running_jobs'), __name__)
|
logger.info(wording.get('running_jobs'), __name__)
|
||||||
if job_runner.run_jobs(process_step):
|
halt_on_error = False
|
||||||
|
if job_runner.run_jobs(process_step, halt_on_error):
|
||||||
logger.info(wording.get('processing_jobs_succeed'), __name__)
|
logger.info(wording.get('processing_jobs_succeed'), __name__)
|
||||||
else:
|
else:
|
||||||
logger.info(wording.get('processing_jobs_failed'), __name__)
|
logger.info(wording.get('processing_jobs_failed'), __name__)
|
||||||
|
|
||||||
if job_action == 'job-retry':
|
if job_action == 'job-retry':
|
||||||
logger.info(wording.get('retrying_job').format(job_id = job_id), __name__)
|
logger.info(wording.get('retrying_job').format(job_id = job_id), __name__)
|
||||||
if job_id and job_runner.retry_job(job_id, process_step):
|
if job_id and job_runner.retry_job(job_id, process_step):
|
||||||
@@ -110,9 +113,11 @@ def run(job_action : JobRunnerAction, job_id : str) -> Tuple[gradio.Button, grad
|
|||||||
updated_job_ids = job_manager.find_job_ids('failed') or [ 'none' ]
|
updated_job_ids = job_manager.find_job_ids('failed') or [ 'none' ]
|
||||||
|
|
||||||
return gradio.Button(visible = True), gradio.Button(visible = False), gradio.Dropdown(value = get_last(updated_job_ids), choices = updated_job_ids)
|
return gradio.Button(visible = True), gradio.Button(visible = False), gradio.Dropdown(value = get_last(updated_job_ids), choices = updated_job_ids)
|
||||||
|
|
||||||
if job_action == 'job-retry-all':
|
if job_action == 'job-retry-all':
|
||||||
logger.info(wording.get('retrying_jobs'), __name__)
|
logger.info(wording.get('retrying_jobs'), __name__)
|
||||||
if job_runner.retry_jobs(process_step):
|
halt_on_error = False
|
||||||
|
if job_runner.retry_jobs(process_step, halt_on_error):
|
||||||
logger.info(wording.get('processing_jobs_succeed'), __name__)
|
logger.info(wording.get('processing_jobs_succeed'), __name__)
|
||||||
else:
|
else:
|
||||||
logger.info(wording.get('processing_jobs_failed'), __name__)
|
logger.info(wording.get('processing_jobs_failed'), __name__)
|
||||||
@@ -129,6 +134,7 @@ def update_job_action(job_action : JobRunnerAction) -> gradio.Dropdown:
|
|||||||
updated_job_ids = job_manager.find_job_ids('queued') or [ 'none' ]
|
updated_job_ids = job_manager.find_job_ids('queued') or [ 'none' ]
|
||||||
|
|
||||||
return gradio.Dropdown(value = get_last(updated_job_ids), choices = updated_job_ids, visible = True)
|
return gradio.Dropdown(value = get_last(updated_job_ids), choices = updated_job_ids, visible = True)
|
||||||
|
|
||||||
if job_action == 'job-retry':
|
if job_action == 'job-retry':
|
||||||
updated_job_ids = job_manager.find_job_ids('failed') or [ 'none' ]
|
updated_job_ids = job_manager.find_job_ids('failed') or [ 'none' ]
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import gradio
|
|||||||
from facefusion import state_manager, wording
|
from facefusion import state_manager, wording
|
||||||
from facefusion.processors import choices as processors_choices
|
from facefusion.processors import choices as processors_choices
|
||||||
from facefusion.processors.core import load_processor_module
|
from facefusion.processors.core import load_processor_module
|
||||||
from facefusion.processors.typing import LipSyncerModel
|
from facefusion.processors.types import LipSyncerModel
|
||||||
from facefusion.uis.core import get_ui_component, register_ui_component
|
from facefusion.uis.core import get_ui_component, register_ui_component
|
||||||
|
|
||||||
LIP_SYNCER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
LIP_SYNCER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
@@ -14,11 +14,12 @@ LIP_SYNCER_MODEL_DROPDOWN : Optional[gradio.Dropdown] = None
|
|||||||
def render() -> None:
|
def render() -> None:
|
||||||
global LIP_SYNCER_MODEL_DROPDOWN
|
global LIP_SYNCER_MODEL_DROPDOWN
|
||||||
|
|
||||||
|
has_lip_syncer = 'lip_syncer' in state_manager.get_item('processors')
|
||||||
LIP_SYNCER_MODEL_DROPDOWN = gradio.Dropdown(
|
LIP_SYNCER_MODEL_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.lip_syncer_model_dropdown'),
|
label = wording.get('uis.lip_syncer_model_dropdown'),
|
||||||
choices = processors_choices.lip_syncer_models,
|
choices = processors_choices.lip_syncer_models,
|
||||||
value = state_manager.get_item('lip_syncer_model'),
|
value = state_manager.get_item('lip_syncer_model'),
|
||||||
visible = 'lip_syncer' in state_manager.get_item('processors')
|
visible = has_lip_syncer
|
||||||
)
|
)
|
||||||
register_ui_component('lip_syncer_model_dropdown', LIP_SYNCER_MODEL_DROPDOWN)
|
register_ui_component('lip_syncer_model_dropdown', LIP_SYNCER_MODEL_DROPDOWN)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import gradio
|
|||||||
import facefusion.choices
|
import facefusion.choices
|
||||||
from facefusion import state_manager, wording
|
from facefusion import state_manager, wording
|
||||||
from facefusion.common_helper import calc_int_step
|
from facefusion.common_helper import calc_int_step
|
||||||
from facefusion.typing import VideoMemoryStrategy
|
from facefusion.types import VideoMemoryStrategy
|
||||||
|
|
||||||
VIDEO_MEMORY_STRATEGY_DROPDOWN : Optional[gradio.Dropdown] = None
|
VIDEO_MEMORY_STRATEGY_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
SYSTEM_MEMORY_LIMIT_SLIDER : Optional[gradio.Slider] = None
|
SYSTEM_MEMORY_LIMIT_SLIDER : Optional[gradio.Slider] = None
|
||||||
|
|||||||
@@ -5,14 +5,17 @@ import gradio
|
|||||||
import facefusion.choices
|
import facefusion.choices
|
||||||
from facefusion import state_manager, wording
|
from facefusion import state_manager, wording
|
||||||
from facefusion.common_helper import calc_int_step
|
from facefusion.common_helper import calc_int_step
|
||||||
|
from facefusion.ffmpeg import get_available_encoder_set
|
||||||
from facefusion.filesystem import is_image, is_video
|
from facefusion.filesystem import is_image, is_video
|
||||||
from facefusion.typing import Fps, OutputAudioEncoder, OutputVideoEncoder, OutputVideoPreset
|
from facefusion.types import AudioEncoder, Fps, VideoEncoder, VideoPreset
|
||||||
from facefusion.uis.core import get_ui_components, register_ui_component
|
from facefusion.uis.core import get_ui_components, register_ui_component
|
||||||
from facefusion.vision import create_image_resolutions, create_video_resolutions, detect_image_resolution, detect_video_fps, detect_video_resolution, pack_resolution
|
from facefusion.vision import create_image_resolutions, create_video_resolutions, detect_image_resolution, detect_video_fps, detect_video_resolution, pack_resolution
|
||||||
|
|
||||||
OUTPUT_IMAGE_QUALITY_SLIDER : Optional[gradio.Slider] = None
|
OUTPUT_IMAGE_QUALITY_SLIDER : Optional[gradio.Slider] = None
|
||||||
OUTPUT_IMAGE_RESOLUTION_DROPDOWN : Optional[gradio.Dropdown] = None
|
OUTPUT_IMAGE_RESOLUTION_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
OUTPUT_AUDIO_ENCODER_DROPDOWN : Optional[gradio.Dropdown] = None
|
OUTPUT_AUDIO_ENCODER_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
|
OUTPUT_AUDIO_QUALITY_SLIDER : Optional[gradio.Slider] = None
|
||||||
|
OUTPUT_AUDIO_VOLUME_SLIDER : Optional[gradio.Slider] = None
|
||||||
OUTPUT_VIDEO_ENCODER_DROPDOWN : Optional[gradio.Dropdown] = None
|
OUTPUT_VIDEO_ENCODER_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
OUTPUT_VIDEO_PRESET_DROPDOWN : Optional[gradio.Dropdown] = None
|
OUTPUT_VIDEO_PRESET_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
OUTPUT_VIDEO_RESOLUTION_DROPDOWN : Optional[gradio.Dropdown] = None
|
OUTPUT_VIDEO_RESOLUTION_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||||
@@ -24,6 +27,8 @@ def render() -> None:
|
|||||||
global OUTPUT_IMAGE_QUALITY_SLIDER
|
global OUTPUT_IMAGE_QUALITY_SLIDER
|
||||||
global OUTPUT_IMAGE_RESOLUTION_DROPDOWN
|
global OUTPUT_IMAGE_RESOLUTION_DROPDOWN
|
||||||
global OUTPUT_AUDIO_ENCODER_DROPDOWN
|
global OUTPUT_AUDIO_ENCODER_DROPDOWN
|
||||||
|
global OUTPUT_AUDIO_QUALITY_SLIDER
|
||||||
|
global OUTPUT_AUDIO_VOLUME_SLIDER
|
||||||
global OUTPUT_VIDEO_ENCODER_DROPDOWN
|
global OUTPUT_VIDEO_ENCODER_DROPDOWN
|
||||||
global OUTPUT_VIDEO_PRESET_DROPDOWN
|
global OUTPUT_VIDEO_PRESET_DROPDOWN
|
||||||
global OUTPUT_VIDEO_RESOLUTION_DROPDOWN
|
global OUTPUT_VIDEO_RESOLUTION_DROPDOWN
|
||||||
@@ -32,6 +37,7 @@ def render() -> None:
|
|||||||
|
|
||||||
output_image_resolutions = []
|
output_image_resolutions = []
|
||||||
output_video_resolutions = []
|
output_video_resolutions = []
|
||||||
|
available_encoder_set = get_available_encoder_set()
|
||||||
if is_image(state_manager.get_item('target_path')):
|
if is_image(state_manager.get_item('target_path')):
|
||||||
output_image_resolution = detect_image_resolution(state_manager.get_item('target_path'))
|
output_image_resolution = detect_image_resolution(state_manager.get_item('target_path'))
|
||||||
output_image_resolutions = create_image_resolutions(output_image_resolution)
|
output_image_resolutions = create_image_resolutions(output_image_resolution)
|
||||||
@@ -54,13 +60,29 @@ def render() -> None:
|
|||||||
)
|
)
|
||||||
OUTPUT_AUDIO_ENCODER_DROPDOWN = gradio.Dropdown(
|
OUTPUT_AUDIO_ENCODER_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.output_audio_encoder_dropdown'),
|
label = wording.get('uis.output_audio_encoder_dropdown'),
|
||||||
choices = facefusion.choices.output_audio_encoders,
|
choices = available_encoder_set.get('audio'),
|
||||||
value = state_manager.get_item('output_audio_encoder'),
|
value = state_manager.get_item('output_audio_encoder'),
|
||||||
visible = is_video(state_manager.get_item('target_path'))
|
visible = is_video(state_manager.get_item('target_path'))
|
||||||
)
|
)
|
||||||
|
OUTPUT_AUDIO_QUALITY_SLIDER = gradio.Slider(
|
||||||
|
label = wording.get('uis.output_audio_quality_slider'),
|
||||||
|
value = state_manager.get_item('output_audio_quality'),
|
||||||
|
step = calc_int_step(facefusion.choices.output_audio_quality_range),
|
||||||
|
minimum = facefusion.choices.output_audio_quality_range[0],
|
||||||
|
maximum = facefusion.choices.output_audio_quality_range[-1],
|
||||||
|
visible = is_video(state_manager.get_item('target_path'))
|
||||||
|
)
|
||||||
|
OUTPUT_AUDIO_VOLUME_SLIDER = gradio.Slider(
|
||||||
|
label = wording.get('uis.output_audio_volume_slider'),
|
||||||
|
value = state_manager.get_item('output_audio_volume'),
|
||||||
|
step = calc_int_step(facefusion.choices.output_audio_volume_range),
|
||||||
|
minimum = facefusion.choices.output_audio_volume_range[0],
|
||||||
|
maximum = facefusion.choices.output_audio_volume_range[-1],
|
||||||
|
visible = is_video(state_manager.get_item('target_path'))
|
||||||
|
)
|
||||||
OUTPUT_VIDEO_ENCODER_DROPDOWN = gradio.Dropdown(
|
OUTPUT_VIDEO_ENCODER_DROPDOWN = gradio.Dropdown(
|
||||||
label = wording.get('uis.output_video_encoder_dropdown'),
|
label = wording.get('uis.output_video_encoder_dropdown'),
|
||||||
choices = facefusion.choices.output_video_encoders,
|
choices = available_encoder_set.get('video'),
|
||||||
value = state_manager.get_item('output_video_encoder'),
|
value = state_manager.get_item('output_video_encoder'),
|
||||||
visible = is_video(state_manager.get_item('target_path'))
|
visible = is_video(state_manager.get_item('target_path'))
|
||||||
)
|
)
|
||||||
@@ -99,6 +121,8 @@ def listen() -> None:
|
|||||||
OUTPUT_IMAGE_QUALITY_SLIDER.release(update_output_image_quality, inputs = OUTPUT_IMAGE_QUALITY_SLIDER)
|
OUTPUT_IMAGE_QUALITY_SLIDER.release(update_output_image_quality, inputs = OUTPUT_IMAGE_QUALITY_SLIDER)
|
||||||
OUTPUT_IMAGE_RESOLUTION_DROPDOWN.change(update_output_image_resolution, inputs = OUTPUT_IMAGE_RESOLUTION_DROPDOWN)
|
OUTPUT_IMAGE_RESOLUTION_DROPDOWN.change(update_output_image_resolution, inputs = OUTPUT_IMAGE_RESOLUTION_DROPDOWN)
|
||||||
OUTPUT_AUDIO_ENCODER_DROPDOWN.change(update_output_audio_encoder, inputs = OUTPUT_AUDIO_ENCODER_DROPDOWN)
|
OUTPUT_AUDIO_ENCODER_DROPDOWN.change(update_output_audio_encoder, inputs = OUTPUT_AUDIO_ENCODER_DROPDOWN)
|
||||||
|
OUTPUT_AUDIO_QUALITY_SLIDER.release(update_output_audio_quality, inputs = OUTPUT_AUDIO_QUALITY_SLIDER)
|
||||||
|
OUTPUT_AUDIO_VOLUME_SLIDER.release(update_output_audio_volume, inputs = OUTPUT_AUDIO_VOLUME_SLIDER)
|
||||||
OUTPUT_VIDEO_ENCODER_DROPDOWN.change(update_output_video_encoder, inputs = OUTPUT_VIDEO_ENCODER_DROPDOWN)
|
OUTPUT_VIDEO_ENCODER_DROPDOWN.change(update_output_video_encoder, inputs = OUTPUT_VIDEO_ENCODER_DROPDOWN)
|
||||||
OUTPUT_VIDEO_PRESET_DROPDOWN.change(update_output_video_preset, inputs = OUTPUT_VIDEO_PRESET_DROPDOWN)
|
OUTPUT_VIDEO_PRESET_DROPDOWN.change(update_output_video_preset, inputs = OUTPUT_VIDEO_PRESET_DROPDOWN)
|
||||||
OUTPUT_VIDEO_QUALITY_SLIDER.release(update_output_video_quality, inputs = OUTPUT_VIDEO_QUALITY_SLIDER)
|
OUTPUT_VIDEO_QUALITY_SLIDER.release(update_output_video_quality, inputs = OUTPUT_VIDEO_QUALITY_SLIDER)
|
||||||
@@ -110,23 +134,23 @@ def listen() -> None:
|
|||||||
'target_image',
|
'target_image',
|
||||||
'target_video'
|
'target_video'
|
||||||
]):
|
]):
|
||||||
for method in [ 'upload', 'change', 'clear' ]:
|
for method in [ 'change', 'clear' ]:
|
||||||
getattr(ui_component, method)(remote_update, outputs = [ OUTPUT_IMAGE_QUALITY_SLIDER, OUTPUT_IMAGE_RESOLUTION_DROPDOWN, OUTPUT_AUDIO_ENCODER_DROPDOWN, OUTPUT_VIDEO_ENCODER_DROPDOWN, OUTPUT_VIDEO_PRESET_DROPDOWN, OUTPUT_VIDEO_QUALITY_SLIDER, OUTPUT_VIDEO_RESOLUTION_DROPDOWN, OUTPUT_VIDEO_FPS_SLIDER ])
|
getattr(ui_component, method)(remote_update, outputs = [ OUTPUT_IMAGE_QUALITY_SLIDER, OUTPUT_IMAGE_RESOLUTION_DROPDOWN, OUTPUT_AUDIO_ENCODER_DROPDOWN, OUTPUT_AUDIO_QUALITY_SLIDER, OUTPUT_AUDIO_VOLUME_SLIDER, OUTPUT_VIDEO_ENCODER_DROPDOWN, OUTPUT_VIDEO_PRESET_DROPDOWN, OUTPUT_VIDEO_QUALITY_SLIDER, OUTPUT_VIDEO_RESOLUTION_DROPDOWN, OUTPUT_VIDEO_FPS_SLIDER ])
|
||||||
|
|
||||||
|
|
||||||
def remote_update() -> Tuple[gradio.Slider, gradio.Dropdown, gradio.Dropdown, gradio.Dropdown, gradio.Dropdown, gradio.Slider, gradio.Dropdown, gradio.Slider]:
|
def remote_update() -> Tuple[gradio.Slider, gradio.Dropdown, gradio.Dropdown, gradio.Slider, gradio.Slider, gradio.Dropdown, gradio.Dropdown, gradio.Slider, gradio.Dropdown, gradio.Slider]:
|
||||||
if is_image(state_manager.get_item('target_path')):
|
if is_image(state_manager.get_item('target_path')):
|
||||||
output_image_resolution = detect_image_resolution(state_manager.get_item('target_path'))
|
output_image_resolution = detect_image_resolution(state_manager.get_item('target_path'))
|
||||||
output_image_resolutions = create_image_resolutions(output_image_resolution)
|
output_image_resolutions = create_image_resolutions(output_image_resolution)
|
||||||
state_manager.set_item('output_image_resolution', pack_resolution(output_image_resolution))
|
state_manager.set_item('output_image_resolution', pack_resolution(output_image_resolution))
|
||||||
return gradio.Slider(visible = True), gradio.Dropdown(value = state_manager.get_item('output_image_resolution'), choices = output_image_resolutions, visible = True), gradio.Dropdown(visible = False), gradio.Dropdown(visible = False), gradio.Dropdown(visible = False), gradio.Slider(visible = False), gradio.Dropdown(visible = False), gradio.Slider(visible = False)
|
return gradio.Slider(visible = True), gradio.Dropdown(value = state_manager.get_item('output_image_resolution'), choices = output_image_resolutions, visible = True), gradio.Dropdown(visible = False), gradio.Slider(visible = False), gradio.Slider(visible = False), gradio.Dropdown(visible = False), gradio.Dropdown(visible = False), gradio.Slider(visible = False), gradio.Dropdown(visible = False), gradio.Slider(visible = False)
|
||||||
if is_video(state_manager.get_item('target_path')):
|
if is_video(state_manager.get_item('target_path')):
|
||||||
output_video_resolution = detect_video_resolution(state_manager.get_item('target_path'))
|
output_video_resolution = detect_video_resolution(state_manager.get_item('target_path'))
|
||||||
output_video_resolutions = create_video_resolutions(output_video_resolution)
|
output_video_resolutions = create_video_resolutions(output_video_resolution)
|
||||||
state_manager.set_item('output_video_resolution', pack_resolution(output_video_resolution))
|
state_manager.set_item('output_video_resolution', pack_resolution(output_video_resolution))
|
||||||
state_manager.set_item('output_video_fps', detect_video_fps(state_manager.get_item('target_path')))
|
state_manager.set_item('output_video_fps', detect_video_fps(state_manager.get_item('target_path')))
|
||||||
return gradio.Slider(visible = False), gradio.Dropdown(visible = False), gradio.Dropdown(visible = True), gradio.Dropdown(visible = True), gradio.Dropdown(visible = True), gradio.Slider(visible = True), gradio.Dropdown(value = state_manager.get_item('output_video_resolution'), choices = output_video_resolutions, visible = True), gradio.Slider(value = state_manager.get_item('output_video_fps'), visible = True)
|
return gradio.Slider(visible = False), gradio.Dropdown(visible = False), gradio.Dropdown(visible = True), gradio.Slider(visible = True), gradio.Slider(visible = True), gradio.Dropdown(visible = True), gradio.Dropdown(visible = True), gradio.Slider(visible = True), gradio.Dropdown(value = state_manager.get_item('output_video_resolution'), choices = output_video_resolutions, visible = True), gradio.Slider(value = state_manager.get_item('output_video_fps'), visible = True)
|
||||||
return gradio.Slider(visible = False), gradio.Dropdown(visible = False), gradio.Dropdown(visible = False), gradio.Dropdown(visible = False), gradio.Dropdown(visible = False), gradio.Slider(visible = False), gradio.Dropdown(visible = False), gradio.Slider(visible = False)
|
return gradio.Slider(visible = False), gradio.Dropdown(visible = False), gradio.Dropdown(visible = False), gradio.Slider(visible = False), gradio.Slider(visible = False), gradio.Dropdown(visible = False), gradio.Dropdown(visible = False), gradio.Slider(visible = False), gradio.Dropdown(visible = False), gradio.Slider(visible = False)
|
||||||
|
|
||||||
|
|
||||||
def update_output_image_quality(output_image_quality : float) -> None:
|
def update_output_image_quality(output_image_quality : float) -> None:
|
||||||
@@ -137,15 +161,23 @@ def update_output_image_resolution(output_image_resolution : str) -> None:
|
|||||||
state_manager.set_item('output_image_resolution', output_image_resolution)
|
state_manager.set_item('output_image_resolution', output_image_resolution)
|
||||||
|
|
||||||
|
|
||||||
def update_output_audio_encoder(output_audio_encoder : OutputAudioEncoder) -> None:
|
def update_output_audio_encoder(output_audio_encoder : AudioEncoder) -> None:
|
||||||
state_manager.set_item('output_audio_encoder', output_audio_encoder)
|
state_manager.set_item('output_audio_encoder', output_audio_encoder)
|
||||||
|
|
||||||
|
|
||||||
def update_output_video_encoder(output_video_encoder : OutputVideoEncoder) -> None:
|
def update_output_audio_quality(output_audio_quality : float) -> None:
|
||||||
|
state_manager.set_item('output_audio_quality', int(output_audio_quality))
|
||||||
|
|
||||||
|
|
||||||
|
def update_output_audio_volume(output_audio_volume: float) -> None:
|
||||||
|
state_manager.set_item('output_audio_volume', int(output_audio_volume))
|
||||||
|
|
||||||
|
|
||||||
|
def update_output_video_encoder(output_video_encoder : VideoEncoder) -> None:
|
||||||
state_manager.set_item('output_video_encoder', output_video_encoder)
|
state_manager.set_item('output_video_encoder', output_video_encoder)
|
||||||
|
|
||||||
|
|
||||||
def update_output_video_preset(output_video_preset : OutputVideoPreset) -> None:
|
def update_output_video_preset(output_video_preset : VideoPreset) -> None:
|
||||||
state_manager.set_item('output_video_preset', output_video_preset)
|
state_manager.set_item('output_video_preset', output_video_preset)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ from facefusion.common_helper import get_first
|
|||||||
from facefusion.content_analyser import analyse_frame
|
from facefusion.content_analyser import analyse_frame
|
||||||
from facefusion.core import conditional_append_reference_faces
|
from facefusion.core import conditional_append_reference_faces
|
||||||
from facefusion.face_analyser import get_average_face, get_many_faces
|
from facefusion.face_analyser import get_average_face, get_many_faces
|
||||||
|
from facefusion.face_selector import sort_faces_by_order
|
||||||
from facefusion.face_store import clear_reference_faces, clear_static_faces, get_reference_faces
|
from facefusion.face_store import clear_reference_faces, clear_static_faces, get_reference_faces
|
||||||
from facefusion.filesystem import filter_audio_paths, is_image, is_video
|
from facefusion.filesystem import filter_audio_paths, is_image, is_video
|
||||||
from facefusion.processors.core import get_processors_modules
|
from facefusion.processors.core import get_processors_modules
|
||||||
from facefusion.typing import AudioFrame, Face, FaceSet, VisionFrame
|
from facefusion.types import AudioFrame, Face, FaceSet, VisionFrame
|
||||||
from facefusion.uis.core import get_ui_component, get_ui_components, register_ui_component
|
from facefusion.uis.core import get_ui_component, get_ui_components, register_ui_component
|
||||||
from facefusion.uis.typing import ComponentOptions
|
from facefusion.uis.types import ComponentOptions
|
||||||
from facefusion.vision import count_video_frame_total, detect_frame_orientation, get_video_frame, normalize_frame_color, read_static_image, read_static_images, resize_frame_resolution
|
from facefusion.vision import count_video_frame_total, detect_frame_orientation, normalize_frame_color, read_static_image, read_static_images, read_video_frame, restrict_frame
|
||||||
|
|
||||||
PREVIEW_IMAGE : Optional[gradio.Image] = None
|
PREVIEW_IMAGE : Optional[gradio.Image] = None
|
||||||
PREVIEW_FRAME_SLIDER : Optional[gradio.Slider] = None
|
PREVIEW_FRAME_SLIDER : Optional[gradio.Slider] = None
|
||||||
@@ -59,7 +60,7 @@ def render() -> None:
|
|||||||
preview_image_options['elem_classes'] = [ 'image-preview', 'is-' + detect_frame_orientation(preview_vision_frame) ]
|
preview_image_options['elem_classes'] = [ 'image-preview', 'is-' + detect_frame_orientation(preview_vision_frame) ]
|
||||||
|
|
||||||
if is_video(state_manager.get_item('target_path')):
|
if is_video(state_manager.get_item('target_path')):
|
||||||
temp_vision_frame = get_video_frame(state_manager.get_item('target_path'), state_manager.get_item('reference_frame_number'))
|
temp_vision_frame = read_video_frame(state_manager.get_item('target_path'), state_manager.get_item('reference_frame_number'))
|
||||||
preview_vision_frame = process_preview_frame(reference_faces, source_face, source_audio_frame, temp_vision_frame)
|
preview_vision_frame = process_preview_frame(reference_faces, source_face, source_audio_frame, temp_vision_frame)
|
||||||
preview_image_options['value'] = normalize_frame_color(preview_vision_frame)
|
preview_image_options['value'] = normalize_frame_color(preview_vision_frame)
|
||||||
preview_image_options['elem_classes'] = [ 'image-preview', 'is-' + detect_frame_orientation(preview_vision_frame) ]
|
preview_image_options['elem_classes'] = [ 'image-preview', 'is-' + detect_frame_orientation(preview_vision_frame) ]
|
||||||
@@ -74,7 +75,7 @@ def render() -> None:
|
|||||||
|
|
||||||
def listen() -> None:
|
def listen() -> None:
|
||||||
PREVIEW_FRAME_SLIDER.release(update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE, show_progress = 'hidden')
|
PREVIEW_FRAME_SLIDER.release(update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE, show_progress = 'hidden')
|
||||||
PREVIEW_FRAME_SLIDER.change(slide_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE, show_progress = 'hidden')
|
PREVIEW_FRAME_SLIDER.change(slide_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE, show_progress = 'hidden', trigger_mode = 'once')
|
||||||
|
|
||||||
reference_face_position_gallery = get_ui_component('reference_face_position_gallery')
|
reference_face_position_gallery = get_ui_component('reference_face_position_gallery')
|
||||||
if reference_face_position_gallery:
|
if reference_face_position_gallery:
|
||||||
@@ -87,7 +88,7 @@ def listen() -> None:
|
|||||||
'target_image',
|
'target_image',
|
||||||
'target_video'
|
'target_video'
|
||||||
]):
|
]):
|
||||||
for method in [ 'upload', 'change', 'clear' ]:
|
for method in [ 'change', 'clear' ]:
|
||||||
getattr(ui_component, method)(update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE)
|
getattr(ui_component, method)(update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE)
|
||||||
|
|
||||||
for ui_component in get_ui_components(
|
for ui_component in get_ui_components(
|
||||||
@@ -95,7 +96,7 @@ def listen() -> None:
|
|||||||
'target_image',
|
'target_image',
|
||||||
'target_video'
|
'target_video'
|
||||||
]):
|
]):
|
||||||
for method in [ 'upload', 'change', 'clear' ]:
|
for method in [ 'change', 'clear' ]:
|
||||||
getattr(ui_component, method)(update_preview_frame_slider, outputs = PREVIEW_FRAME_SLIDER)
|
getattr(ui_component, method)(update_preview_frame_slider, outputs = PREVIEW_FRAME_SLIDER)
|
||||||
|
|
||||||
for ui_component in get_ui_components(
|
for ui_component in get_ui_components(
|
||||||
@@ -110,6 +111,7 @@ def listen() -> None:
|
|||||||
for ui_component in get_ui_components(
|
for ui_component in get_ui_components(
|
||||||
[
|
[
|
||||||
'age_modifier_direction_slider',
|
'age_modifier_direction_slider',
|
||||||
|
'deep_swapper_morph_slider',
|
||||||
'expression_restorer_factor_slider',
|
'expression_restorer_factor_slider',
|
||||||
'face_editor_eyebrow_direction_slider',
|
'face_editor_eyebrow_direction_slider',
|
||||||
'face_editor_eye_gaze_horizontal_slider',
|
'face_editor_eye_gaze_horizontal_slider',
|
||||||
@@ -126,6 +128,7 @@ def listen() -> None:
|
|||||||
'face_editor_head_yaw_slider',
|
'face_editor_head_yaw_slider',
|
||||||
'face_editor_head_roll_slider',
|
'face_editor_head_roll_slider',
|
||||||
'face_enhancer_blend_slider',
|
'face_enhancer_blend_slider',
|
||||||
|
'face_enhancer_weight_slider',
|
||||||
'frame_colorizer_blend_slider',
|
'frame_colorizer_blend_slider',
|
||||||
'frame_enhancer_blend_slider',
|
'frame_enhancer_blend_slider',
|
||||||
'reference_face_distance_slider',
|
'reference_face_distance_slider',
|
||||||
@@ -142,6 +145,7 @@ def listen() -> None:
|
|||||||
for ui_component in get_ui_components(
|
for ui_component in get_ui_components(
|
||||||
[
|
[
|
||||||
'age_modifier_model_dropdown',
|
'age_modifier_model_dropdown',
|
||||||
|
'deep_swapper_model_dropdown',
|
||||||
'expression_restorer_model_dropdown',
|
'expression_restorer_model_dropdown',
|
||||||
'processors_checkbox_group',
|
'processors_checkbox_group',
|
||||||
'face_editor_model_dropdown',
|
'face_editor_model_dropdown',
|
||||||
@@ -158,7 +162,9 @@ def listen() -> None:
|
|||||||
'face_detector_model_dropdown',
|
'face_detector_model_dropdown',
|
||||||
'face_detector_size_dropdown',
|
'face_detector_size_dropdown',
|
||||||
'face_detector_angles_checkbox_group',
|
'face_detector_angles_checkbox_group',
|
||||||
'face_landmarker_model_dropdown'
|
'face_landmarker_model_dropdown',
|
||||||
|
'face_occluder_model_dropdown',
|
||||||
|
'face_parser_model_dropdown'
|
||||||
]):
|
]):
|
||||||
ui_component.change(clear_and_update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE)
|
ui_component.change(clear_and_update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE)
|
||||||
|
|
||||||
@@ -178,8 +184,8 @@ def clear_and_update_preview_image(frame_number : int = 0) -> gradio.Image:
|
|||||||
|
|
||||||
def slide_preview_image(frame_number : int = 0) -> gradio.Image:
|
def slide_preview_image(frame_number : int = 0) -> gradio.Image:
|
||||||
if is_video(state_manager.get_item('target_path')):
|
if is_video(state_manager.get_item('target_path')):
|
||||||
preview_vision_frame = normalize_frame_color(get_video_frame(state_manager.get_item('target_path'), frame_number))
|
preview_vision_frame = normalize_frame_color(read_video_frame(state_manager.get_item('target_path'), frame_number))
|
||||||
preview_vision_frame = resize_frame_resolution(preview_vision_frame, (1024, 1024))
|
preview_vision_frame = restrict_frame(preview_vision_frame, (1024, 1024))
|
||||||
return gradio.Image(value = preview_vision_frame)
|
return gradio.Image(value = preview_vision_frame)
|
||||||
return gradio.Image(value = None)
|
return gradio.Image(value = None)
|
||||||
|
|
||||||
@@ -190,7 +196,13 @@ def update_preview_image(frame_number : int = 0) -> gradio.Image:
|
|||||||
conditional_append_reference_faces()
|
conditional_append_reference_faces()
|
||||||
reference_faces = get_reference_faces() if 'reference' in state_manager.get_item('face_selector_mode') else None
|
reference_faces = get_reference_faces() if 'reference' in state_manager.get_item('face_selector_mode') else None
|
||||||
source_frames = read_static_images(state_manager.get_item('source_paths'))
|
source_frames = read_static_images(state_manager.get_item('source_paths'))
|
||||||
source_faces = get_many_faces(source_frames)
|
source_faces = []
|
||||||
|
|
||||||
|
for source_frame in source_frames:
|
||||||
|
temp_faces = get_many_faces([ source_frame ])
|
||||||
|
temp_faces = sort_faces_by_order(temp_faces, 'large-small')
|
||||||
|
if temp_faces:
|
||||||
|
source_faces.append(get_first(temp_faces))
|
||||||
source_face = get_average_face(source_faces)
|
source_face = get_average_face(source_faces)
|
||||||
source_audio_path = get_first(filter_audio_paths(state_manager.get_item('source_paths')))
|
source_audio_path = get_first(filter_audio_paths(state_manager.get_item('source_paths')))
|
||||||
source_audio_frame = create_empty_audio_frame()
|
source_audio_frame = create_empty_audio_frame()
|
||||||
@@ -210,7 +222,7 @@ def update_preview_image(frame_number : int = 0) -> gradio.Image:
|
|||||||
return gradio.Image(value = preview_vision_frame, elem_classes = [ 'image-preview', 'is-' + detect_frame_orientation(preview_vision_frame) ])
|
return gradio.Image(value = preview_vision_frame, elem_classes = [ 'image-preview', 'is-' + detect_frame_orientation(preview_vision_frame) ])
|
||||||
|
|
||||||
if is_video(state_manager.get_item('target_path')):
|
if is_video(state_manager.get_item('target_path')):
|
||||||
temp_vision_frame = get_video_frame(state_manager.get_item('target_path'), frame_number)
|
temp_vision_frame = read_video_frame(state_manager.get_item('target_path'), frame_number)
|
||||||
preview_vision_frame = process_preview_frame(reference_faces, source_face, source_audio_frame, temp_vision_frame)
|
preview_vision_frame = process_preview_frame(reference_faces, source_face, source_audio_frame, temp_vision_frame)
|
||||||
preview_vision_frame = normalize_frame_color(preview_vision_frame)
|
preview_vision_frame = normalize_frame_color(preview_vision_frame)
|
||||||
return gradio.Image(value = preview_vision_frame, elem_classes = [ 'image-preview', 'is-' + detect_frame_orientation(preview_vision_frame) ])
|
return gradio.Image(value = preview_vision_frame, elem_classes = [ 'image-preview', 'is-' + detect_frame_orientation(preview_vision_frame) ])
|
||||||
@@ -225,7 +237,7 @@ def update_preview_frame_slider() -> gradio.Slider:
|
|||||||
|
|
||||||
|
|
||||||
def process_preview_frame(reference_faces : FaceSet, source_face : Face, source_audio_frame : AudioFrame, target_vision_frame : VisionFrame) -> VisionFrame:
|
def process_preview_frame(reference_faces : FaceSet, source_face : Face, source_audio_frame : AudioFrame, target_vision_frame : VisionFrame) -> VisionFrame:
|
||||||
target_vision_frame = resize_frame_resolution(target_vision_frame, (1024, 1024))
|
target_vision_frame = restrict_frame(target_vision_frame, (1024, 1024))
|
||||||
source_vision_frame = target_vision_frame.copy()
|
source_vision_frame = target_vision_frame.copy()
|
||||||
if analyse_frame(target_vision_frame):
|
if analyse_frame(target_vision_frame):
|
||||||
return cv2.GaussianBlur(target_vision_frame, (99, 99), 0)
|
return cv2.GaussianBlur(target_vision_frame, (99, 99), 0)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ from typing import List, Optional
|
|||||||
import gradio
|
import gradio
|
||||||
|
|
||||||
from facefusion import state_manager, wording
|
from facefusion import state_manager, wording
|
||||||
from facefusion.filesystem import list_directory
|
from facefusion.filesystem import get_file_name, resolve_file_paths
|
||||||
from facefusion.processors.core import clear_processors_modules, get_processors_modules
|
from facefusion.processors.core import get_processors_modules
|
||||||
from facefusion.uis.core import register_ui_component
|
from facefusion.uis.core import register_ui_component
|
||||||
|
|
||||||
PROCESSORS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
PROCESSORS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = None
|
||||||
@@ -26,15 +26,18 @@ def listen() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def update_processors(processors : List[str]) -> gradio.CheckboxGroup:
|
def update_processors(processors : List[str]) -> gradio.CheckboxGroup:
|
||||||
clear_processors_modules(state_manager.get_item('processors'))
|
|
||||||
state_manager.set_item('processors', processors)
|
|
||||||
|
|
||||||
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
||||||
|
if hasattr(processor_module, 'clear_inference_pool'):
|
||||||
|
processor_module.clear_inference_pool()
|
||||||
|
|
||||||
|
for processor_module in get_processors_modules(processors):
|
||||||
if not processor_module.pre_check():
|
if not processor_module.pre_check():
|
||||||
return gradio.CheckboxGroup()
|
return gradio.CheckboxGroup()
|
||||||
|
|
||||||
|
state_manager.set_item('processors', processors)
|
||||||
return gradio.CheckboxGroup(value = state_manager.get_item('processors'), choices = sort_processors(state_manager.get_item('processors')))
|
return gradio.CheckboxGroup(value = state_manager.get_item('processors'), choices = sort_processors(state_manager.get_item('processors')))
|
||||||
|
|
||||||
|
|
||||||
def sort_processors(processors : List[str]) -> List[str]:
|
def sort_processors(processors : List[str]) -> List[str]:
|
||||||
available_processors = list_directory('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))
|
return sorted(available_processors, key = lambda processor : processors.index(processor) if processor in processors else len(processors))
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from facefusion import state_manager, wording
|
|||||||
from facefusion.common_helper import get_first
|
from facefusion.common_helper import get_first
|
||||||
from facefusion.filesystem import filter_audio_paths, filter_image_paths, has_audio, has_image
|
from facefusion.filesystem import filter_audio_paths, filter_image_paths, has_audio, has_image
|
||||||
from facefusion.uis.core import register_ui_component
|
from facefusion.uis.core import register_ui_component
|
||||||
from facefusion.uis.typing import File
|
from facefusion.uis.types import File
|
||||||
|
|
||||||
SOURCE_FILE : Optional[gradio.File] = None
|
SOURCE_FILE : Optional[gradio.File] = None
|
||||||
SOURCE_AUDIO : Optional[gradio.Audio] = None
|
SOURCE_AUDIO : Optional[gradio.Audio] = None
|
||||||
@@ -23,11 +23,6 @@ def render() -> None:
|
|||||||
SOURCE_FILE = gradio.File(
|
SOURCE_FILE = gradio.File(
|
||||||
label = wording.get('uis.source_file'),
|
label = wording.get('uis.source_file'),
|
||||||
file_count = 'multiple',
|
file_count = 'multiple',
|
||||||
file_types =
|
|
||||||
[
|
|
||||||
'audio',
|
|
||||||
'image'
|
|
||||||
],
|
|
||||||
value = state_manager.get_item('source_paths') if has_source_audio or has_source_image else None
|
value = state_manager.get_item('source_paths') if has_source_audio or has_source_image else None
|
||||||
)
|
)
|
||||||
source_file_names = [ source_file_value.get('path') for source_file_value in SOURCE_FILE.value ] if SOURCE_FILE.value else None
|
source_file_names = [ source_file_value.get('path') for source_file_value in SOURCE_FILE.value ] if SOURCE_FILE.value else None
|
||||||
@@ -55,10 +50,12 @@ def update(files : List[File]) -> Tuple[gradio.Audio, gradio.Image]:
|
|||||||
file_names = [ file.name for file in files ] if files else None
|
file_names = [ file.name for file in files ] if files else None
|
||||||
has_source_audio = has_audio(file_names)
|
has_source_audio = has_audio(file_names)
|
||||||
has_source_image = has_image(file_names)
|
has_source_image = has_image(file_names)
|
||||||
|
|
||||||
if has_source_audio or has_source_image:
|
if has_source_audio or has_source_image:
|
||||||
source_audio_path = get_first(filter_audio_paths(file_names))
|
source_audio_path = get_first(filter_audio_paths(file_names))
|
||||||
source_image_path = get_first(filter_image_paths(file_names))
|
source_image_path = get_first(filter_image_paths(file_names))
|
||||||
state_manager.set_item('source_paths', file_names)
|
state_manager.set_item('source_paths', file_names)
|
||||||
return gradio.Audio(value = source_audio_path, visible = has_source_audio), gradio.Image(value = source_image_path, visible = has_source_image)
|
return gradio.Audio(value = source_audio_path, visible = has_source_audio), gradio.Image(value = source_image_path, visible = has_source_image)
|
||||||
|
|
||||||
state_manager.clear_item('source_paths')
|
state_manager.clear_item('source_paths')
|
||||||
return gradio.Audio(value = None, visible = False), gradio.Image(value = None, visible = False)
|
return gradio.Audio(value = None, visible = False), gradio.Image(value = None, visible = False)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user