Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
fd7c6366
Commit
fd7c6366
authored
Apr 10, 2024
by
comfyanonymous
Browse files
Add an AddNoise node to add noise depending on the sigma.
parent
831511a1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
comfy_extras/nodes_custom_sampler.py
comfy_extras/nodes_custom_sampler.py
+47
-0
No files found.
comfy_extras/nodes_custom_sampler.py
View file @
fd7c6366
...
...
@@ -538,6 +538,52 @@ class SamplerCustomAdvanced:
out_denoised
=
out
return
(
out
,
out_denoised
)
class
AddNoise
:
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"model"
:
(
"MODEL"
,),
"noise"
:
(
"NOISE"
,
),
"sigmas"
:
(
"SIGMAS"
,
),
"latent_image"
:
(
"LATENT"
,
),
}
}
RETURN_TYPES
=
(
"LATENT"
,)
FUNCTION
=
"add_noise"
CATEGORY
=
"_for_testing/custom_sampling/noise"
def
add_noise
(
self
,
model
,
noise
,
sigmas
,
latent_image
):
if
len
(
sigmas
)
==
0
:
return
latent_image
latent
=
latent_image
latent_image
=
latent
[
"samples"
]
noisy
=
noise
.
generate_noise
(
latent
)
model_sampling
=
model
.
get_model_object
(
"model_sampling"
)
process_latent_out
=
model
.
get_model_object
(
"process_latent_out"
)
process_latent_in
=
model
.
get_model_object
(
"process_latent_in"
)
if
len
(
sigmas
)
>
1
:
scale
=
torch
.
abs
(
sigmas
[
0
]
-
sigmas
[
-
1
])
else
:
scale
=
sigmas
[
0
]
if
torch
.
count_nonzero
(
latent_image
)
>
0
:
#Don't shift the empty latent image.
latent_image
=
process_latent_in
(
latent_image
)
noisy
=
model_sampling
.
noise_scaling
(
scale
,
noisy
,
latent_image
)
noisy
=
process_latent_out
(
noisy
)
noisy
=
torch
.
nan_to_num
(
noisy
,
nan
=
0.0
,
posinf
=
0.0
,
neginf
=
0.0
)
out
=
latent
.
copy
()
out
[
"samples"
]
=
noisy
return
(
out
,)
NODE_CLASS_MAPPINGS
=
{
"SamplerCustom"
:
SamplerCustom
,
"BasicScheduler"
:
BasicScheduler
,
...
...
@@ -561,5 +607,6 @@ NODE_CLASS_MAPPINGS = {
"BasicGuider"
:
BasicGuider
,
"RandomNoise"
:
RandomNoise
,
"DisableNoise"
:
DisableNoise
,
"AddNoise"
:
AddNoise
,
"SamplerCustomAdvanced"
:
SamplerCustomAdvanced
,
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment