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 8a190ab..5e61c29 100644 --- a/adetailer/__version__.py +++ b/adetailer/__version__.py @@ -1 +1 @@ -__version__ = "23.7.5" +__version__ = "23.7.6" diff --git a/install.py b/install.py index 25bfba2..fa71ae9 100644 --- a/install.py +++ b/install.py @@ -7,12 +7,15 @@ 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: 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.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 @@ def get_initial_noise_multiplier(self, p, args: ADetailerArgs) -> float | None: 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 @@ def pred_preprocessing(self, pred: PredictOutput, args: ADetailerArgs): 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 @@ def compare_prompt(p, processed, n: int = 0): 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 @@ def _postprocess_image(self, p, pp, args: ADetailerArgs, *, n: int = 0) -> bool: 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):