Add anime-seg segmentation backend (SkyTNT ISNet)

Add AnimeSegSegmenter (skytnt/anime-seg ISNet ONNX via onnxruntime, no remote
code) and a make_segmenter factory selected by SegmentationSettings.backend
("birefnet" | "anime-seg"). The ONNX output is already 0..1, so it slots into the
same soft-mask interface BiRefNetSegmenter uses.

On the anime samples anime-seg recovers more and more-coherent hair wisps than
BiRefNet (TestImage2 shoulder rescue: added px 1886 -> 3278, largest connected
component 147 -> 454), as expected from an anime-trained model. Default backend
stays birefnet.

Adds onnxruntime to requirements.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-30 23:58:22 +08:00
parent 26b0bc8388
commit 08378e57f8
5 changed files with 53 additions and 2 deletions
+2 -2
View File
@@ -31,9 +31,9 @@ class MattingPipeline:
def _segment(self, rgb: np.ndarray) -> np.ndarray:
if self._segmenter is None:
from .segmentation import BiRefNetSegmenter
from .segmentation import make_segmenter
self._segmenter = BiRefNetSegmenter(self.settings.segmentation)
self._segmenter = make_segmenter(self.settings.segmentation)
return self._segmenter.mask(rgb)
def _predict_alpha(self, rgb: np.ndarray, trimap: np.ndarray, bg_confidence: np.ndarray) -> tuple[np.ndarray, str]: