Compare commits

...

10 Commits

Author SHA1 Message Date
Mr.Tom fb5c15ff43
Merge 6d6d2fc748 into 3da987340b 2024-10-19 05:39:57 +07:00
KRSHH 3da987340b
Fix Enhancer for Map Faces 2024-10-15 13:08:03 +05:30
Kenneth Estanislao a4216bf9ec
Update README.md
added tips and links
2024-10-14 19:54:21 +08:00
KRSHH ab26413ce8 on/off enhancer during inference and improve FPS counter 2024-10-13 13:16:21 +05:30
hoangngoc5275 6d6d2fc748
Update python-package.yml
Signed-off-by: hoangngoc5275 <hoangngocngoc50@gmail.com>
2024-09-29 04:33:28 +07:00
hoangngoc5275 cb9d04933b
Merge branch 'hacksider:main' into main 2024-09-29 04:10:38 +07:00
looman loras 2edde04570 Merge branch 'main' of https://github.com/hoangngoc5275/Deepface
* 'main' of https://github.com/hoangngoc5275/Deepface:
  Create python-package.yml
2024-09-18 17:18:02 +07:00
hoangngoc5275 5da4632c15
Merge branch 'hacksider:main' into main 2024-09-17 11:16:08 +07:00
hoangngoc5275 0f65be8bb3
Merge branch 'hacksider:main' into main 2024-09-16 20:53:42 +07:00
hoangngoc5275 d0faf924d1
Create python-package.yml
Signed-off-by: hoangngoc5275 <hoangngocngoc50@gmail.com>
2024-09-14 15:03:47 +07:00
4 changed files with 102 additions and 21 deletions

View File

@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python package
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: falses
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest

View File

@ -379,6 +379,10 @@ For the latest experimental builds and features, see the [experimental branch](h
This is an open-source project developed in our free time. Updates may be delayed.
**Tips and Links:**
- [How to make the most of Deep-Live-Cam](https://hacksider.gumroad.com/p/how-to-make-the-most-on-deep-live-cam)
- Face enhancer is good, but still very slow for any live streaming purpose.
## Credits

View File

@ -9,23 +9,35 @@ import modules.processors.frame.core
from modules.core import update_status
from modules.face_analyser import get_one_face
from modules.typing import Frame, Face
from modules.utilities import conditional_download, resolve_relative_path, is_image, is_video
from modules.utilities import (
conditional_download,
resolve_relative_path,
is_image,
is_video,
)
FACE_ENHANCER = None
THREAD_SEMAPHORE = threading.Semaphore()
THREAD_LOCK = threading.Lock()
NAME = 'DLC.FACE-ENHANCER'
NAME = "DLC.FACE-ENHANCER"
def pre_check() -> bool:
download_directory_path = resolve_relative_path('..\models')
conditional_download(download_directory_path, ['https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth'])
download_directory_path = resolve_relative_path("..\models")
conditional_download(
download_directory_path,
[
"https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth"
],
)
return True
def pre_start() -> bool:
if not is_image(modules.globals.target_path) and not is_video(modules.globals.target_path):
update_status('Select an image or video for target path.', NAME)
if not is_image(modules.globals.target_path) and not is_video(
modules.globals.target_path
):
update_status("Select an image or video for target path.", NAME)
return False
return True
@ -35,21 +47,18 @@ def get_face_enhancer() -> Any:
with THREAD_LOCK:
if FACE_ENHANCER is None:
if os.name == 'nt':
model_path = resolve_relative_path('..\models\GFPGANv1.4.pth')
if os.name == "nt":
model_path = resolve_relative_path("..\models\GFPGANv1.4.pth")
# todo: set models path https://github.com/TencentARC/GFPGAN/issues/399
else:
model_path = resolve_relative_path('../models/GFPGANv1.4.pth')
model_path = resolve_relative_path("../models/GFPGANv1.4.pth")
FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1) # type: ignore[attr-defined]
return FACE_ENHANCER
def enhance_face(temp_frame: Frame) -> Frame:
with THREAD_SEMAPHORE:
_, _, temp_frame = get_face_enhancer().enhance(
temp_frame,
paste_back=True
)
_, _, temp_frame = get_face_enhancer().enhance(temp_frame, paste_back=True)
return temp_frame
@ -60,7 +69,9 @@ def process_frame(source_face: Face, temp_frame: Frame) -> Frame:
return temp_frame
def process_frames(source_path: str, temp_frame_paths: List[str], progress: Any = None) -> None:
def process_frames(
source_path: str, temp_frame_paths: List[str], progress: Any = None
) -> None:
for temp_frame_path in temp_frame_paths:
temp_frame = cv2.imread(temp_frame_path)
result = process_frame(None, temp_frame)
@ -77,3 +88,10 @@ def process_image(source_path: str, target_path: str, output_path: str) -> None:
def process_video(source_path: str, temp_frame_paths: List[str]) -> None:
modules.processors.frame.core.process_video(None, temp_frame_paths, process_frames)
def process_frame_v2(temp_frame: Frame) -> Frame:
target_face = get_one_face(temp_frame)
if target_face:
temp_frame = enhance_face(temp_frame)
return temp_frame

View File

@ -229,7 +229,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
color_correction_value = ctk.BooleanVar(value=modules.globals.color_correction)
color_correction_switch = ctk.CTkSwitch(
root,
text="Fix Blueish Cam\n(force cv2 to use RGB instead of BGR)",
text="Fix Blueish Cam",
variable=color_correction_value,
cursor="hand2",
command=lambda: (
@ -514,6 +514,12 @@ def update_pop_live_status(text: str) -> None:
def update_tumbler(var: str, value: bool) -> None:
modules.globals.fp_ui[var] = value
save_switch_states()
# If we're currently in a live preview, update the frame processors
if PREVIEW.state() == "normal":
global frame_processors
frame_processors = get_frame_processors_modules(
modules.globals.frame_processors
)
def select_source_path() -> None:
@ -753,6 +759,8 @@ def create_webcam_preview(camera_index: int):
source_image = None
prev_time = time.time()
fps_update_interval = 0.5 # Update FPS every 0.5 seconds
frame_count = 0
fps = 0
while camera:
@ -775,22 +783,33 @@ def create_webcam_preview(camera_index: int):
source_image = get_one_face(cv2.imread(modules.globals.source_path))
for frame_processor in frame_processors:
if frame_processor.NAME == "DLC.FACE-ENHANCER":
if modules.globals.fp_ui["face_enhancer"]:
temp_frame = frame_processor.process_frame(None, temp_frame)
else:
temp_frame = frame_processor.process_frame(source_image, temp_frame)
else:
modules.globals.target_path = None
for frame_processor in frame_processors:
if frame_processor.NAME == "DLC.FACE-ENHANCER":
if modules.globals.fp_ui["face_enhancer"]:
temp_frame = frame_processor.process_frame_v2(temp_frame)
else:
temp_frame = frame_processor.process_frame_v2(temp_frame)
# Calculate and display FPS
current_time = time.time()
fps = 1 / (current_time - prev_time)
frame_count += 1
if current_time - prev_time >= fps_update_interval:
fps = frame_count / (current_time - prev_time)
frame_count = 0
prev_time = current_time
if modules.globals.show_fps:
cv2.putText(
temp_frame,
f"FPS: {fps:.2f}",
f"FPS: {fps:.1f}",
(10, 30),
cv2.FONT_HERSHEY_SIMPLEX,
1,