mirror of
https://github.com/Bing-su/adetailer.git
synced 2026-01-26 19:29:54 +00:00
Merge branch 'dev'
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -7,11 +7,11 @@ from .ultralytics import ultralytics_predict
|
||||
ADETAILER = "ADetailer"
|
||||
|
||||
__all__ = [
|
||||
"__version__",
|
||||
"ADetailerArgs",
|
||||
"ADETAILER",
|
||||
"ALL_ARGS",
|
||||
"ADetailerArgs",
|
||||
"PredictOutput",
|
||||
"__version__",
|
||||
"get_models",
|
||||
"mediapipe_predict",
|
||||
"ultralytics_predict",
|
||||
|
||||
@@ -10,7 +10,7 @@ from typing import Any, Generic, Optional, TypeVar
|
||||
|
||||
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"
|
||||
|
||||
@@ -16,8 +16,8 @@ except ImportError:
|
||||
from .restore import CNHijackRestore, cn_allow_script_control
|
||||
|
||||
__all__ = [
|
||||
"ControlNetExt",
|
||||
"CNHijackRestore",
|
||||
"ControlNetExt",
|
||||
"cn_allow_script_control",
|
||||
"controlnet_exists",
|
||||
"controlnet_type",
|
||||
|
||||
18
install.py
18
install.py
@@ -8,12 +8,17 @@ from importlib.metadata import version # python >= 3.8
|
||||
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:
|
||||
@@ -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
|
||||
|
||||
@@ -44,7 +52,7 @@ 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),
|
||||
]
|
||||
@@ -52,7 +60,9 @@ def install():
|
||||
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}"
|
||||
|
||||
@@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, Any, NamedTuple, cast
|
||||
|
||||
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
|
||||
|
||||
@@ -15,7 +15,8 @@ from adetailer.mediapipe import mediapipe_predict
|
||||
)
|
||||
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)
|
||||
|
||||
@@ -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(
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user