From 4cec57a1fb496f81071321658f1b8c4630530af3 Mon Sep 17 00:00:00 2001 From: Bingsu Date: Sun, 9 Jul 2023 21:29:38 +0900 Subject: [PATCH 1/3] feat: ensure rgb init image, misc --- adetailer/__version__.py | 2 +- scripts/!adetailer.py | 32 +++++++++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/adetailer/__version__.py b/adetailer/__version__.py index 8a190ab..50fd40c 100644 --- a/adetailer/__version__.py +++ b/adetailer/__version__.py @@ -1 +1 @@ -__version__ = "23.7.5" +__version__ = "23.7.6.dev0" diff --git a/scripts/!adetailer.py b/scripts/!adetailer.py index ed5de1a..7251262 100644 --- a/scripts/!adetailer.py +++ b/scripts/!adetailer.py @@ -33,7 +33,6 @@ from controlnet_ext import ControlNetExt, controlnet_exists, get_cn_models from controlnet_ext.restore import ( CNHijackRestore, cn_allow_script_control, - cn_restore_unet_hook, ) from sd_webui import images, safe, script_callbacks, scripts, shared from sd_webui.devices import NansException @@ -302,7 +301,8 @@ class AfterDetailerScript(scripts.Script): return args.ad_noise_multiplier return None - def infotext(self, p) -> str: + @staticmethod + def infotext(p) -> str: return create_infotext( p, p.all_prompts, p.all_seeds, p.all_subseeds, None, 0, 0 ) @@ -460,8 +460,15 @@ class AfterDetailerScript(scripts.Script): merge_invert=args.ad_mask_merge_invert, ) + @staticmethod + def ensure_rgb_image(image: Any): + if hasattr(image, "mode") and image.mode != "RGB": + image = image.convert("RGB") + return image + + @staticmethod def i2i_prompts_replace( - self, i2i, prompts: list[str], negative_prompts: list[str], j: int + i2i, prompts: list[str], negative_prompts: list[str], j: int ) -> None: i1 = min(j, len(prompts) - 1) i2 = min(j, len(negative_prompts) - 1) @@ -482,15 +489,16 @@ class AfterDetailerScript(scripts.Script): f"[-] ADetailer: applied {ordinal(n + 1)} ad_negative_prompt: {processed.all_negative_prompts[0]!r}" ) - def need_call_process(self, p) -> bool: - i = p._ad_idx + @staticmethod + def need_call_process(p) -> bool: + i = p.batch_index bs = p.batch_size - return i % bs == bs - 1 + return i == bs - 1 - def need_call_postprocess(self, p) -> bool: - i = p._ad_idx - bs = p.batch_size - return i % bs == 0 + @staticmethod + def need_call_postprocess(p) -> bool: + i = p.batch_index + return i == 0 @rich_traceback def process(self, p, *args_): @@ -555,12 +563,10 @@ class AfterDetailerScript(scripts.Script): if is_mediapipe: print(f"mediapipe: {steps} detected.") - _user_pt = p.prompt - _user_ng = p.negative_prompt - p2 = copy(i2i) for j in range(steps): p2.image_mask = masks[j] + p2.init_images[0] = self.ensure_rgb_image(p2.init_images[0]) self.i2i_prompts_replace(p2, ad_prompts, ad_negatives, j) if re.match(r"^\s*\[SKIP\]\s*$", p2.prompt): From b00b6b5fe08e3346d5848ee73583bc1103e269ed Mon Sep 17 00:00:00 2001 From: Bingsu Date: Sun, 16 Jul 2023 02:06:20 +0900 Subject: [PATCH 2/3] feat: add `py-cpuinfo`, remove `protobuf` --- install.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/install.py b/install.py index 25bfba2..fa71ae9 100644 --- a/install.py +++ b/install.py @@ -7,12 +7,15 @@ from importlib.metadata import version # python >= 3.8 from packaging.version import parse +import_name = {"py-cpuinfo": "cpuinfo"} + def is_installed( package: str, min_version: str | None = None, max_version: str | None = None ): + name = import_name.get(package, package) try: - spec = importlib.util.find_spec(package) + spec = importlib.util.find_spec(name) except ModuleNotFoundError: return False @@ -27,9 +30,6 @@ def is_installed( if not max_version: max_version = "99999999.99999999.99999999" - if package == "google.protobuf": - package = "protobuf" - try: pkg_version = version(package) return parse(min_version) <= parse(pkg_version) <= parse(max_version) @@ -49,15 +49,12 @@ def install(): ("huggingface_hub", None, None), ("pydantic", "1.10.8", None), ("rich", "13.4.2", None), - # mediapipe - ("protobuf", "3.20.0", "3.20.9999"), + # ultralytics + ("py-cpuinfo", None, None), ] for pkg, low, high in deps: - # https://github.com/protocolbuffers/protobuf/tree/main/python - name = "google.protobuf" if pkg == "protobuf" else pkg - - if not is_installed(name, low, high): + if not is_installed(pkg, low, high): if low and high: cmd = f"{pkg}>={low},<={high}" elif low: From 5171a8b69079d7395f58f9036dabcc5415931fc2 Mon Sep 17 00:00:00 2001 From: Bingsu Date: Sun, 16 Jul 2023 02:15:00 +0900 Subject: [PATCH 3/3] chore: v23.7.6 --- CHANGELOG.md | 6 ++++++ adetailer/__version__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af8a888..12d26d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 2023-07-16 + +- v23.7.6 +- `ultralytics 8.0.135`에 추가된 cpuinfo 기능을 위해 `py-cpuinfo`를 미리 설치하게 함. (미리 설치 안하면 cpu나 mps사용할 때 재시작해야함) +- init_image가 RGB 모드가 아닐 때 RGB로 변경. + ## 2023-07-07 - v23.7.4 diff --git a/adetailer/__version__.py b/adetailer/__version__.py index 50fd40c..5e61c29 100644 --- a/adetailer/__version__.py +++ b/adetailer/__version__.py @@ -1 +1 @@ -__version__ = "23.7.6.dev0" +__version__ = "23.7.6"