From f9563afd7b4084e0a4d203c14861b81b1512653a Mon Sep 17 00:00:00 2001 From: kijai <40791699+kijai@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:38:01 +0200 Subject: [PATCH] Add random noise option to InjectNoiseToLatent -node --- nodes.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nodes.py b/nodes.py index 63214e4..eff1326 100644 --- a/nodes.py +++ b/nodes.py @@ -2825,6 +2825,7 @@ class InjectNoiseToLatent: }, "optional":{ "mask": ("MASK", ), + "mix_randn_amount": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1000.0, "step": 0.001}), } } @@ -2833,7 +2834,7 @@ class InjectNoiseToLatent: CATEGORY = "KJNodes/noise" - def injectnoise(self, latents, strength, noise, normalize, average, mask=None): + def injectnoise(self, latents, strength, noise, normalize, average, mix_randn_amount=0, mask=None): samples = latents.copy() if latents["samples"].shape != noise["samples"].shape: raise ValueError("InjectNoiseToLatent: Latent and noise must have the same shape") @@ -2849,6 +2850,10 @@ class InjectNoiseToLatent: if mask.shape[0] < noised.shape[0]: mask = mask.repeat((noised.shape[0] -1) // mask.shape[0] + 1, 1, 1, 1)[:noised.shape[0]] noised = mask * noised + (1-mask) * latents["samples"] + if mix_randn_amount > 0: + rand_noise = torch.randn_like(noised) + noised = ((1 - mix_randn_amount) * noised + mix_randn_amount * + rand_noise) / ((mix_randn_amount**2 + (1-mix_randn_amount)**2) ** 0.5) samples["samples"] = noised return (samples,)