Implement BiRefNet and HAT Sharper models with background removal capabilities

- Added validation documentation for AI model tiers.
- Introduced `background.py` for background removal logic, including inference functions for alpha and foreground extraction.
- Created `onnx_birefnet.py` to handle BiRefNet model sessions and alpha inference.
- Developed tests for background models, ensuring proper dispatch and session reuse.
- Added tests for BiRefNet ONNX model to validate alpha output and error handling for invalid values.
- Implemented model export scripts for BiRefNet and HAT Sharper, ensuring proper weight compression and licensing.
- Created `deform_sampling.py` for deformable convolution operations used in BiRefNet.
- Added utility functions for compressing ONNX weights without altering graph arithmetic.
- Introduced a reference plane node for depth field adjustments in geometry processing.
This commit is contained in:
2026-09-10 20:50:44 +08:00
parent 8ae3c1d5b7
commit e8129fe495
70 changed files with 1890 additions and 1208 deletions

View File

@@ -3,18 +3,9 @@ import sys
import bpy
from .preferences import addon_preferences
from .runtime import runtime
from .server import model_catalog as shared_model_catalog
BEN2_MODEL_KEY = "BEN2_BASE"
REALESRGAN_GENERAL_WDN_MODEL_KEY = shared_model_catalog.DEFAULT_UPSCALE_MODEL_KEY
DEFAULT_MOGE2_MODEL_KEY = "MOGE2_VITS_NORMAL"
REQUIRED_MODEL_KEYS = (
DEFAULT_MOGE2_MODEL_KEY,
BEN2_MODEL_KEY,
REALESRGAN_GENERAL_WDN_MODEL_KEY,
)
DEVICE_LABELS = {
@@ -87,7 +78,7 @@ def ai_status():
environment_ready = runtime.environment_ready()
ready_models = {model["key"] for model in model_catalog() if model.get("ready")}
missing_models = tuple(
model_key for model_key in REQUIRED_MODEL_KEYS if model_key not in ready_models
model_key for model_key in shared_model_catalog.DEFAULT_MODEL_KEYS if model_key not in ready_models
)
return {
"environment_ready": environment_ready,
@@ -127,14 +118,15 @@ def model_record(model_key):
def _model_items(models):
numbers = {"MOGE2_VITS_NORMAL": 0, "MOGE2_VITB_NORMAL": 1, "MOGE3_VITL": 3}
return [
(
model["key"],
model["label"],
f"{model['description']}; license: {model['license']}",
index,
numbers[model["key"]],
)
for index, model in enumerate(models)
for model in models
]
@@ -143,18 +135,6 @@ def geometry_model_enum_items(_owner, _context):
return _model_items(models)
def configured_upscale_model(context=None):
preferences = addon_preferences(context)
model = getattr(
preferences,
"upscale_model",
shared_model_catalog.DEFAULT_UPSCALE_MODEL_KEY,
)
if model in shared_model_catalog.UPSCALE_MODELS:
return model
return shared_model_catalog.DEFAULT_UPSCALE_MODEL_KEY
def upscale_model_label(model_key):
model = shared_model_catalog.UPSCALE_MODELS.get(model_key)
return model.label if model is not None else model_key