Add complex-background matting mode to the service via background_mode
Backports master's non-flat matting (chroma.enabled: false + the hue-free cross-check gate) into server-edition, and exposes it over HTTP without surfacing the internal "chroma" wording: /remove-background gains a background_mode form field (flat, default | complex). complex maps to chroma disabled -- no colour key, segmentation alone drives the trimap and every colour-keyed stage (auto-detect, hue split, chroma suppression, despill) is bypassed. The cross-check veto still works in complex mode via its second-opinion-confidence gate (cross_check.second_lo/hi) but defaults OFF there (it costs the HR-matting forward); an explicit cross_check=on re-enables it. No new model weights: complex mode reuses the already-provisioned BiRefNet seg + ViTMatte (+ optional HR-matting cross-check). Flat mode is unchanged (bit-identical), and server-edition's own extras (cross_check.lock, foreground.use_gpu CuPy path) are preserved -- the port is surgical, not a copy of master's files. - settings: ChromaSettings.enabled, CrossCheckSettings.second_lo/hi - config: override_settings chroma passthrough - despill/foreground: model=None safe guards (foreground keeps GPU path) - alpha_post: cross_check_alpha hue-free gate when proj is None - pipeline: _process_rgb complex branch (seg-only trimap, skip colour stages) - service/app: process(chroma=), background_mode field, complex-defaults-off cross-check, X-BGFilter-Background-Mode header - cli: --chroma/--no-chroma - configs/docs: gpu.yaml + default.yaml + README/README_ZH Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+12
-3
@@ -187,9 +187,10 @@ python -m uvicorn app:app --host 127.0.0.1 --port 18083 --workers 1
|
||||
| 字段 | 必填 | 取值 | 含义 |
|
||||
| --- | --- | --- | --- |
|
||||
| `file` | 是 | 图片文件 | 源图(字段名固定为 `file`)。 |
|
||||
| `screen_color` | 否 | `#RRGGBB`,或留空/`auto` | 背景色先验;留空则从边框自动探测。 |
|
||||
| `background_mode` | 否 | `flat`(默认)/ `complex` | `flat` = 纯色背景(走色键管线)。`complex` = 非纯色/实景背景:无色键,完全由分割器驱动抠图;此模式下 `screen_color` 被忽略,发丝细节通常弱于纯色模式。 |
|
||||
| `screen_color` | 否 | `#RRGGBB`,或留空/`auto` | 背景色先验;留空则从边框自动探测。`background_mode=complex` 时忽略。 |
|
||||
| `seg_model` | 否 | `birefnet`(默认)/ `anime-seg` | 分割后端。 |
|
||||
| `cross_check` | 否 | `1`/`0`(也接受 `true`/`false`/`yes`/`no`/`on`/`off`) | 按请求覆盖交叉否决;留空 = 服务端默认。 |
|
||||
| `cross_check` | 否 | `1`/`0`(也接受 `true`/`false`/`yes`/`no`/`on`/`off`) | 按请求覆盖交叉否决;留空在 `flat` 模式 = 服务端默认,但在 `complex` 模式**默认关闭**(传 `on` 启用其无色相门控)。 |
|
||||
|
||||
### 响应头(`200` 时)
|
||||
|
||||
@@ -199,13 +200,14 @@ python -m uvicorn app:app --host 127.0.0.1 --port 18083 --workers 1
|
||||
| `X-BGFilter-Seg-Model` | `birefnet` | 实际使用的分割器。 |
|
||||
| `X-BGFilter-Screen-Color` | `#CFEFFF` / `auto` | 实际使用的背景色。 |
|
||||
| `X-BGFilter-Cross-Check` | `on` / `off` | 本次实际的 cross-check 状态。 |
|
||||
| `X-BGFilter-Background-Mode` | `flat` / `complex` | 本次实际的背景模式。 |
|
||||
|
||||
### 状态码
|
||||
|
||||
| 码 | 何时 |
|
||||
| --- | --- |
|
||||
| `200` | 成功——响应体是 RGBA PNG。 |
|
||||
| `400` | 输入有误:图片无法解码,`screen_color`/`seg_model`/`cross_check` 非法,或自动探测失败(请传 `screen_color`)。 |
|
||||
| `400` | 输入有误:图片无法解码,`screen_color`/`seg_model`/`cross_check`/`background_mode` 非法,或自动探测失败(请传 `screen_color`)。 |
|
||||
| `401` | 鉴权已开且 token 缺失或错误。 |
|
||||
| `413` | 图片超过 `BGFILTER_MAX_IMAGE_PIXELS`(默认约 4 MP)。 |
|
||||
| `500` | 推理失败。 |
|
||||
@@ -226,6 +228,13 @@ curl -sS \
|
||||
-F "seg_model=anime-seg" \
|
||||
-F "cross_check=off" \
|
||||
http://127.0.0.1:18083/remove-background -o output.png
|
||||
|
||||
# 非纯色/实景背景(无色键);此模式 cross-check 默认关闭,
|
||||
# 需要时加 cross_check=on 启用无色相残留否决
|
||||
curl -sS \
|
||||
-F "file=@scene.jpg" \
|
||||
-F "background_mode=complex" \
|
||||
http://127.0.0.1:18083/remove-background -o output.png
|
||||
```
|
||||
|
||||
配置来自 `BGFILTER_CONFIG`(存在时默认 `configs/default.yaml`);`BGFILTER_DEVICE` 同时
|
||||
|
||||
Reference in New Issue
Block a user