setting dimensions

This commit is contained in:
Johannes Stelzer 2023-10-13 10:50:53 +01:00
parent 40ee8700ad
commit 92554c42ab
2 changed files with 19 additions and 48 deletions

View File

@ -43,16 +43,15 @@ class DiffusersHolder():
self.negative_prompt = "" self.negative_prompt = ""
self.guidance_scale = 5.0 self.guidance_scale = 5.0
self.num_inference_steps = 30 self.num_inference_steps = 30
# Check if valid pipe # Check if valid pipe
self.pipe = pipe self.pipe = pipe
self.device = str(pipe._execution_device) self.device = str(pipe._execution_device)
self.init_types() self.init_types()
self.width_latent = self.pipe.unet.config.sample_size self.width_latent = self.pipe.unet.config.sample_size
self.height_latent = self.pipe.unet.config.sample_size self.height_latent = self.pipe.unet.config.sample_size
def init_types(self): def init_types(self):
assert hasattr(self.pipe, "__class__"), "No valid diffusers pipeline found." assert hasattr(self.pipe, "__class__"), "No valid diffusers pipeline found."
assert hasattr(self.pipe.__class__, "__name__"), "No valid diffusers pipeline found." assert hasattr(self.pipe.__class__, "__name__"), "No valid diffusers pipeline found."
@ -65,29 +64,28 @@ class DiffusersHolder():
prompt_embeds = self.pipe._encode_prompt("test", self.device, 1, True) prompt_embeds = self.pipe._encode_prompt("test", self.device, 1, True)
self.dtype = prompt_embeds.dtype self.dtype = prompt_embeds.dtype
def set_num_inference_steps(self, num_inference_steps): def set_num_inference_steps(self, num_inference_steps):
self.num_inference_steps = num_inference_steps self.num_inference_steps = num_inference_steps
if self.use_sd_xl: if self.use_sd_xl:
self.pipe.scheduler.set_timesteps(self.num_inference_steps, device=self.device) self.pipe.scheduler.set_timesteps(self.num_inference_steps, device=self.device)
def set_dimensions(self, size_output):
def set_dimensions(self, width, height): width, height = size_output
s = self.pipe.vae_scale_factor s = self.pipe.vae_scale_factor
if width is None: if width is None:
self.width_latent = self.pipe.unet.config.sample_size self.width_latent = self.pipe.unet.config.sample_size
self.width_img = self.width_latent * self.pipe.vae_scale_factor self.width_img = self.width_latent * self.pipe.vae_scale_factor
else: else:
self.width_img = int(round(width / s) * s) self.width_img = int(round(width / s) * s)
self.width_latent = int(self.width_img / s) self.width_latent = int(self.width_img / s)
if height is None: if height is None:
self.height_latent = self.pipe.unet.config.sample_size self.height_latent = self.pipe.unet.config.sample_size
self.height_img = self.width_latent * self.pipe.vae_scale_factor self.height_img = self.width_latent * self.pipe.vae_scale_factor
else: else:
self.height_img = int(round(height / s) * s) self.height_img = int(round(height / s) * s)
self.height_latent = int(self.height_img / s) self.height_latent = int(self.height_img / s)
print(f"set_dimensions to width={width} and height={height}")
def set_negative_prompt(self, negative_prompt): def set_negative_prompt(self, negative_prompt):
r"""Set the negative prompt. Currenty only one negative prompt is supported r"""Set the negative prompt. Currenty only one negative prompt is supported
@ -503,19 +501,6 @@ class DiffusersHolder():
else: else:
return list_latents_out return list_latents_out
#%%
"""
steps:
x get controlnet vanilla running.
- externalize conditions
- have conditions as input (use one list)
- include latent blending
- test latent blending
- have lora and latent blending
"""
#%% #%%
@ -543,22 +528,4 @@ if __name__ == "__main__":
# %%
"""
OPEN
- rename text encodings to conditionings
- other examples
- kill upscaling? or keep?
- cleanup
- ldh
- sdh class
- diffusion holder
- check linting
- check docstrings
- fix readme
"""

View File

@ -107,15 +107,19 @@ class LatentBlending():
self.dt_per_diff = 0 self.dt_per_diff = 0
self.spatial_mask = None self.spatial_mask = None
self.lpips = lpips.LPIPS(net='alex').cuda(self.device) self.lpips = lpips.LPIPS(net='alex').cuda(self.device)
self.set_prompt1("") self.set_prompt1("")
self.set_prompt2("") self.set_prompt2("")
def set_dimensions(self, size_output=None):
def set_dimensions(self, width=None, height=None): r"""
self.dh.set_dimensions(width, height) sets the size of the output video.
Args:
size_output: tuple
width x height
Note: the size will get automatically adjusted to be divisable by 32.
"""
self.dh.set_dimensions(size_output)
def set_guidance_scale(self, guidance_scale): def set_guidance_scale(self, guidance_scale):
r""" r"""