@@ -24,12 +24,22 @@ def __init__(self, image, p, filename, pnginfo):
24
24
"""dictionary with parameters for image's PNG info data; infotext will have the key 'parameters'"""
25
25
26
26
27
+ class CGFDenoiserParams :
28
+ def __init__ (self , x_in , image_cond_in , sigma_in , sampling_step , total_sampling_steps ):
29
+ self .x_in = x_in
30
+ self .image_cond_in = image_cond_in
31
+ self .sigma_in = sigma_in
32
+ self .sampling_step = sampling_step
33
+ self .total_sampling_steps = total_sampling_steps
34
+
35
+
27
36
ScriptCallback = namedtuple ("ScriptCallback" , ["script" , "callback" ])
28
37
callbacks_model_loaded = []
29
38
callbacks_ui_tabs = []
30
39
callbacks_ui_settings = []
31
40
callbacks_before_image_saved = []
32
41
callbacks_image_saved = []
42
+ callbacks_cfg_denoiser = []
33
43
34
44
35
45
def clear_callbacks ():
@@ -84,6 +94,14 @@ def image_saved_callback(params: ImageSaveParams):
84
94
report_exception (c , 'image_saved_callback' )
85
95
86
96
97
+ def cfg_denoiser_callback (params : CGFDenoiserParams ):
98
+ for c in callbacks_cfg_denoiser :
99
+ try :
100
+ c .callback (params )
101
+ except Exception :
102
+ report_exception (c , 'cfg_denoiser_callback' )
103
+
104
+
87
105
def add_callback (callbacks , fun ):
88
106
stack = [x for x in inspect .stack () if x .filename != __file__ ]
89
107
filename = stack [0 ].filename if len (stack ) > 0 else 'unknown file'
@@ -130,3 +148,12 @@ def on_image_saved(callback):
130
148
- params: ImageSaveParams - parameters the image was saved with. Changing fields in this object does nothing.
131
149
"""
132
150
add_callback (callbacks_image_saved , callback )
151
+
152
+
153
+ def on_cfg_denoiser (callback ):
154
+ """register a function to be called in the kdiffussion cfg_denoiser method after building the inner model inputs.
155
+ The callback is called with one argument:
156
+ - params: CGFDenoiserParams - parameters to be passed to the inner model and sampling state details.
157
+ """
158
+ add_callback (callbacks_cfg_denoiser , callback )
159
+
0 commit comments