Make cross-check and reuse-as-seg the service default

Cross-check + reuse-as-seg are already the config/CLI default; align the HTTP
service with them instead of forcing cross-check off. The earlier off-by-default
was to avoid the extra inference, but reuse-as-seg now makes that forward double
as the seg mask (birefnet backend) -- it replaces the primary seg model rather
than adding to it, so the cost concern is gone.

- app.py: honour the config default (on); BGFILTER_CROSS_CHECK still forces
  either way, unset = config.
- service.py preload: warm the cross-check HR-matting model, and skip the now-
  redundant primary segmenter when reuse covers segmentation.
- README / DEPLOY(_ZH): document cross-check as default-on, BiRefNet_HR-matting
  as required (not optional), BGFILTER_CROSS_CHECK=0 to disable.

Verified: service defaults cross_check on, env forces both ways, preload picks
cross-checker and skips the primary segmenter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-06 16:11:43 +08:00
parent c19a35de80
commit ad445611ad
5 changed files with 52 additions and 41 deletions
+8 -6
View File
@@ -62,12 +62,14 @@ def _build_settings():
if device:
# Covers both settings.model.device and settings.segmentation.device.
settings = override_settings(settings, device=device)
# The cross-model veto adds one extra large-model inference (~35 s/image on
# CPU), so the service defaults it OFF regardless of the config default;
# opt back in with BGFILTER_CROSS_CHECK=1. Other cross_check params (model,
# thresholds) still come from the config.
cross_check = os.environ.get("BGFILTER_CROSS_CHECK", "0").strip().lower() in ("1", "true", "yes", "on")
settings = override_settings(settings, cross_check=cross_check)
# The cross-model veto is default behaviour (config default: on). With
# reuse-as-seg it replaces the primary seg forward rather than adding to it,
# so the earlier CPU-cost concern no longer applies. BGFILTER_CROSS_CHECK
# can still force it either way; unset = honour the config.
cc_env = os.environ.get("BGFILTER_CROSS_CHECK")
if cc_env is not None and cc_env.strip() != "":
cross_check = cc_env.strip().lower() in ("1", "true", "yes", "on")
settings = override_settings(settings, cross_check=cross_check)
return settings