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:
@@ -43,7 +43,10 @@ segmentation mask by default**, skipping the primary seg model entirely (one
|
||||
less model to load, ~20 s faster per image on CPU). Pilot-validated
|
||||
(TestImage3 / FixImage1): trimap 99.8% identical, no structural change to
|
||||
fingers, hair wisps or thin lines. Disable with `--no-cross-check-as-seg` to
|
||||
run the dedicated seg model instead.
|
||||
run the dedicated seg model instead. The reuse is a same-family swap, so it
|
||||
applies to the `birefnet` backend only: with `--seg-backend anime-seg` the
|
||||
anime segmenter keeps its own forward and the cross-check veto still runs
|
||||
independently on top.
|
||||
|
||||
The segmentation trimap defaults to `directional` mode (chroma + seg + a hue-direction
|
||||
split: it keeps a background-coloured garment such as a white shirt while dropping a
|
||||
|
||||
+10
-1
@@ -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)
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -72,6 +72,8 @@ cross_check:
|
||||
# drives both trimap topology and the veto, skipping the primary seg model
|
||||
# (saves its ~9s forward + ~0.9 GB load; CPU pipeline ~66s -> ~45s). Pilot:
|
||||
# trimap 99.8% identical, no structural change (fingers/wisps/bowstring OK).
|
||||
# Only applies to the birefnet backend (same-family swap); anime-seg keeps
|
||||
# its own forward, with the cross-check running independently on top.
|
||||
# Disable with --no-cross-check-as-seg. No effect when cross_check is off.
|
||||
reuse_as_seg: true
|
||||
# Cross-check forward precision, same semantics as segmentation.precision
|
||||
|
||||
Reference in New Issue
Block a user