diff --git a/CHANGELOG.md b/CHANGELOG.md index e5d924948..9df9e17ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,7 @@ As of this release, default backend is set to **diffusers** as its more feature - support controlnets with non-default yaml config files - implement resize modes for override images - allow any selection of units + - dynamically install depenencies required by specific processors - fix input image size - fix video color mode - fix correct image mode diff --git a/extensions-builtin/stable-diffusion-webui-images-browser b/extensions-builtin/stable-diffusion-webui-images-browser index 8dc4665c4..3d2d0f4c7 160000 --- a/extensions-builtin/stable-diffusion-webui-images-browser +++ b/extensions-builtin/stable-diffusion-webui-images-browser @@ -1 +1 @@ -Subproject commit 8dc4665c4f4e79cc12d06ad5b6fb47ddf84593fa +Subproject commit 3d2d0f4c7b0599f88df99a9ea66c21bcbec49bda diff --git a/html/reference.json b/html/reference.json index b4b46db1c..f397aee4b 100644 --- a/html/reference.json +++ b/html/reference.json @@ -44,18 +44,22 @@ }, "StabilityAI SD-XL 1.0 Base": { "path": "stabilityai/stable-diffusion-xl-base-1.0", + "variant": "fp16", "desc": "Stable Diffusion XL (SDXL) is the latest AI image generation model that is tailored towards more photorealistic outputs with more detailed imagery and composition compared to previous SD models, including SD 2.1. It can make realistic faces, legible text within the images, and better image composition, all while using shorter and simpler prompts at a greatly increased base resolution of 1024x1024. Just like its predecessors, SDXL has the ability to generate image variations using image-to-image prompting, inpainting (reimagining of the selected parts of an image), and outpainting (creating new parts that lie outside the image borders).", "preview": "stabilityai--stable-diffusion-xl-base-1.0.jpg" }, "StabilityAI SD 2.1 Turbo": { "path": "stabilityai/sd-turbo", "alt": "sd_turbo.safetensors@https://huggingface.co/stabilityai/sd-turbo/resolve/main/sd_turbo.safetensors?download=true", + "variant": "fp16", "desc": "SD-Turbo is a distilled version of Stable Diffusion 2.1, trained for real-time synthesis. SD-Turbo is based on a novel training method called Adversarial Diffusion Distillation (ADD) (see the technical report), which allows sampling large-scale foundational image diffusion models in 1 to 4 steps at high image quality. This approach uses score distillation to leverage large-scale off-the-shelf image diffusion models as a teacher signal and combines this with an adversarial loss to ensure high image fidelity even in the low-step regime of one or two sampling steps.", "preview": "stabilityai--sd-turbo.jpg", "original": true }, "StabilityAI SD-XL Turbo": { "path": "stabilityai/sdxl-turbo", + "alt": "sdxl_turbo.safetensors@https://huggingface.co/stabilityai/sdxl-turbo/resolve/main/sdxl_turbo.safetensors?download=true", + "variant": "fp16", "desc": "SDXL-Turbo is a distilled version of SDXL 1.0, trained for real-time synthesis. SDXL-Turbo is based on a novel training method called Adversarial Diffusion Distillation (ADD) (see the technical report), which allows sampling large-scale foundational image diffusion models in 1 to 4 steps at high image quality. This approach uses score distillation to leverage large-scale off-the-shelf image diffusion models as a teacher signal and combines this with an adversarial loss to ensure high image fidelity even in the low-step regime of one or two sampling steps.", "preview": "stabilityai--sdxl-turbo.jpg" }, diff --git a/modules/control/proc/dwpose/__init__.py b/modules/control/proc/dwpose/__init__.py index d5009ade6..45039e920 100644 --- a/modules/control/proc/dwpose/__init__.py +++ b/modules/control/proc/dwpose/__init__.py @@ -6,13 +6,28 @@ import os os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE" - import cv2 import numpy as np from PIL import Image - from modules.control.util import HWC3, resize_image from .draw import draw_bodypose, draw_handpose, draw_facepose +checked_ok = False + + +def check_dependencies(): + global checked_ok # pylint: disable=global-statement + from installer import installed, install, log + packages = [('openmim', 'openmim'), ('mmengine', 'mmengine'), ('mmcv', 'mmcv'), ('mmpose', 'mmpose'), ('mmdet', 'mmdet')] + for pkg in packages: + if not installed(pkg[1], reload=True, quiet=True): + install(pkg[0], pkg[1], ignore=False) + try: + import mmcv # pylint: disable=unused-import + checked_ok = True + return True + except Exception as e: + log.error(f'DWPose: {e}') + return False def draw_pose(pose, H, W): @@ -31,6 +46,9 @@ def draw_pose(pose, H, W): class DWposeDetector: def __init__(self, det_config=None, det_ckpt=None, pose_config=None, pose_ckpt=None, device="cpu"): + if not checked_ok: + if not check_dependencies(): + return from .wholebody import Wholebody self.pose_estimation = Wholebody(det_config, det_ckpt, pose_config, pose_ckpt, device) diff --git a/modules/control/proc/mediapipe_face.py b/modules/control/proc/mediapipe_face.py index 7c26ff410..04d90c02e 100644 --- a/modules/control/proc/mediapipe_face.py +++ b/modules/control/proc/mediapipe_face.py @@ -5,6 +5,24 @@ from PIL import Image from modules.control.util import HWC3, resize_image +checked_ok = False + +def check_dependencies(): + global checked_ok # pylint: disable=global-statement + from installer import installed, install, log + packages = [('mediapipe', 'mediapipe')] + for pkg in packages: + if not installed(pkg[1], reload=True, quiet=True): + install(pkg[0], pkg[1], ignore=False) + try: + import mediapipe as mp # pylint: disable=unused-import + checked_ok = True + return True + except Exception as e: + log.error(f'MediaPipe: {e}') + return False + + class MediapipeFaceDetector: def __call__(self, input_image: Union[np.ndarray, Image.Image] = None, @@ -14,6 +32,9 @@ class MediapipeFaceDetector: detect_resolution: int = 512, image_resolution: int = 512, **kwargs): + if not checked_ok: + if not check_dependencies(): + return from .mediapipe_face_util import generate_annotation if input_image is None: raise ValueError("input_image must be defined.") diff --git a/modules/modelloader.py b/modules/modelloader.py index bab65c100..00ef7bb08 100644 --- a/modules/modelloader.py +++ b/modules/modelloader.py @@ -296,7 +296,20 @@ def load_reference(name: str): shared.log.debug(f'Reference model: {found[0]}') return True shared.log.debug(f'Reference download: {name}') - model_dir = download_diffusers_model(name, shared.opts.diffusers_dir) + reference_models = shared.readfile(os.path.join('html', 'reference.json'), silent=False) + model_opts = {} + for v in reference_models.values(): + if v.get('path', '') == name: + model_opts = v + break + model_dir = download_diffusers_model( + hub_id=name, + cache_dir=shared.opts.diffusers_dir, + variant=model_opts.get('variant', None), + revision=model_opts.get('revision', None), + mirror=model_opts.get('mirror', None), + custom_pipeline=model_opts.get('custom_pipeline', None) + ) if model_dir is None: shared.log.debug(f'Reference download failed: {name}') return False