process interruption

This commit is contained in:
sachalin
2022-11-23 13:43:33 +01:00
parent 755b98bff7
commit db88ee530a

View File

@@ -32,10 +32,11 @@ from diffusers.schedulers import DDIMScheduler
from PIL import Image from PIL import Image
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import torch import torch
from movie_man import MovieSaver from movie_util import MovieSaver
import datetime import datetime
from typing import Callable, List, Optional, Union from typing import Callable, List, Optional, Union
import inspect import inspect
from threading import Thread
torch.set_grad_enabled(False) torch.set_grad_enabled(False)
#%% #%%
@@ -95,6 +96,7 @@ class LatentBlending():
self.list_injection_idx_prev = [] self.list_injection_idx_prev = []
self.text_embedding1 = None self.text_embedding1 = None
self.text_embedding2 = None self.text_embedding2 = None
self.stop_diffusion = False
def check_asserts(self): def check_asserts(self):
@@ -232,6 +234,9 @@ class LatentBlending():
else: else:
assert len(fixed_seeds)==2, "Supply a list with len = 2" assert len(fixed_seeds)==2, "Supply a list with len = 2"
# Process interruption variable
self.stop_diffusion = False
# Recycling? There are requirements # Recycling? There are requirements
if recycle_img1 or recycle_img2: if recycle_img1 or recycle_img2:
if self.list_nmb_branches_prev == []: if self.list_nmb_branches_prev == []:
@@ -286,9 +291,11 @@ class LatentBlending():
if recycle_img1: if recycle_img1:
self.tree_status[t_block][0] = 'computed' self.tree_status[t_block][0] = 'computed'
self.tree_final_imgs[0] = self.latent2image(self.tree_latents[-1][0][-1]) self.tree_final_imgs[0] = self.latent2image(self.tree_latents[-1][0][-1])
self.tree_final_imgs_timing[0] = 0
if recycle_img2: if recycle_img2:
self.tree_status[t_block][-1] = 'computed' self.tree_status[t_block][-1] = 'computed'
self.tree_final_imgs[-1] = self.latent2image(self.tree_latents[-1][-1][-1]) self.tree_final_imgs[-1] = self.latent2image(self.tree_latents[-1][-1][-1])
self.tree_final_imgs_timing[-1] = 0
# setup compute order: goal: try to get last branch computed asap. # setup compute order: goal: try to get last branch computed asap.
# first compute the right keyframe. needs to be there in any case # first compute the right keyframe. needs to be there in any case
@@ -324,6 +331,10 @@ class LatentBlending():
# Diffusion computations start here # Diffusion computations start here
time_start = time.time() time_start = time.time()
for t_block, idx_branch in tqdm(list_compute, desc="computing transition"): for t_block, idx_branch in tqdm(list_compute, desc="computing transition"):
if self.stop_diffusion:
print("run_transition: process interrupted")
return self.tree_final_imgs
# print(f"computing t_block {t_block} idx_branch {idx_branch}") # print(f"computing t_block {t_block} idx_branch {idx_branch}")
idx_stop = list_injection_idx_ext[t_block+1] idx_stop = list_injection_idx_ext[t_block+1]
fract_mixing = self.tree_fracts[t_block][idx_branch] fract_mixing = self.tree_fracts[t_block][idx_branch]
@@ -934,20 +945,58 @@ def get_time(resolution=None):
#%% le main #%% le main
if __name__ == "__main__": if __name__ == "__main__":
device = "cuda:0"
model_path = "../stable_diffusion_models/stable-diffusion-v1-5"
scheduler = DDIMScheduler(beta_start=0.00085,
beta_end=0.012,
beta_schedule="scaled_linear",
clip_sample=False,
set_alpha_to_one=False)
pipe = StableDiffusionPipeline.from_pretrained(
model_path,
revision="fp16",
torch_dtype=torch.float16,
scheduler=scheduler,
use_auth_token=True
)
pipe = pipe.to(device)
num_inference_steps = 20 # Number of diffusion interations
list_nmb_branches = [2, 3, 10, 24] # Branching structure: how many branches
list_injection_strength = [0.0, 0.6, 0.8, 0.9] # Branching structure: how deep is the blending
width = 512
height = 512
guidance_scale = 5
fixed_seeds = [993621550, 280335986]
lb = LatentBlending(pipe, device, height, width, num_inference_steps, guidance_scale)
prompt1 = "photo of a beautiful forest covered in white flowers, ambient light, very detailed, magic"
prompt2 = "photo of an eerie statue surrounded by ferns and vines, analog photograph kodak portra, mystical ambience, incredible detail"
lb.set_prompt1(prompt1)
lb.set_prompt2(prompt2)
imgs_transition = lb.run_transition(list_nmb_branches, list_injection_strength, fixed_seeds=fixed_seeds)
xxx
#%%
#%%
""" #%%
TODO Coding: """
TODO Coding:
RUNNING WITHOUT PROMPT! RUNNING WITHOUT PROMPT!
auto mode (quality settings) auto mode (quality settings)
save value ranges, can it be trashed? save value ranges, can it be trashed?
set all variables in init! self.img2... set all variables in init! self.img2...
TODO Other: TODO Other:
github github
write text write text
requirements requirements
@@ -955,4 +1004,4 @@ if __name__ == "__main__":
make colab make colab
license license
twitter et al twitter et al
""" """