mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
i
This commit is contained in:
+2
-16
@@ -15,6 +15,7 @@ from nodes import VAEDecode, EmptyLatentImage, CLIPTextEncode
|
|||||||
from comfy.sample import prepare_mask, broadcast_cond, load_additional_models, cleanup_additional_models
|
from comfy.sample import prepare_mask, broadcast_cond, load_additional_models, cleanup_additional_models
|
||||||
from modules.samplers_advanced import KSampler, KSamplerWithRefiner
|
from modules.samplers_advanced import KSampler, KSamplerWithRefiner
|
||||||
from modules.adm_patch import patch_negative_adm
|
from modules.adm_patch import patch_negative_adm
|
||||||
|
from modules.cv2win32 import show_preview
|
||||||
|
|
||||||
|
|
||||||
patch_negative_adm()
|
patch_negative_adm()
|
||||||
@@ -22,8 +23,6 @@ opCLIPTextEncode = CLIPTextEncode()
|
|||||||
opEmptyLatentImage = EmptyLatentImage()
|
opEmptyLatentImage = EmptyLatentImage()
|
||||||
opVAEDecode = VAEDecode()
|
opVAEDecode = VAEDecode()
|
||||||
|
|
||||||
cv2_is_top = False
|
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionModel:
|
class StableDiffusionModel:
|
||||||
def __init__(self, unet, vae, clip, clip_vision):
|
def __init__(self, unet, vae, clip, clip_vision):
|
||||||
@@ -82,26 +81,13 @@ def get_previewer(device, latent_format):
|
|||||||
x_sample = einops.rearrange(x_sample, 'b c h w -> b h w c')
|
x_sample = einops.rearrange(x_sample, 'b c h w -> b h w c')
|
||||||
x_sample = x_sample.cpu().numpy()[..., ::-1].copy().clip(0, 255).astype(np.uint8)
|
x_sample = x_sample.cpu().numpy()[..., ::-1].copy().clip(0, 255).astype(np.uint8)
|
||||||
for i, s in enumerate(x_sample):
|
for i, s in enumerate(x_sample):
|
||||||
flag = f'OpenCV Diffusion Preview {i}'
|
show_preview(f'OpenCV Diffusion Preview {i}', s, title=f'Preview Image {i} [{step}/{total_steps}]')
|
||||||
cv2.imshow(flag, s)
|
|
||||||
cv2.setWindowTitle(flag, f'Preview Image {i} [{step}/{total_steps}]')
|
|
||||||
if not cv2_is_top:
|
|
||||||
cv2.setWindowProperty(flag, cv2.WND_PROP_TOPMOST, 1)
|
|
||||||
cv2_is_top = True
|
|
||||||
else:
|
|
||||||
cv2.setWindowProperty(flag, cv2.WND_PROP_TOPMOST, 0)
|
|
||||||
cv2.waitKey(1)
|
|
||||||
|
|
||||||
taesd.preview = preview_function
|
taesd.preview = preview_function
|
||||||
|
|
||||||
return taesd
|
return taesd
|
||||||
|
|
||||||
|
|
||||||
def close_all_preview():
|
|
||||||
cv2_is_top = False
|
|
||||||
cv2.destroyAllWindows()
|
|
||||||
|
|
||||||
|
|
||||||
@torch.no_grad()
|
@torch.no_grad()
|
||||||
def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sampler_name='dpmpp_2m_sde_gpu',
|
def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sampler_name='dpmpp_2m_sde_gpu',
|
||||||
scheduler='karras', denoise=1.0, disable_noise=False, start_step=None, last_step=None,
|
scheduler='karras', denoise=1.0, disable_noise=False, start_step=None, last_step=None,
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import cv2
|
||||||
|
|
||||||
|
|
||||||
|
def show_preview(flag, img, title=None):
|
||||||
|
if title is None:
|
||||||
|
title = flag
|
||||||
|
cv2.imshow(flag, img)
|
||||||
|
cv2.setWindowTitle(flag, title)
|
||||||
|
cv2.waitKey(1)
|
||||||
|
|
||||||
|
|
||||||
|
def close_all_preview():
|
||||||
|
cv2.destroyAllWindows()
|
||||||
@@ -3,6 +3,7 @@ import os
|
|||||||
import torch
|
import torch
|
||||||
|
|
||||||
from modules.path import modelfile_path, lorafile_path
|
from modules.path import modelfile_path, lorafile_path
|
||||||
|
from modules.cv2win32 import close_all_preview
|
||||||
|
|
||||||
|
|
||||||
xl_base_filename = os.path.join(modelfile_path, 'sd_xl_base_1.0.safetensors')
|
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
|
|||||||
|
|
||||||
images = core.image_to_numpy(decoded_latent)
|
images = core.image_to_numpy(decoded_latent)
|
||||||
|
|
||||||
core.close_all_preview()
|
close_all_preview()
|
||||||
|
|
||||||
return images
|
return images
|
||||||
|
|||||||
Reference in New Issue
Block a user