Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
5a591382
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
11 个月 前同步成功
通知
1771
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
5a591382
编写于
8月 19, 2023
作者:
A
AUTOMATIC1111
提交者:
GitHub
8月 19, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12616 from catboxanon/extra-noise-callback
Add extra noise callback
上级
448d6bef
254be4ee
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
0 deletion
+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
未找到文件。
modules/script_callbacks.py
浏览文件 @
5a591382
...
@@ -28,6 +28,15 @@ class ImageSaveParams:
...
@@ -28,6 +28,15 @@ class ImageSaveParams:
"""dictionary with parameters for image's PNG info data; infotext will have the key 'parameters'"""
"""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
:
class
CFGDenoiserParams
:
def
__init__
(
self
,
x
,
image_cond
,
sigma
,
sampling_step
,
total_sampling_steps
,
text_cond
,
text_uncond
):
def
__init__
(
self
,
x
,
image_cond
,
sigma
,
sampling_step
,
total_sampling_steps
,
text_cond
,
text_uncond
):
self
.
x
=
x
self
.
x
=
x
...
@@ -100,6 +109,7 @@ callback_map = dict(
...
@@ -100,6 +109,7 @@ callback_map = dict(
callbacks_ui_settings
=
[],
callbacks_ui_settings
=
[],
callbacks_before_image_saved
=
[],
callbacks_before_image_saved
=
[],
callbacks_image_saved
=
[],
callbacks_image_saved
=
[],
callbacks_extra_noise
=
[],
callbacks_cfg_denoiser
=
[],
callbacks_cfg_denoiser
=
[],
callbacks_cfg_denoised
=
[],
callbacks_cfg_denoised
=
[],
callbacks_cfg_after_cfg
=
[],
callbacks_cfg_after_cfg
=
[],
...
@@ -189,6 +199,14 @@ def image_saved_callback(params: ImageSaveParams):
...
@@ -189,6 +199,14 @@ def image_saved_callback(params: ImageSaveParams):
report_exception
(
c
,
'image_saved_callback'
)
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
):
def
cfg_denoiser_callback
(
params
:
CFGDenoiserParams
):
for
c
in
callback_map
[
'callbacks_cfg_denoiser'
]:
for
c
in
callback_map
[
'callbacks_cfg_denoiser'
]:
try
:
try
:
...
@@ -367,6 +385,14 @@ def on_image_saved(callback):
...
@@ -367,6 +385,14 @@ def on_image_saved(callback):
add_callback
(
callback_map
[
'callbacks_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
):
def
on_cfg_denoiser
(
callback
):
"""register a function to be called in the kdiffussion cfg_denoiser method after building the inner model inputs.
"""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:
The callback is called with one argument:
...
...
modules/sd_samplers_kdiffusion.py
浏览文件 @
5a591382
...
@@ -3,6 +3,7 @@ import inspect
...
@@ -3,6 +3,7 @@ import inspect
import
k_diffusion.sampling
import
k_diffusion.sampling
from
modules
import
sd_samplers_common
,
sd_samplers_extra
,
sd_samplers_cfg_denoiser
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.sd_samplers_cfg_denoiser
import
CFGDenoiser
# noqa: F401
from
modules.script_callbacks
import
ExtraNoiseParams
,
extra_noise_callback
from
modules.shared
import
opts
from
modules.shared
import
opts
import
modules.shared
as
shared
import
modules.shared
as
shared
...
@@ -147,6 +148,9 @@ class KDiffusionSampler(sd_samplers_common.Sampler):
...
@@ -147,6 +148,9 @@ class KDiffusionSampler(sd_samplers_common.Sampler):
if
opts
.
img2img_extra_noise
>
0
:
if
opts
.
img2img_extra_noise
>
0
:
p
.
extra_generation_params
[
"Extra noise"
]
=
opts
.
img2img_extra_noise
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
xi
+=
noise
*
opts
.
img2img_extra_noise
extra_params_kwargs
=
self
.
initialize
(
p
)
extra_params_kwargs
=
self
.
initialize
(
p
)
...
...
modules/sd_samplers_timesteps.py
浏览文件 @
5a591382
...
@@ -3,6 +3,7 @@ import inspect
...
@@ -3,6 +3,7 @@ import inspect
import
sys
import
sys
from
modules
import
devices
,
sd_samplers_common
,
sd_samplers_timesteps_impl
from
modules
import
devices
,
sd_samplers_common
,
sd_samplers_timesteps_impl
from
modules.sd_samplers_cfg_denoiser
import
CFGDenoiser
from
modules.sd_samplers_cfg_denoiser
import
CFGDenoiser
from
modules.script_callbacks
import
ExtraNoiseParams
,
extra_noise_callback
from
modules.shared
import
opts
from
modules.shared
import
opts
import
modules.shared
as
shared
import
modules.shared
as
shared
...
@@ -106,6 +107,9 @@ class CompVisSampler(sd_samplers_common.Sampler):
...
@@ -106,6 +107,9 @@ class CompVisSampler(sd_samplers_common.Sampler):
if
opts
.
img2img_extra_noise
>
0
:
if
opts
.
img2img_extra_noise
>
0
:
p
.
extra_generation_params
[
"Extra noise"
]
=
opts
.
img2img_extra_noise
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
xi
+=
noise
*
opts
.
img2img_extra_noise
*
sqrt_alpha_cumprod
extra_params_kwargs
=
self
.
initialize
(
p
)
extra_params_kwargs
=
self
.
initialize
(
p
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录