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
+7 -8
View File
@@ -20,9 +20,9 @@ Two pipelines, selected by `segmentation.enabled` in the config:
Lightest / fastest; leans entirely on the colour key for topology.
- **Single segmenter** (`enabled: true`, default) — one segmentation model drives the
trimap topology (holes, hair), ViTMatte then refines the soft edges. Backend is
switchable: `anime-seg` (default, ONNX, for anime characters) or `birefnet` (general
salient objects — text, logos, photos; needs `trust_remote_code`). Use
`--config configs\birefnet.yaml` for the BiRefNet backend.
switchable: `birefnet` (default, general salient objects — text, logos, photos; needs
`trust_remote_code`) or `anime-seg` (ONNX, tuned for anime characters). Switch at
runtime with `--seg-backend anime-seg` (it also selects the matching weights).
Both share pymatting foreground estimation and a colour de-spill. There is **no**
green-contamination rescue / recolour layer — with clean source images it is
@@ -74,15 +74,15 @@ D:\MiniConda\envs\lightML\python.exe -m bgfilter.cli `
--input Samples\TestImage.png `
--output Outputs\TestImage_rgba.png `
--debug-dir Outputs\TestImage_debug `
--config configs\default.yaml `
--device cuda
--config configs\default.yaml
```
No `--screen-color` is needed — the background colour is auto-detected. Add
`--screen-color "#CFEFFF"` only to override it. The CLI reads `configs/default.yaml`
when `--config` is provided; command-line options override config values, so tuning
usually happens in YAML while runtime choices (`--device`, `--screen-color`,
`--trimap-mode`) stay on the command line.
`--trimap-mode`, `--seg-backend`) stay on the command line. The default device is
**CPU**; add `--device cuda` for GPU.
## Batch
@@ -91,8 +91,7 @@ D:\MiniConda\envs\lightML\python.exe -m bgfilter.cli `
--input-dir Samples `
--output-dir Outputs `
--debug-dir Outputs\debug `
--config configs\default.yaml `
--device cuda
--config configs\default.yaml
```
## Chroma-alpha debug mode