From f63350cd87e8d5f3264d945f9de033a0e2ee46de Mon Sep 17 00:00:00 2001 From: dailingx <468551414@qq.com> Date: Sat, 15 Jun 2024 01:48:17 +0800 Subject: [PATCH] support random seed --- gradio_app.py | 33 ++++++++++++++++++++++++++++++--- scripts/evaluation/inference.py | 8 ++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/gradio_app.py b/gradio_app.py index 6d1c0e9..abaf4fa 100644 --- a/gradio_app.py +++ b/gradio_app.py @@ -1,6 +1,7 @@ import os, argparse import sys import gradio as gr +import random from scripts.gradio.i2v_test import Image2Video sys.path.insert(1, os.path.join(sys.path[0], 'lvdm')) @@ -31,17 +32,19 @@ i2v_examples_256 = [ ['prompts/256/guitar0.jpeg', 'bear playing guitar happily, snowing', 50, 7.5, 1.0, 3, 122] ] +max_seed = 2 ** 31 + def dynamicrafter_demo(result_dir='./tmp/', res=1024): if res == 1024: resolution = '576_1024' - css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px}""" + css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px} #random_button {max-width: 100px !important}""" elif res == 512: resolution = '320_512' - css = """#input_img {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px}""" + css = """#input_img {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px} #random_button {max-width: 100px !important}""" elif res == 256: resolution = '256_256' - css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px}""" + css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px} #random_button {max-width: 100px !important}""" else: raise NotImplementedError(f"Unsupported resolution: {res}") image2video = Image2Video(result_dir, resolution=resolution) @@ -76,6 +79,14 @@ def dynamicrafter_demo(result_dir='./tmp/', res=1024): with gr.Row(): i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50) i2v_motion = gr.Slider(minimum=5, maximum=20, step=1, elem_id="i2v_motion", label="FPS", value=10) + with gr.Row(): + i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=max_seed, step=1, value=123) + random_button = gr.Button('\U0001f3b2\ufe0f', elem_id="random_button") + random_button.click( + fn=lambda: random.randint(0, max_seed), + outputs=i2v_seed, + queue=False + ) i2v_end_btn = gr.Button("Generate") # with gr.Tab(label='Result'): with gr.Row(): @@ -107,6 +118,14 @@ def dynamicrafter_demo(result_dir='./tmp/', res=1024): with gr.Row(): i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50) i2v_motion = gr.Slider(minimum=15, maximum=30, step=1, elem_id="i2v_motion", label="FPS", value=24) + with gr.Row(): + i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=max_seed, step=1, value=123) + random_button = gr.Button('\U0001f3b2\ufe0f', elem_id="random_button") + random_button.click( + fn=lambda: random.randint(0, max_seed), + outputs=i2v_seed, + queue=False + ) i2v_end_btn = gr.Button("Generate") # with gr.Tab(label='Result'): with gr.Row(): @@ -138,6 +157,14 @@ def dynamicrafter_demo(result_dir='./tmp/', res=1024): with gr.Row(): i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50) i2v_motion = gr.Slider(minimum=1, maximum=4, step=1, elem_id="i2v_motion", label="Motion magnitude", value=3) + with gr.Row(): + i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=max_seed, step=1, value=123) + random_button = gr.Button('\U0001f3b2\ufe0f', elem_id="random_button") + random_button.click( + fn=lambda: random.randint(0, max_seed), + outputs=i2v_seed, + queue=False + ) i2v_end_btn = gr.Button("Generate") # with gr.Tab(label='Result'): with gr.Row(): diff --git a/scripts/evaluation/inference.py b/scripts/evaluation/inference.py index ae0368b..e0a7d31 100644 --- a/scripts/evaluation/inference.py +++ b/scripts/evaluation/inference.py @@ -14,6 +14,7 @@ sys.path.insert(1, os.path.join(sys.path[0], '..', '..')) from lvdm.models.samplers.ddim import DDIMSampler from lvdm.models.samplers.ddim_multiplecond import DDIMSampler as DDIMSampler_multicond from utils.utils import instantiate_from_config +import random def get_filelist(data_dir, postfixes): @@ -351,7 +352,10 @@ if __name__ == '__main__': print("@DynamiCrafter cond-Inference: %s"%now) parser = get_parser() args = parser.parse_args() - - seed_everything(args.seed) + + seed = args.seed + if seed < 0: + seed = random.randint(0, 2 ** 31) + seed_everything(seed) rank, gpu_num = 0, 1 run_inference(args, gpu_num, rank) \ No newline at end of file