mirror of
https://github.com/s0md3v/roop.git
synced 2025-12-06 18:08:29 +00:00
Flip the hooks and update CLI usage
This commit is contained in:
parent
c70631f9fd
commit
fa93a0b1e5
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -26,6 +26,6 @@ jobs:
|
||||
with:
|
||||
python-version: 3.9
|
||||
- run: pip install -r requirements.txt gdown
|
||||
- run: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4
|
||||
- run: python run.py -s=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4
|
||||
- run: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex psnr -f null -
|
||||
|
||||
|
||||
23
README.md
23
README.md
@ -34,29 +34,28 @@ Additional command line arguments are given below:
|
||||
```
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-f SOURCE_PATH, --face SOURCE_PATH
|
||||
use a face image
|
||||
-s SOURCE_PATH, --source SOURCE_PATH
|
||||
select an source image
|
||||
-t TARGET_PATH, --target TARGET_PATH
|
||||
replace image or video with face
|
||||
select an target image or video
|
||||
-o OUTPUT_PATH, --output OUTPUT_PATH
|
||||
save output to this file
|
||||
select output file or directory
|
||||
--frame-processor {face_swapper,face_enhancer} [{face_swapper,face_enhancer} ...]
|
||||
list of frame processors to run
|
||||
--keep-fps maintain original fps
|
||||
--keep-audio maintain original audio
|
||||
--keep-frames keep frames directory
|
||||
--many-faces swap every face in the frame
|
||||
pipeline of frame processors
|
||||
--keep-fps keep original fps
|
||||
--keep-audio keep original audio
|
||||
--keep-frames keep temporary frames
|
||||
--many-faces process every face
|
||||
--video-encoder {libx264,libx265,libvpx-vp9}
|
||||
adjust output video encoder
|
||||
--video-quality VIDEO_QUALITY
|
||||
adjust output video quality
|
||||
--max-memory MAX_MEMORY
|
||||
maximum amount of RAM in GB to be used
|
||||
maximum amount of RAM in GB
|
||||
--execution-provider {cpu,...} [{cpu,...} ...]
|
||||
execution provider
|
||||
--execution-threads EXECUTION_THREADS
|
||||
number of threads to be use for the GPU
|
||||
|
||||
number of execution threads
|
||||
```
|
||||
|
||||
Looking for a CLI mode? Using the -f/--face argument will make the program in cli mode.
|
||||
|
||||
@ -35,7 +35,7 @@ def parse_args() -> None:
|
||||
parser.add_argument('-s', '--source', help='select an source image', dest='source_path')
|
||||
parser.add_argument('-t', '--target', help='select an target image or video', dest='target_path')
|
||||
parser.add_argument('-o', '--output', help='select output file or directory', dest='output_path')
|
||||
parser.add_argument('--frame-processor', help='list of frame processors to run', dest='frame_processor', default=['face_swapper'], choices=['face_swapper', 'face_enhancer'], nargs='+')
|
||||
parser.add_argument('--frame-processor', help='pipeline of frame processors', dest='frame_processor', default=['face_swapper'], choices=['face_swapper', 'face_enhancer'], nargs='+')
|
||||
parser.add_argument('--keep-fps', help='keep original fps', dest='keep_fps', action='store_true', default=False)
|
||||
parser.add_argument('--keep-audio', help='keep original audio', dest='keep_audio', action='store_true', default=True)
|
||||
parser.add_argument('--keep-frames', help='keep temporary frames', dest='keep_frames', action='store_true', default=False)
|
||||
@ -100,6 +100,7 @@ def limit_resources() -> None:
|
||||
gpus = tensorflow.config.experimental.list_physical_devices('GPU')
|
||||
for gpu in gpus:
|
||||
tensorflow.config.experimental.set_memory_growth(gpu, True)
|
||||
# limit memory usage
|
||||
if roop.globals.max_memory:
|
||||
memory = roop.globals.max_memory * 1024 ** 3
|
||||
if platform.system().lower() == 'darwin':
|
||||
@ -143,7 +144,7 @@ def start() -> None:
|
||||
destroy()
|
||||
# todo: this needs a temp path for images to work with multiple frame processors
|
||||
for frame_processor in get_frame_processors_modules(roop.globals.frame_processors):
|
||||
update_status(f'{frame_processor.NAME} in progress...')
|
||||
update_status(f'{frame_processor.NAME} is progressing...')
|
||||
frame_processor.process_image(roop.globals.source_path, roop.globals.target_path, roop.globals.output_path)
|
||||
release_resources()
|
||||
if is_image(roop.globals.target_path):
|
||||
@ -161,7 +162,7 @@ def start() -> None:
|
||||
extract_frames(roop.globals.target_path)
|
||||
temp_frame_paths = get_temp_frame_paths(roop.globals.target_path)
|
||||
for frame_processor in get_frame_processors_modules(roop.globals.frame_processors):
|
||||
update_status(f'{frame_processor.NAME} in progress...')
|
||||
update_status(f'{frame_processor.NAME} is progressing...')
|
||||
frame_processor.process_video(roop.globals.source_path, temp_frame_paths)
|
||||
release_resources()
|
||||
# handles fps
|
||||
|
||||
@ -9,6 +9,7 @@ from codeformer.basicsr.utils import img2tensor, tensor2img
|
||||
|
||||
import roop.globals
|
||||
import roop.processors.frame.core
|
||||
from roop.core import update_status
|
||||
from roop.utilities import conditional_download, resolve_relative_path, is_image, is_video
|
||||
|
||||
if 'ROCMExecutionProvider' in roop.globals.execution_providers:
|
||||
@ -20,13 +21,13 @@ NAME = 'Face Enhancer'
|
||||
|
||||
|
||||
def pre_check() -> None:
|
||||
if not is_image(roop.globals.target_path) and not is_video(roop.globals.target_path):
|
||||
quit('Select an image or video for target path.')
|
||||
download_directory_path = resolve_relative_path('../models')
|
||||
conditional_download(download_directory_path, ['https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth'])
|
||||
|
||||
|
||||
def pre_start() -> None:
|
||||
download_directory_path = resolve_relative_path('../models')
|
||||
conditional_download(download_directory_path, ['https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth'])
|
||||
if not is_image(roop.globals.target_path) and not is_video(roop.globals.target_path):
|
||||
return update_status('Select an image or video for target path.')
|
||||
|
||||
|
||||
def get_code_former():
|
||||
|
||||
@ -5,6 +5,7 @@ import threading
|
||||
|
||||
import roop.globals
|
||||
import roop.processors.frame.core
|
||||
from roop.core import update_status
|
||||
from roop.face_analyser import get_one_face, get_many_faces
|
||||
from roop.utilities import conditional_download, resolve_relative_path, is_image, is_video
|
||||
|
||||
@ -14,17 +15,17 @@ NAME = 'Face Swapper'
|
||||
|
||||
|
||||
def pre_check() -> None:
|
||||
if not is_image(roop.globals.source_path):
|
||||
quit('Select an image for source path.')
|
||||
if not get_one_face(cv2.imread(roop.globals.source_path)):
|
||||
quit('No face in source path detected.')
|
||||
if not is_image(roop.globals.target_path) and not is_video(roop.globals.target_path):
|
||||
quit('Select an image or video for target path.')
|
||||
download_directory_path = resolve_relative_path('../models')
|
||||
conditional_download(download_directory_path, ['https://huggingface.co/deepinsight/inswapper/resolve/main/inswapper_128.onnx'])
|
||||
|
||||
|
||||
def pre_start() -> None:
|
||||
download_directory_path = resolve_relative_path('../models')
|
||||
conditional_download(download_directory_path, ['https://huggingface.co/deepinsight/inswapper/resolve/main/inswapper_128.onnx'])
|
||||
if not is_image(roop.globals.source_path):
|
||||
return update_status('Select an image for source path.')
|
||||
elif not get_one_face(cv2.imread(roop.globals.source_path)):
|
||||
return update_status('No face in source path detected.')
|
||||
if not is_image(roop.globals.target_path) and not is_video(roop.globals.target_path):
|
||||
return update_status('Select an image or video for target path.')
|
||||
|
||||
|
||||
def get_face_swapper() -> None:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user