From 58cadd23d5cdfdd48ae81cfdf3f83f0042c3a0e8 Mon Sep 17 00:00:00 2001 From: lugo Date: Mon, 28 Nov 2022 18:14:20 +0100 Subject: [PATCH] cleanup --- cherry_picknick.py | 49 ++++++++++++++++++++++++++++++++++---------- example1_standard.py | 8 +++++--- example2_inpaint.py | 26 ++++++++--------------- 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/cherry_picknick.py b/cherry_picknick.py index 0d6813a..b3b037f 100644 --- a/cherry_picknick.py +++ b/cherry_picknick.py @@ -32,23 +32,24 @@ torch.set_grad_enabled(False) #%% First let us spawn a stable diffusion holder -device = "cuda:0" -num_inference_steps = 20 # Number of diffusion interations -fp_ckpt = "../stable_diffusion_models/ckpt/768-v-ema.ckpt" -fp_config = '../stablediffusion/configs/stable-diffusion/v2-inference-v.yaml' +use_inpaint = True -sdh = StableDiffusionHolder(fp_ckpt, fp_config, device, num_inference_steps=num_inference_steps) +device = "cuda" +fp_ckpt= "../stable_diffusion_models/ckpt/512-inpainting-ema.ckpt" +fp_config = '../stablediffusion/configs//stable-diffusion/v2-inpainting-inference.yaml' + +# fp_ckpt = "../stable_diffusion_models/ckpt/768-v-ema.ckpt" +# fp_config = '../stablediffusion/configs/stable-diffusion/v2-inference-v.yaml' + +sdh = StableDiffusionHolder(fp_ckpt, fp_config, device) + + + #%% Next let's set up all parameters num_inference_steps = 30 # Number of diffusion interations -list_nmb_branches = [2, 3, 10, 24]#, 50] # Branching structure: how many branches -list_injection_strength = [0.0, 0.6, 0.8, 0.9]#, 0.95] # Branching structure: how deep is the blending guidance_scale = 5 -fps = 30 -duration_target = 10 -width = 512 -height = 512 lb = LatentBlending(sdh, num_inference_steps, guidance_scale) @@ -71,6 +72,32 @@ for k, prompt in enumerate(list_prompts): plt.show() print(f"prompt {k} seed {seed} trial {i}") +#%% +#%% Let's make a source image and mask. +k=0 +for i in range(10): + seed = 190791709# np.random.randint(999999999) +# seed0 = 629575320 + + lb = LatentBlending(sdh) + lb.autosetup_branching(quality='medium', deepth_strength=0.65) + + prompt1 = "photo of a futuristic alien temple in a desert, mystic, glowing, organic, intricate, sci-fi movie, mesmerizing, scary" + lb.set_prompt1(prompt1) + lb.init_inpainting(init_empty=True) + lb.set_seed(seed) + plt.imshow(lb.run_diffusion(lb.text_embedding1, return_image=True)) + plt.title(f"prompt1 {k}, seed {i} {seed}") + plt.show() + print(f"prompt1 {k} seed {seed} trial {i}") + + xx + +#%% +mask_image = 255*np.ones([512,512], dtype=np.uint8) +mask_image[340:420, 170:280, ] = 0 +mask_image = Image.fromarray(mask_image) + #%% """ diff --git a/example1_standard.py b/example1_standard.py index 5a6cec1..4af13d4 100644 --- a/example1_standard.py +++ b/example1_standard.py @@ -40,15 +40,17 @@ sdh = StableDiffusionHolder(fp_ckpt, fp_config, device) #%% Next let's set up all parameters quality = 'medium' +deepth_strength = 0.65 fixed_seeds = [69731932, 504430820] -lb = LatentBlending(sdh) prompt1 = "photo of a beautiful forest covered in white flowers, ambient light, very detailed, magic" prompt2 = "photo of an golden statue with a funny hat, surrounded by ferns and vines, grainy analog photograph, mystical ambience, incredible detail" + +lb = LatentBlending(sdh) +lb.autosetup_branching(quality=quality, deepth_strength=deepth_strength) lb.set_prompt1(prompt1) lb.set_prompt2(prompt2) -lb.autosetup_branching(quality=quality) imgs_transition = lb.run_transition(fixed_seeds=fixed_seeds) @@ -58,7 +60,7 @@ fps = 60 imgs_transition_ext = add_frames_linear_interp(imgs_transition, duration_transition, fps) # movie saving -fp_movie = f"movie_example1.mp4" +fp_movie = "movie_example1.mp4" if os.path.isfile(fp_movie): os.remove(fp_movie) ms = MovieSaver(fp_movie, fps=fps, shape_hw=[sdh.height, sdh.width]) diff --git a/example2_inpaint.py b/example2_inpaint.py index 38f0d06..8457bef 100644 --- a/example2_inpaint.py +++ b/example2_inpaint.py @@ -34,40 +34,32 @@ from stable_diffusion_holder import StableDiffusionHolder torch.set_grad_enabled(False) #%% First let us spawn a stable diffusion holder -device = "cuda:0" -num_inference_steps = 20 # Number of diffusion interations +device = "cuda" +quality = 'medium' +deepth_strength = 0.65 fp_ckpt= "../stable_diffusion_models/ckpt/512-inpainting-ema.ckpt" fp_config = '../stablediffusion/configs//stable-diffusion/v2-inpainting-inference.yaml' -sdh = StableDiffusionHolder(fp_ckpt, fp_config, device, num_inference_steps=num_inference_steps) +sdh = StableDiffusionHolder(fp_ckpt, fp_config, device) #%% Let's make a source image and mask. -height = 512 -width = 512 -num_inference_steps = 30 -guidance_scale = 5 -fixed_seeds = [629575320, 670154945] +seed0 = 190791709 lb = LatentBlending(sdh) -lb.autosetup_branching("low") +lb.autosetup_branching(quality=quality, deepth_strength=deepth_strength) prompt1 = "photo of a futuristic alien temple in a desert, mystic, glowing, organic, intricate, sci-fi movie, mesmerizing, scary" lb.set_prompt1(prompt1) lb.init_inpainting(init_empty=True) -lb.set_seed(fixed_seeds[0]) +lb.set_seed(seed0) image_source = lb.run_diffusion(lb.text_embedding1, return_image=True) mask_image = 255*np.ones([512,512], dtype=np.uint8) -mask_image[160:250, 200:320] = 0 +mask_image[340:420, 170:280, ] = 0 mask_image = Image.fromarray(mask_image) #%% Next let's set up all parameters -# FIXME below fix numbers -# We want 20 diffusion steps, begin with 2 branches, have 3 branches at step 12 (=0.6*20) -# 10 branches at step 16 (=0.8*20) and 24 branches at step 18 (=0.9*20) -# Furthermore we want seed 993621550 for keyframeA and seed 54878562 for keyframeB () - -fixed_seeds = [993621550, 280335986] +fixed_seeds = [seed0, 280335986] prompt1 = "photo of a futuristic alien temple in a desert, mystic, glowing, organic, intricate, sci-fi movie, mesmerizing, scary" prompt2 = "aerial photo of a futuristic alien temple in a coastal area, waves clashing"