Align defaults with server-edition: reuse-as-seg and despill both OFF

Adopt server-edition's settings.py and default.yaml verbatim (zero diff on
these files between branches now):

- reuse_as_seg: false. The reuse equivalence holds for solid figures but
  breaks on thin pale strokes over a low-contrast background: HR-matting
  (trained on P3M-10k portraits + AM-2k animals) reads them as
  semi-transparent wisps, and as the trimap topology source it destroys
  white calligraphy (TestImage4: stroke alpha 0.92 -> 0.51, 48% of stroke
  pixels below 0.5) that the DIS5K-trained segmenter keeps solid (seg 0.97
  vs 0.40). As the gated cross-check veto the same signal stays harmless
  (hue gate excludes neutral strokes; confidence gate exempts soft edges).
  Opt in with --cross-check-as-seg for character batches.

- despill.enabled: false (mirrors server ba5d667): no positional/semantic
  guard, desaturates and hue-shifts subjects sharing the background's hue.

README updated accordingly; the performance table notes its numbers were
measured with reuse on.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-11 12:37:02 +08:00
parent 18c6918e45
commit f22af16517
4 changed files with 41 additions and 25 deletions
+13 -7
View File
@@ -84,12 +84,13 @@ class CrossCheckSettings:
input_size: int = 2048
# Reuse the cross-check forward as the segmentation mask: one HR-matting
# 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
# 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
# primary seg model entirely (saves its load + forward; measured ~20 s/image
# on CPU, ~0.9-1.3 GB VRAM on GPU). Pilot-validated on TestImage3/FixImage1:
# trimap 99.8% identical. Default OFF on server-edition: the dedicated
# segmenter keeps its own forward and the veto stays an independent signal;
# opt in with --cross-check-as-seg. Only applies to the birefnet backend
# (a same-family swap); needs cross_check and segmentation both enabled.
reuse_as_seg: bool = False
# Compute precision of the cross-check forward: "fp32" or "bf16" (autocast;
# needs bf16-capable hardware, else falls back to fp32 with a warning).
precision: str = "fp32"
@@ -121,7 +122,12 @@ class ForegroundSettings:
@dataclass(frozen=True)
class DespillSettings:
enabled: bool = True
# Off by default: despill pulls foreground chroma along the background-hue axis
# with no positional or semantic guard, so a subject sharing the background's hue
# (e.g. a blue suit on a blue backdrop) is desaturated/hue-shifted (~ΔE 35, blue
# -> purple). This is the root default the cpu-fast lane inherits. Re-enable
# per-config or with --despill only when edge spill genuinely matters.
enabled: bool = False
edge_low: float = 0.005
strength: float = 0.92
edge_expand_radius: int = 2