Default to BiRefNet + CPU; add --seg-backend to pick the segmenter

- Segmentation backend now defaults to birefnet (ZhengPeng7/BiRefNet); anime-seg is
  selected at runtime with --seg-backend anime-seg, which also swaps in the matching
  weights (unknown backends raise). Config files stay for detailed tuning, not
  backend selection.
- Default device is now cpu everywhere (dataclass defaults, default.yaml,
  birefnet.yaml); pass --device cuda for GPU. Avoids a hard CUDA-required failure on
  machines without a CUDA-enabled PyTorch build.
- Docs: README + workflow status note updated (backend via --seg-backend, CPU
  default, examples no longer force --device cuda).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-02 16:32:13 +08:00
parent 62f175948e
commit a6d84845c6
7 changed files with 32 additions and 20 deletions
+11
View File
@@ -17,6 +17,9 @@ from .settings import (
T = TypeVar("T")
# Canonical weights per segmentation backend (selected at runtime via --seg-backend).
_SEG_MODELS = {"birefnet": "ZhengPeng7/BiRefNet", "anime-seg": "skytnt/anime-seg"}
def _load_yaml(path: str | Path) -> dict[str, Any]:
try:
@@ -100,6 +103,14 @@ def override_settings(settings: PipelineSettings, **overrides: Any) -> PipelineS
seg_updates: dict[str, Any] = {}
if overrides.get("device") is not None:
seg_updates["device"] = overrides["device"]
if overrides.get("seg_backend") is not None:
backend = overrides["seg_backend"]
if backend not in _SEG_MODELS:
raise ValueError(
f"Unknown --seg-backend '{backend}'. Use one of: {', '.join(_SEG_MODELS)}."
)
seg_updates["backend"] = backend
seg_updates["model_name"] = _SEG_MODELS[backend]
screen_color = (
overrides["screen_color"]