Skip to content

Commit

Permalink
Next (#778)
Browse files Browse the repository at this point in the history
* [Bugfix] Add back the support for --many-faces (#771)

* Cleanup many-faces vs reference face, Fix float on reference frame, Introduce globals typing

* Fix headless

* Fix attribute typing error

* Bump version

---------

Co-authored-by: Barak Segal <[email protected]>
  • Loading branch information
henryruhs and barak353 authored Jul 27, 2023
1 parent ef41919 commit e064270
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
Binary file modified gui-demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions roop/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def parse_args() -> None:

roop.globals.source_path = args.source_path
roop.globals.target_path = args.target_path
roop.globals.output_path = normalize_output_path(roop.globals.source_path, roop.globals.target_path, args.output_path) # type: ignore
roop.globals.headless = roop.globals.source_path and roop.globals.target_path and roop.globals.output_path
roop.globals.output_path = normalize_output_path(roop.globals.source_path, roop.globals.target_path, args.output_path)
roop.globals.headless = roop.globals.source_path is not None and roop.globals.target_path is not None and roop.globals.output_path is not None
roop.globals.frame_processors = args.frame_processor
roop.globals.keep_fps = args.keep_fps
roop.globals.keep_frames = args.keep_frames
Expand Down Expand Up @@ -109,7 +109,7 @@ def limit_resources() -> None:
memory = roop.globals.max_memory * 1024 ** 6
if platform.system().lower() == 'windows':
import ctypes
kernel32 = ctypes.windll.kernel32
kernel32 = ctypes.windll.kernel32 # type: ignore[attr-defined]
kernel32.SetProcessWorkingSetSize(-1, ctypes.c_size_t(memory), ctypes.c_size_t(memory))
else:
import resource
Expand Down
38 changes: 19 additions & 19 deletions roop/globals.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from typing import List
from typing import List, Optional

source_path = None
target_path = None
output_path = None
headless = None
source_path: Optional[str] = None
target_path: Optional[str] = None
output_path: Optional[str] = None
headless: Optional[bool] = None
frame_processors: List[str] = []
keep_fps = None
keep_frames = None
skip_audio = None
many_faces = None
reference_face_position = None
reference_frame_number = None
similar_face_distance = None
temp_frame_format = None
temp_frame_quality = None
output_video_encoder = None
output_video_quality = None
max_memory = None
keep_fps: Optional[bool] = None
keep_frames: Optional[bool] = None
skip_audio: Optional[bool] = None
many_faces: Optional[bool] = None
reference_face_position: Optional[int] = None
reference_frame_number: Optional[int] = None
similar_face_distance: Optional[float] = None
temp_frame_format: Optional[str] = None
temp_frame_quality: Optional[int] = None
output_video_encoder: Optional[str] = None
output_video_quality: Optional[int] = None
max_memory: Optional[int] = None
execution_providers: List[str] = []
execution_threads = None
log_level = 'error'
execution_threads: Optional[int] = None
log_level: str = 'error'
2 changes: 1 addition & 1 deletion roop/metadata.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = 'roop'
version = '1.3.0'
version = '1.3.1'
6 changes: 3 additions & 3 deletions roop/processors/frame/face_swapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def process_frame(source_face: Face, reference_face: Face, temp_frame: Frame) ->

def process_frames(source_path: str, temp_frame_paths: List[str], update: Callable[[], None]) -> None:
source_face = get_one_face(cv2.imread(source_path))
reference_face = get_face_reference()
reference_face = None if roop.globals.many_faces else get_face_reference()
for temp_frame_path in temp_frame_paths:
temp_frame = cv2.imread(temp_frame_path)
result = process_frame(source_face, reference_face, temp_frame)
Expand All @@ -87,13 +87,13 @@ def process_frames(source_path: str, temp_frame_paths: List[str], update: Callab
def process_image(source_path: str, target_path: str, output_path: str) -> None:
source_face = get_one_face(cv2.imread(source_path))
target_frame = cv2.imread(target_path)
reference_face = get_one_face(target_frame, roop.globals.reference_face_position)
reference_face = None if roop.globals.many_faces else get_one_face(target_frame, roop.globals.reference_face_position)
result = process_frame(source_face, reference_face, target_frame)
cv2.imwrite(output_path, result)


def process_video(source_path: str, temp_frame_paths: List[str]) -> None:
if not get_face_reference():
if not roop.globals.many_faces and not get_face_reference():
reference_frame = cv2.imread(temp_frame_paths[roop.globals.reference_frame_number])
reference_face = get_one_face(reference_frame, roop.globals.reference_face_position)
set_face_reference(reference_face)
Expand Down
10 changes: 5 additions & 5 deletions roop/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def select_source_path(source_path: Optional[str] = None) -> None:
if source_path is None:
source_path = ctk.filedialog.askopenfilename(title='select an source image', initialdir=RECENT_DIRECTORY_SOURCE)
if is_image(source_path):
roop.globals.source_path = source_path # type: ignore
roop.globals.source_path = source_path
RECENT_DIRECTORY_SOURCE = os.path.dirname(roop.globals.source_path)
image = render_image_preview(roop.globals.source_path, (200, 200))
source_label.configure(image=image)
Expand All @@ -170,12 +170,12 @@ def select_target_path(target_path: Optional[str] = None) -> None:
if target_path is None:
target_path = ctk.filedialog.askopenfilename(title='select an target image or video', initialdir=RECENT_DIRECTORY_TARGET)
if is_image(target_path):
roop.globals.target_path = target_path # type: ignore
roop.globals.target_path = target_path
RECENT_DIRECTORY_TARGET = os.path.dirname(roop.globals.target_path)
image = render_image_preview(roop.globals.target_path, (200, 200))
target_label.configure(image=image)
elif is_video(target_path):
roop.globals.target_path = target_path # type: ignore
roop.globals.target_path = target_path
RECENT_DIRECTORY_TARGET = os.path.dirname(roop.globals.target_path)
video_frame = render_video_preview(target_path, (200, 200))
target_label.configure(image=video_frame)
Expand Down Expand Up @@ -273,8 +273,8 @@ def update_preview(frame_number: int = 0) -> None:

def update_face_reference(steps: int) -> None:
clear_face_reference()
reference_frame_number = preview_slider.get()
roop.globals.reference_face_position += steps # type: ignore
reference_frame_number = int(preview_slider.get())
roop.globals.reference_face_position += steps
roop.globals.reference_frame_number = reference_frame_number
update_preview(reference_frame_number)

Expand Down

0 comments on commit e064270

Please sign in to comment.