Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing-su committed Jul 15, 2023
2 parents e881a65 + 5171a8b commit ee75bb8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion adetailer/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "23.7.5"
__version__ = "23.7.6"
17 changes: 7 additions & 10 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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:
Expand Down
32 changes: 19 additions & 13 deletions scripts/!adetailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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)
Expand All @@ -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_):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit ee75bb8

Please sign in to comment.