Commit 0b646335 authored by AUTOMATIC1111's avatar AUTOMATIC1111

fix img2img

parent 0c7bdcc1
...@@ -73,3 +73,6 @@ class SD3Inferencer(torch.nn.Module): ...@@ -73,3 +73,6 @@ class SD3Inferencer(torch.nn.Module):
(self, 'cond_stage_model'), (self, 'cond_stage_model'),
(self, 'model'), (self, 'model'),
] ]
def add_noise_to_latent(self, x, noise, amount):
return x * (1 - amount) + noise * amount
...@@ -1737,10 +1737,10 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing): ...@@ -1737,10 +1737,10 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
latmask = latmask[0] latmask = latmask[0]
if self.mask_round: if self.mask_round:
latmask = np.around(latmask) latmask = np.around(latmask)
latmask = np.tile(latmask[None], (4, 1, 1)) latmask = np.tile(latmask[None], (self.init_latent.shape[1], 1, 1))
self.mask = torch.asarray(1.0 - latmask).to(shared.device).type(self.sd_model.dtype) self.mask = torch.asarray(1.0 - latmask).to(shared.device).type(devices.dtype)
self.nmask = torch.asarray(latmask).to(shared.device).type(self.sd_model.dtype) self.nmask = torch.asarray(latmask).to(shared.device).type(devices.dtype)
# this needs to be fixed to be done in sample() using actual seeds for batches # this needs to be fixed to be done in sample() using actual seeds for batches
if self.inpainting_fill == 2: if self.inpainting_fill == 2:
......
...@@ -133,6 +133,9 @@ class KDiffusionSampler(sd_samplers_common.Sampler): ...@@ -133,6 +133,9 @@ class KDiffusionSampler(sd_samplers_common.Sampler):
sigmas = self.get_sigmas(p, steps) sigmas = self.get_sigmas(p, steps)
sigma_sched = sigmas[steps - t_enc - 1:] sigma_sched = sigmas[steps - t_enc - 1:]
if hasattr(shared.sd_model, 'add_noise_to_latent'):
xi = shared.sd_model.add_noise_to_latent(x, noise, sigma_sched[0])
else:
xi = x + noise * sigma_sched[0] xi = x + noise * sigma_sched[0]
if opts.img2img_extra_noise > 0: if opts.img2img_extra_noise > 0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment