Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing-su committed Dec 6, 2024
2 parents 358d170 + 190e708 commit 7ae5d7a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.3.3
rev: v3.4.1
hooks:
- id: prettier

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.8.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
4 changes: 2 additions & 2 deletions adetailer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
ADETAILER = "ADetailer"

__all__ = [
"__version__",
"ADetailerArgs",
"ADETAILER",
"ALL_ARGS",
"ADetailerArgs",
"PredictOutput",
"__version__",
"get_models",
"mediapipe_predict",
"ultralytics_predict",
Expand Down
2 changes: 1 addition & 1 deletion adetailer/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from huggingface_hub import hf_hub_download
from PIL import Image, ImageDraw
from rich import print
from rich import print # noqa: A004 Shadowing built-in 'print'
from torchvision.transforms.functional import to_pil_image

REPO_ID = "Bingsu/adetailer"
Expand Down
2 changes: 1 addition & 1 deletion controlnet_ext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from .restore import CNHijackRestore, cn_allow_script_control

__all__ = [
"ControlNetExt",
"CNHijackRestore",
"ControlNetExt",
"cn_allow_script_control",
"controlnet_exists",
"controlnet_type",
Expand Down
18 changes: 14 additions & 4 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
from packaging.version import parse

import_name = {"py-cpuinfo": "cpuinfo", "protobuf": "google.protobuf"}
custom_requirements = {"ultralytics": "ultralytics>=8.3.0,!=8.3.41,!=8.3.42"}
excluded_versions = {"ultralytics": ("8.3.41", "8.3.42")}


def is_installed(
package: str, min_version: str | None = None, max_version: str | None = None
package: str,
min_version: str | None = None,
max_version: str | None = None,
):
name = import_name.get(package, package)
excluded = excluded_versions.get(package, ())
try:
spec = importlib.util.find_spec(name)
except ModuleNotFoundError:
Expand All @@ -32,7 +37,10 @@ def is_installed(

try:
pkg_version = version(package)
return parse(min_version) <= parse(pkg_version) <= parse(max_version)
return (
parse(min_version) <= parse(pkg_version) <= parse(max_version)
and pkg_version not in excluded
)
except Exception:
return False

Expand All @@ -44,15 +52,17 @@ def run_pip(*args):
def install():
deps = [
# requirements
("ultralytics", "8.2.0", None),
("ultralytics", "8.3.0", None),
("mediapipe", "0.10.13", "0.10.15"),
("rich", "13.0.0", None),
]

pkgs = []
for pkg, low, high in deps:
if not is_installed(pkg, low, high):
if low and high:
if pkg in custom_requirements:
cmd = custom_requirements[pkg]
elif low and high:
cmd = f"{pkg}>={low},<={high}"
elif low:
cmd = f"{pkg}>={low}"
Expand Down
2 changes: 1 addition & 1 deletion scripts/!adetailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import gradio as gr
from PIL import Image, ImageChops
from rich import print
from rich import print # noqa: A004 Shadowing built-in 'print'

import modules
from aaaaaa.conditional import create_binary_mask, schedulers
Expand Down
9 changes: 5 additions & 4 deletions tests/test_mediapipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
)
def test_mediapipe(sample_image2: Image.Image, model_name: str):
result = mediapipe_predict(model_name, sample_image2)
assert result.preview is not None
assert len(result.bboxes) > 0
assert len(result.masks) > 0
assert len(result.confidences) > 0
if result.preview is not None:
assert len(result.bboxes) > 0
assert len(result.masks) > 0
assert len(result.confidences) > 0
assert len(result.bboxes) == len(result.masks) == len(result.confidences)
9 changes: 9 additions & 0 deletions tests/test_ultralytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ def test_ultralytics_hf_models(sample_image: Image.Image, model_name: str):
model_path = hf_hub_download("Bingsu/adetailer", model_name)
result = ultralytics_predict(model_path, sample_image)
assert result.preview is not None
assert len(result.bboxes) > 0
assert len(result.masks) > 0
assert len(result.confidences) > 0
assert len(result.bboxes) == len(result.masks) == len(result.confidences)


def test_yolo_world_default(sample_image: Image.Image):
model_path = hf_hub_download("Bingsu/yolo-world-mirror", "yolov8x-worldv2.pt")
result = ultralytics_predict(model_path, sample_image)
assert result.preview is not None
assert len(result.bboxes) > 0
assert len(result.masks) > 0
assert len(result.confidences) > 0
assert len(result.bboxes) == len(result.masks) == len(result.confidences)


@pytest.mark.parametrize(
Expand All @@ -51,3 +59,4 @@ def test_yolo_world(sample_image2: Image.Image, klass: str):
assert len(result.bboxes) > 0
assert len(result.masks) > 0
assert len(result.confidences) > 0
assert len(result.bboxes) == len(result.masks) == len(result.confidences)

0 comments on commit 7ae5d7a

Please sign in to comment.