From 2a2f38a016f383e8be94b0ba2d35e8ad33300d00 Mon Sep 17 00:00:00 2001 From: wfng92 <43742196+wfng92@users.noreply.github.com> Date: Fri, 16 Dec 2022 04:59:19 +0800 Subject: [PATCH] Correct timestep for img2img initial noise addition (#1946) * Correct timestep for img2img initial noise addition * apply fix to inpaint and txt2img2img as well Co-authored-by: Lincoln Stein --- ldm/invoke/generator/img2img.py | 2 +- ldm/invoke/generator/inpaint.py | 2 +- ldm/invoke/generator/txt2img2img.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ldm/invoke/generator/img2img.py b/ldm/invoke/generator/img2img.py index f188d9b23d..1881d847d8 100644 --- a/ldm/invoke/generator/img2img.py +++ b/ldm/invoke/generator/img2img.py @@ -45,7 +45,7 @@ class Img2Img(Generator): # encode (scaled latent) z_enc = sampler.stochastic_encode( self.init_latent, - torch.tensor([t_enc]).to(self.model.device), + torch.tensor([t_enc - 1]).to(self.model.device), noise=x_T ) diff --git a/ldm/invoke/generator/inpaint.py b/ldm/invoke/generator/inpaint.py index b86e21efe6..a2613f48ea 100644 --- a/ldm/invoke/generator/inpaint.py +++ b/ldm/invoke/generator/inpaint.py @@ -279,7 +279,7 @@ class Inpaint(Img2Img): # encode (scaled latent) z_enc = sampler.stochastic_encode( self.init_latent, - torch.tensor([t_enc]).to(self.model.device), + torch.tensor([t_enc - 1]).to(self.model.device), noise=x_T ) diff --git a/ldm/invoke/generator/txt2img2img.py b/ldm/invoke/generator/txt2img2img.py index b8d0f81322..a1ebf423b9 100644 --- a/ldm/invoke/generator/txt2img2img.py +++ b/ldm/invoke/generator/txt2img2img.py @@ -84,7 +84,7 @@ class Txt2Img2Img(Generator): z_enc = ddim_sampler.stochastic_encode( samples, - torch.tensor([t_enc]).to(self.model.device), + torch.tensor([t_enc-1]).to(self.model.device), noise=self.get_noise(width,height,False) )