Skip to content

Commit

Permalink
fix: invalid variation noise logic
Browse files Browse the repository at this point in the history
- To compensate for the loss of Gaussian noise characteristics due to interpolation between two noises, scale.
  • Loading branch information
ltdrdata committed May 1, 2024
1 parent 23d8b83 commit 80e5958
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion modules/impact/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os


version_code = [5, 2]
version_code = [5, 2, 1]
version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')

dependency_version = 20
Expand Down
12 changes: 7 additions & 5 deletions modules/impact/hooks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import copy

import torch

import nodes

from impact import utils
from . import segs_nodes
from thirdparty import noise_nodes
Expand All @@ -12,6 +9,7 @@
import folder_paths
import os
from comfy_extras import nodes_custom_sampler
import math


class PixelKSampleHook:
Expand Down Expand Up @@ -201,9 +199,13 @@ def get_custom_noise(self, seed, noise, is_start):
noise = nodes_custom_sampler.Noise_RandomNoise(seed).generate_noise(empty_noise)
noise_2nd = nodes_custom_sampler.Noise_RandomNoise(self.variation_seed).generate_noise(empty_noise)

noise = (1 - self.variation_strength) * noise + self.variation_strength * noise_2nd
mixed_noise = ((1 - self.variation_strength) * noise + self.variation_strength * noise_2nd)

return noise
# NOTE: mixed_noise is not gaussian noise; therefore, adjust the scale to correct it to gaussian noise.
scale_factor = math.sqrt((1 - self.variation_strength) ** 2 + self.variation_strength ** 2)
corrected_noise = mixed_noise / scale_factor # Scale the noise to maintain variance of 1

return corrected_noise


class SimpleDetailerDenoiseSchedulerHook(DetailerHook):
Expand Down

0 comments on commit 80e5958

Please sign in to comment.