Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
5a591382
Commit
5a591382
authored
Aug 19, 2023
by
AUTOMATIC1111
Committed by
GitHub
Aug 19, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12616 from catboxanon/extra-noise-callback
Add extra noise callback
parents
448d6bef
254be4ee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
0 deletions
+34
-0
modules/script_callbacks.py
modules/script_callbacks.py
+26
-0
modules/sd_samplers_kdiffusion.py
modules/sd_samplers_kdiffusion.py
+4
-0
modules/sd_samplers_timesteps.py
modules/sd_samplers_timesteps.py
+4
-0
No files found.
modules/script_callbacks.py
View file @
5a591382
...
...
@@ -28,6 +28,15 @@ class ImageSaveParams:
"""dictionary with parameters for image's PNG info data; infotext will have the key 'parameters'"""
class
ExtraNoiseParams
:
def
__init__
(
self
,
noise
,
x
):
self
.
noise
=
noise
"""Random noise generated by the seed"""
self
.
x
=
x
"""Latent image representation of the image"""
class
CFGDenoiserParams
:
def
__init__
(
self
,
x
,
image_cond
,
sigma
,
sampling_step
,
total_sampling_steps
,
text_cond
,
text_uncond
):
self
.
x
=
x
...
...
@@ -100,6 +109,7 @@ callback_map = dict(
callbacks_ui_settings
=
[],
callbacks_before_image_saved
=
[],
callbacks_image_saved
=
[],
callbacks_extra_noise
=
[],
callbacks_cfg_denoiser
=
[],
callbacks_cfg_denoised
=
[],
callbacks_cfg_after_cfg
=
[],
...
...
@@ -189,6 +199,14 @@ def image_saved_callback(params: ImageSaveParams):
report_exception
(
c
,
'image_saved_callback'
)
def
extra_noise_callback
(
params
:
ExtraNoiseParams
):
for
c
in
callback_map
[
'callbacks_extra_noise'
]:
try
:
c
.
callback
(
params
)
except
Exception
:
report_exception
(
c
,
'callbacks_extra_noise'
)
def
cfg_denoiser_callback
(
params
:
CFGDenoiserParams
):
for
c
in
callback_map
[
'callbacks_cfg_denoiser'
]:
try
:
...
...
@@ -367,6 +385,14 @@ def on_image_saved(callback):
add_callback
(
callback_map
[
'callbacks_image_saved'
],
callback
)
def
on_extra_noise
(
callback
):
"""register a function to be called before adding extra noise in img2img or hires fix;
The callback is called with one argument:
- params: ExtraNoiseParams - contains noise determined by seed and latent representation of image
"""
add_callback
(
callback_map
[
'callbacks_extra_noise'
],
callback
)
def
on_cfg_denoiser
(
callback
):
"""register a function to be called in the kdiffussion cfg_denoiser method after building the inner model inputs.
The callback is called with one argument:
...
...
modules/sd_samplers_kdiffusion.py
View file @
5a591382
...
...
@@ -3,6 +3,7 @@ import inspect
import
k_diffusion.sampling
from
modules
import
sd_samplers_common
,
sd_samplers_extra
,
sd_samplers_cfg_denoiser
from
modules.sd_samplers_cfg_denoiser
import
CFGDenoiser
# noqa: F401
from
modules.script_callbacks
import
ExtraNoiseParams
,
extra_noise_callback
from
modules.shared
import
opts
import
modules.shared
as
shared
...
...
@@ -147,6 +148,9 @@ class KDiffusionSampler(sd_samplers_common.Sampler):
if
opts
.
img2img_extra_noise
>
0
:
p
.
extra_generation_params
[
"Extra noise"
]
=
opts
.
img2img_extra_noise
extra_noise_params
=
ExtraNoiseParams
(
noise
,
x
)
extra_noise_callback
(
extra_noise_params
)
noise
=
extra_noise_params
.
noise
xi
+=
noise
*
opts
.
img2img_extra_noise
extra_params_kwargs
=
self
.
initialize
(
p
)
...
...
modules/sd_samplers_timesteps.py
View file @
5a591382
...
...
@@ -3,6 +3,7 @@ import inspect
import
sys
from
modules
import
devices
,
sd_samplers_common
,
sd_samplers_timesteps_impl
from
modules.sd_samplers_cfg_denoiser
import
CFGDenoiser
from
modules.script_callbacks
import
ExtraNoiseParams
,
extra_noise_callback
from
modules.shared
import
opts
import
modules.shared
as
shared
...
...
@@ -106,6 +107,9 @@ class CompVisSampler(sd_samplers_common.Sampler):
if
opts
.
img2img_extra_noise
>
0
:
p
.
extra_generation_params
[
"Extra noise"
]
=
opts
.
img2img_extra_noise
extra_noise_params
=
ExtraNoiseParams
(
noise
,
x
)
extra_noise_callback
(
extra_noise_params
)
noise
=
extra_noise_params
.
noise
xi
+=
noise
*
opts
.
img2img_extra_noise
*
sqrt_alpha_cumprod
extra_params_kwargs
=
self
.
initialize
(
p
)
...
...
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