Commit
·
3979c37
1
Parent(s):
37c03a7
- modules/core.py +2 -16
- modules/cv2win32.py +13 -0
- modules/default_pipeline.py +2 -1
modules/core.py
CHANGED
|
@@ -15,6 +15,7 @@ from nodes import VAEDecode, EmptyLatentImage, CLIPTextEncode
|
|
| 15 |
from comfy.sample import prepare_mask, broadcast_cond, load_additional_models, cleanup_additional_models
|
| 16 |
from modules.samplers_advanced import KSampler, KSamplerWithRefiner
|
| 17 |
from modules.adm_patch import patch_negative_adm
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
patch_negative_adm()
|
|
@@ -22,8 +23,6 @@ opCLIPTextEncode = CLIPTextEncode()
|
|
| 22 |
opEmptyLatentImage = EmptyLatentImage()
|
| 23 |
opVAEDecode = VAEDecode()
|
| 24 |
|
| 25 |
-
cv2_is_top = False
|
| 26 |
-
|
| 27 |
|
| 28 |
class StableDiffusionModel:
|
| 29 |
def __init__(self, unet, vae, clip, clip_vision):
|
|
@@ -82,26 +81,13 @@ def get_previewer(device, latent_format):
|
|
| 82 |
x_sample = einops.rearrange(x_sample, 'b c h w -> b h w c')
|
| 83 |
x_sample = x_sample.cpu().numpy()[..., ::-1].copy().clip(0, 255).astype(np.uint8)
|
| 84 |
for i, s in enumerate(x_sample):
|
| 85 |
-
|
| 86 |
-
cv2.imshow(flag, s)
|
| 87 |
-
cv2.setWindowTitle(flag, f'Preview Image {i} [{step}/{total_steps}]')
|
| 88 |
-
if not cv2_is_top:
|
| 89 |
-
cv2.setWindowProperty(flag, cv2.WND_PROP_TOPMOST, 1)
|
| 90 |
-
cv2_is_top = True
|
| 91 |
-
else:
|
| 92 |
-
cv2.setWindowProperty(flag, cv2.WND_PROP_TOPMOST, 0)
|
| 93 |
-
cv2.waitKey(1)
|
| 94 |
|
| 95 |
taesd.preview = preview_function
|
| 96 |
|
| 97 |
return taesd
|
| 98 |
|
| 99 |
|
| 100 |
-
def close_all_preview():
|
| 101 |
-
cv2_is_top = False
|
| 102 |
-
cv2.destroyAllWindows()
|
| 103 |
-
|
| 104 |
-
|
| 105 |
@torch.no_grad()
|
| 106 |
def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sampler_name='dpmpp_2m_sde_gpu',
|
| 107 |
scheduler='karras', denoise=1.0, disable_noise=False, start_step=None, last_step=None,
|
|
|
|
| 15 |
from comfy.sample import prepare_mask, broadcast_cond, load_additional_models, cleanup_additional_models
|
| 16 |
from modules.samplers_advanced import KSampler, KSamplerWithRefiner
|
| 17 |
from modules.adm_patch import patch_negative_adm
|
| 18 |
+
from modules.cv2win32 import show_preview
|
| 19 |
|
| 20 |
|
| 21 |
patch_negative_adm()
|
|
|
|
| 23 |
opEmptyLatentImage = EmptyLatentImage()
|
| 24 |
opVAEDecode = VAEDecode()
|
| 25 |
|
|
|
|
|
|
|
| 26 |
|
| 27 |
class StableDiffusionModel:
|
| 28 |
def __init__(self, unet, vae, clip, clip_vision):
|
|
|
|
| 81 |
x_sample = einops.rearrange(x_sample, 'b c h w -> b h w c')
|
| 82 |
x_sample = x_sample.cpu().numpy()[..., ::-1].copy().clip(0, 255).astype(np.uint8)
|
| 83 |
for i, s in enumerate(x_sample):
|
| 84 |
+
show_preview(f'OpenCV Diffusion Preview {i}', s, title=f'Preview Image {i} [{step}/{total_steps}]')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
taesd.preview = preview_function
|
| 87 |
|
| 88 |
return taesd
|
| 89 |
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
@torch.no_grad()
|
| 92 |
def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sampler_name='dpmpp_2m_sde_gpu',
|
| 93 |
scheduler='karras', denoise=1.0, disable_noise=False, start_step=None, last_step=None,
|
modules/cv2win32.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def show_preview(flag, img, title=None):
|
| 5 |
+
if title is None:
|
| 6 |
+
title = flag
|
| 7 |
+
cv2.imshow(flag, img)
|
| 8 |
+
cv2.setWindowTitle(flag, title)
|
| 9 |
+
cv2.waitKey(1)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def close_all_preview():
|
| 13 |
+
cv2.destroyAllWindows()
|
modules/default_pipeline.py
CHANGED
|
@@ -3,6 +3,7 @@ import os
|
|
| 3 |
import torch
|
| 4 |
|
| 5 |
from modules.path import modelfile_path, lorafile_path
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
xl_base_filename = os.path.join(modelfile_path, 'sd_xl_base_1.0.safetensors')
|
|
@@ -43,6 +44,6 @@ def process(positive_prompt, negative_prompt, width=1024, height=1024, batch_siz
|
|
| 43 |
|
| 44 |
images = core.image_to_numpy(decoded_latent)
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
return images
|
|
|
|
| 3 |
import torch
|
| 4 |
|
| 5 |
from modules.path import modelfile_path, lorafile_path
|
| 6 |
+
from modules.cv2win32 import close_all_preview
|
| 7 |
|
| 8 |
|
| 9 |
xl_base_filename = os.path.join(modelfile_path, 'sd_xl_base_1.0.safetensors')
|
|
|
|
| 44 |
|
| 45 |
images = core.image_to_numpy(decoded_latent)
|
| 46 |
|
| 47 |
+
close_all_preview()
|
| 48 |
|
| 49 |
return images
|