From d689b06256b4dcadb3d8615123baf5575fb0e47b Mon Sep 17 00:00:00 2001 From: Bryce Date: Tue, 4 Oct 2022 06:12:42 -0700 Subject: [PATCH] fix: ensure init-image-strength 0 is respected addresses https://github.com/brycedrennan/imaginAIry/issues/38 --- imaginairy/api.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/imaginairy/api.py b/imaginairy/api.py index f89ae05..b323f01 100755 --- a/imaginairy/api.py +++ b/imaginairy/api.py @@ -266,18 +266,24 @@ def imagine( # encode (scaled latent) seed_everything(prompt.seed) noise = torch.randn_like(init_latent, device="cpu").to(get_device()) - z_enc = sampler.stochastic_encode( - init_latent, - torch.tensor([t_enc - 1]).to(get_device()), - noise=noise, - ) + if generation_strength >= 1: + # prompt strength gets converted to time encodings, + # which means you can't get to true 0 without this hack + # (or setting steps=1000) + z_enc = noise + else: + z_enc = sampler.stochastic_encode( + init_latent, + torch.tensor([t_enc - 1]).to(get_device()), + noise=noise, + ) log_latent(z_enc, "z_enc") # decode it samples = sampler.decode( - z_enc, - c, - t_enc, + x_latent=z_enc, + cond=c, + t_start=t_enc, unconditional_guidance_scale=prompt.prompt_strength, unconditional_conditioning=uc, img_callback=_img_callback,