From 7f38f8e046b3477f05e55c8d5fbe1a8561b37d6c Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 16 Aug 2023 22:52:35 +0200 Subject: [PATCH] First interation of the benchmark ui --- .gitignore | 1 + roop/uis/components/benchmark.py | 75 ++++++++++++++++++++++++++++++++ roop/uis/layouts/benchmark.py | 20 +++++++++ 3 files changed, 96 insertions(+) create mode 100644 roop/uis/components/benchmark.py create mode 100644 roop/uis/layouts/benchmark.py diff --git a/.gitignore b/.gitignore index e25e7ce3b..d79cc4236 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea +benchmark models temp __pycache__ diff --git a/roop/uis/components/benchmark.py b/roop/uis/components/benchmark.py new file mode 100644 index 000000000..9be66e4ba --- /dev/null +++ b/roop/uis/components/benchmark.py @@ -0,0 +1,75 @@ +from typing import Optional +import time +import gradio + +import roop.globals +from roop.capturer import get_video_frame_total +from roop.core import start +from roop.uis.typing import Update +from roop.utilities import normalize_output_path, conditional_download + +BENCHMARK_DATAFRAME: Optional[gradio.Dataframe] = None +BENCHMARK_BUTTON: Optional[gradio.Button] = None + + +def render() -> None: + global BENCHMARK_DATAFRAME + global BENCHMARK_BUTTON + + conditional_download('benchmark', [ + 'https://huggingface.co/henryruhs/roop-benchmark/resolve/main/source.jpg', + 'https://huggingface.co/henryruhs/roop-benchmark/resolve/main/target-240p.mp4', + 'https://huggingface.co/henryruhs/roop-benchmark/resolve/main/target-360p.mp4', + 'https://huggingface.co/henryruhs/roop-benchmark/resolve/main/target-540p.mp4', + 'https://huggingface.co/henryruhs/roop-benchmark/resolve/main/target-720p.mp4', + 'https://huggingface.co/henryruhs/roop-benchmark/resolve/main/target-1080p.mp4', + 'https://huggingface.co/henryruhs/roop-benchmark/resolve/main/target-1440p.mp4', + 'https://huggingface.co/henryruhs/roop-benchmark/resolve/main/target-2160p.mp4' + ]) + with gradio.Box(): + BENCHMARK_DATAFRAME = gradio.Dataframe( + label='BENCHMARK DATA', + headers=['target path', 'process time', 'relative fps'], + col_count=(3, 'fixed'), + row_count=(6, 'fixed'), + datatype=['str', 'number', 'number'] + ) + BENCHMARK_BUTTON = gradio.Button('Benchmark') + + +def listen() -> None: + BENCHMARK_BUTTON.click(update, outputs=BENCHMARK_DATAFRAME) + + +def update() -> Update: + target_paths = [ + 'benchmark/target-240p.mp4', + 'benchmark/target-360p.mp4', + 'benchmark/target-540p.mp4', + 'benchmark/target-720p.mp4', + 'benchmark/target-1440p.mp4', + 'benchmark/target-2160p.mp4' + ] + value = [] + total_runs = 3 + for target_path in target_paths: + total_process_time = 0.0 + total_fps = 0.0 + for i in range(total_runs + 1): + roop.globals.source_path = 'benchmark/source.jpg' + roop.globals.target_path = target_path + roop.globals.output_path = normalize_output_path(roop.globals.source_path, roop.globals.target_path, 'benchmark') + video_frame_total = get_video_frame_total(roop.globals.target_path) + if roop.globals.output_path: + start_time = time.time() + start() + end_time = time.time() + process_time = end_time - start_time + fps = video_frame_total / process_time + if i > 0: + total_process_time += process_time + total_fps += fps + average_process_time = total_process_time / total_runs + average_fps = total_fps / total_runs + value.append([roop.globals.target_path, average_process_time, average_fps]) + return gradio.update(value=value) diff --git a/roop/uis/layouts/benchmark.py b/roop/uis/layouts/benchmark.py new file mode 100644 index 000000000..804255d2d --- /dev/null +++ b/roop/uis/layouts/benchmark.py @@ -0,0 +1,20 @@ +import gradio + +from roop.uis.components import processor, execution, benchmark + + +def render() -> gradio.Blocks: + with gradio.Blocks() as layout: + with gradio.Row(): + with gradio.Column(scale=2): + processor.render() + execution.render() + with gradio.Column(scale=5): + benchmark.render() + return layout + + +def listen() -> None: + processor.listen() + execution.listen() + benchmark.listen()