Gate seg-reuse to the birefnet backend

reuse_as_seg swaps one BiRefNet-family model for another (the validated
equivalence); it must not silently override an explicitly chosen anime-seg
backend. With --seg-backend anime-seg the segmenter now keeps its own
forward and the cross-check veto runs independently on top -- both
combinable, no flag juggling. Default birefnet path is untouched
(verified byte-identical); anime-seg + cross-check verified to run both
models.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-06 15:52:21 +08:00
parent 10134ad492
commit 72655dea91
4 changed files with 19 additions and 3 deletions
+10 -1
View File
@@ -111,7 +111,16 @@ def _run_image(
)
second_alpha = None
if settings.segmentation.enabled:
if settings.cross_check.enabled and settings.cross_check.reuse_as_seg:
reuse = (
settings.cross_check.enabled
and settings.cross_check.reuse_as_seg
# Reuse swaps one BiRefNet-family model for another (validated
# equivalent topology). A different backend chosen explicitly
# (anime-seg) keeps its own forward; cross-check still runs
# independently on top of it.
and settings.segmentation.backend == "birefnet"
)
if reuse:
# One HR-matting forward serves both the trimap topology and the
# cross-check second opinion; the primary seg model is never loaded.
second_alpha = pipeline._second_opinion(rgb)
+3 -1
View File
@@ -78,7 +78,9 @@ class CrossCheckSettings:
# inference serves both trimap topology and the second opinion, skipping the
# primary seg model entirely (saves its load + forward). Pilot-validated on
# TestImage3/FixImage1: trimap 99.8% identical, no structural change. Only
# takes effect when both cross_check and segmentation are enabled.
# applies to the birefnet segmentation backend (a same-family swap); with
# anime-seg the chosen segmenter keeps its own forward and the cross-check
# runs independently. Needs cross_check and segmentation both enabled.
reuse_as_seg: bool = True
# Compute precision of the cross-check forward: "fp32" or "bf16" (autocast;
# needs bf16-capable hardware, else falls back to fp32 with a warning).