19
19
from modules import devices , prompt_parser , masking , sd_samplers , lowvram , generation_parameters_copypaste , extra_networks , sd_vae_approx , scripts , sd_samplers_common , sd_unet , errors , rng
20
20
from modules .rng import slerp # noqa: F401
21
21
from modules .sd_hijack import model_hijack
22
- from modules .sd_samplers_common import images_tensor_to_samples , decode_first_stage , approximation_indexes
23
22
from modules .shared import opts , cmd_opts , state
24
23
import modules .shared as shared
25
24
import modules .paths as paths
@@ -89,6 +88,7 @@ def create_binary_mask(image):
89
88
return image
90
89
91
90
def txt2img_image_conditioning (sd_model , x , width , height ):
91
+ from modules .sd_samplers_common import images_tensor_to_samples , approximation_indexes
92
92
if sd_model .model .conditioning_key in {'hybrid' , 'concat' }: # Inpainting models
93
93
94
94
# The "masked-image" in this case will just be all 0.5 since the entire image is masked.
@@ -277,6 +277,7 @@ def txt2img_image_conditioning(self, x, width=None, height=None):
277
277
return txt2img_image_conditioning (self .sd_model , x , width or self .width , height or self .height )
278
278
279
279
def depth2img_image_conditioning (self , source_image ):
280
+ from modules .sd_samplers_common import images_tensor_to_samples , approximation_indexes
280
281
# Use the AddMiDaS helper to Format our source image to suit the MiDaS model
281
282
transformer = AddMiDaS (model_type = "dpt_hybrid" )
282
283
transformed = transformer ({"jpg" : rearrange (source_image [0 ], "c h w -> h w c" )})
@@ -296,6 +297,7 @@ def depth2img_image_conditioning(self, source_image):
296
297
return conditioning
297
298
298
299
def edit_image_conditioning (self , source_image ):
300
+ from modules .sd_samplers_common import images_tensor_to_samples , approximation_indexes
299
301
conditioning_image = images_tensor_to_samples (source_image * 0.5 + 0.5 , approximation_indexes .get (opts .sd_vae_encode_method ))
300
302
301
303
return conditioning_image
@@ -588,6 +590,7 @@ class DecodedSamples(list):
588
590
589
591
590
592
def decode_latent_batch (model , batch , target_device = None , check_for_nans = False ):
593
+ from modules .sd_samplers_common import decode_first_stage
591
594
samples = DecodedSamples ()
592
595
593
596
for i in range (batch .shape [0 ]):
@@ -1156,6 +1159,7 @@ def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subs
1156
1159
return self .sample_hr_pass (samples , decoded_samples , seeds , subseeds , subseed_strength , prompts )
1157
1160
1158
1161
def sample_hr_pass (self , samples , decoded_samples , seeds , subseeds , subseed_strength , prompts ):
1162
+
1159
1163
if shared .state .interrupted :
1160
1164
return samples
1161
1165
@@ -1189,6 +1193,7 @@ def save_intermediate(image, index):
1189
1193
# Avoid making the inpainting conditioning unless necessary as
1190
1194
# this does need some extra compute to decode / encode the image again.
1191
1195
if getattr (self , "inpainting_mask_weight" , shared .opts .inpainting_mask_weight ) < 1.0 :
1196
+ from modules .sd_samplers_common import decode_first_stage , approximation_indexes
1192
1197
image_conditioning = self .img2img_image_conditioning (decode_first_stage (self .sd_model , samples ), samples )
1193
1198
else :
1194
1199
image_conditioning = self .txt2img_image_conditioning (samples )
@@ -1212,6 +1217,7 @@ def save_intermediate(image, index):
1212
1217
decoded_samples = decoded_samples .to (shared .device , dtype = devices .dtype_vae )
1213
1218
1214
1219
if opts .sd_vae_encode_method != 'Full' :
1220
+ from modules .sd_samplers_common import images_tensor_to_samples
1215
1221
self .extra_generation_params ['VAE Encoder' ] = opts .sd_vae_encode_method
1216
1222
samples = images_tensor_to_samples (decoded_samples , approximation_indexes .get (opts .sd_vae_encode_method ))
1217
1223
@@ -1387,6 +1393,7 @@ def mask_blur(self, value):
1387
1393
self .mask_blur_y = value
1388
1394
1389
1395
def init (self , all_prompts , all_seeds , all_subseeds ):
1396
+ from modules .sd_samplers_common import images_tensor_to_samples , approximation_indexes
1390
1397
self .image_cfg_scale : float = self .image_cfg_scale if shared .sd_model .cond_stage_key == "edit" else None
1391
1398
1392
1399
self .sampler = sd_samplers .create_sampler (self .sampler_name , self .sd_model )
0 commit comments