---
title: "rembg Ecosystem Deep-Dive: Models, APIs, Deployments, and Alternatives"
category: "16-background-removal-vectorization"
angle: "16a"
subagent: "16a"
status: "draft"
audience: ["skill-authors", "pipeline-engineers", "prompt-to-asset-backend"]
primary_repo: "https://github.com/danielgatis/rembg"
stars: "22k+"
license: "MIT"
tags:
  - background-removal
  - matting
  - rembg
  - birefnet
  - u2net
  - isnet
  - inspyrenet
  - onnxruntime
  - asset-pipeline
last_verified: "2026-04-19"
word_count_target: "2500-4000"
---

# 16a — rembg Ecosystem Deep-Dive

## Executive Summary

`rembg` ([danielgatis/rembg](https://github.com/danielgatis/rembg), MIT, **~22.6k stars** as of April 2026) is the de-facto open-source swiss-army knife for alpha-matte background removal. It is not a single model — it is a thin, cache-friendly runtime layer around ~15 ONNX models shipped via GitHub Releases, exposing four surfaces: a **CLI** (`rembg i|p|s|b`), a **Python library**, an **HTTP server** with Gradio UI, and an official **Docker image** (`danielgatis/rembg`).

For the `prompt-to-asset` project, `rembg` is the most important post-processing hook in the asset pipeline, because every category-13 "transparent background" asset produced by Gemini, DALL·E, or an SD pipeline that writes opaque RGB must have its background stripped *deterministically* before it is handed to the user. The generator's job ends at "a logo on a clean background"; `rembg`'s job is to convert that into RGBA with clean edges.

Three findings dominate:

1. **Model choice beats model tuning.** The catalog spans tiny CPU-friendly nets (`u2netp`, 4.7 MB) all the way to BiRefNet-general (~880 MB). Picking the wrong one costs 10× inference time or 30% mask quality. An automated model picker driven by the asset category (logo vs. product vs. portrait vs. anime) is high-leverage.
2. **rembg is a runtime, not a model.** It's a 22k-star repo precisely because it standardizes `onnxruntime` + HuggingFace-style auto-download + alpha-matting post-processing across a zoo of incompatible research checkpoints. Competing packages (`transparent-background`, `backgroundremover`) are faster *per image* in some regimes, but none has the breadth of model catalog, deployment targets, or community reach.
3. **The last 5% of edge quality is not a model problem.** Halos, semi-transparent hair, and glass edges are solved by **alpha-matting / trimap refinement** (pymatting) and **color decontamination**, not by upgrading models. Shipping a pipeline without a post-processing pass leaves visible "white glow" artifacts on dark product imagery.

## Installation Friction & Runtime Matrix

rembg targets **Python 3.11–3.13**. Installation split in 2024 into three extras corresponding to the `onnxruntime` wheel:

| Extra | onnxruntime package | Typical hardware |
|---|---|---|
| `rembg[cpu]` | `onnxruntime` | macOS/Linux/Windows CPU |
| `rembg[gpu]` | `onnxruntime-gpu` | NVIDIA CUDA + cuDNN |
| `rembg[rocm]` | `onnxruntime-rocm` | AMD ROCm |

CLI support is an extra flag: `pip install "rembg[cpu,cli]"`.

**Known install gotchas:**

- **CUDA setup is fragile.** GitHub issue [#668](https://github.com/danielgatis/rembg/issues/668) is the canonical "cuDNN 9 / CUDA 12 / `onnxruntime-gpu 1.19+`" quicksand. The project's own note: *"If `rembg[gpu]` doesn't work and you can't install CUDA or cudnn-devel, use `rembg[cpu]`."*
- **Apple Silicon has no first-class acceleration.** See issues [#487](https://github.com/danielgatis/rembg/issues/487) and [#556](https://github.com/danielgatis/rembg/issues/556). Workaround: replace `onnxruntime` with [`onnxruntime-silicon`](https://github.com/cansik/onnxruntime-silicon) which bundles the **CoreML Execution Provider**, letting ONNX dispatch to Neural Engine / GPU. A patched install guide exists as a [gist](https://gist.github.com/fathonix/3b9bda262226ac8842338d65ae505673).
- **Windows DirectML** works by replacing `onnxruntime` with `onnxruntime-directml`; this is how some Stable Diffusion UIs ship rembg on AMD Windows.
- **Model auto-download.** First-use triggers a ~170 MB download (for `u2net.onnx`) from the rembg GitHub Release tag `v0.0.0` into `~/.u2net/`. In sandboxed or offline environments, bake these into the Docker image or pre-seed the volume. Override with `U2NET_HOME`, disable checksum with `MODEL_CHECKSUM_DISABLED=1` for custom ONNX files.

**Docker images.**

- CPU: `docker run -v .:/data danielgatis/rembg i /data/in.png /data/out.png` (~1.6 GB).
- NVIDIA: must build locally from `Dockerfile_nvidia_cuda_cudnn_gpu` (~11 GB, cuDNN is non-redistributable).
- Best practice: mount a host models dir: `-v /path/to/models/:/root/.u2net` to avoid re-downloads on every `docker run`.

## Model Catalog (As of April 2026)

All models are ONNX files distributed from [the `v0.0.0` release](https://github.com/danielgatis/rembg/releases/tag/v0.0.0). Source checkpoints are third-party academic releases converted to ONNX.

| Model key | Size | Source | Best for |
|---|---|---|---|
| `u2net` | 176 MB | [xuebinqin/U-2-Net](https://github.com/xuebinqin/U-2-Net) | General fallback, illustrations |
| `u2netp` | 4.7 MB | U-2-Net | Mobile / tight latency budgets |
| `u2net_human_seg` | 176 MB | U-2-Net | Full-body human silhouettes |
| `u2net_cloth_seg` | 176 MB | [levindabhi/cloth-segmentation](https://github.com/levindabhi/cloth-segmentation) | Garment parsing (3 classes) |
| `silueta` | 43 MB | U-2-Net [issue #295](https://github.com/xuebinqin/U-2-Net/issues/295) | Near-`u2net` quality, 4× smaller |
| `isnet-general-use` | 179 MB | [xuebinqin/DIS](https://github.com/xuebinqin/DIS) | **Product shots, e-comm, logos on busy bg** |
| `isnet-anime` | 176 MB | [SkyTNT/anime-segmentation](https://github.com/SkyTNT/anime-segmentation) | Anime/illustration characters |
| `sam` (ViT-B) | ~375 MB enc+dec | [facebookresearch/segment-anything](https://github.com/facebookresearch/segment-anything) | Interactive point/box-driven masks |
| `birefnet-general` | ~880 MB | [ZhengPeng7/BiRefNet](https://github.com/ZhengPeng7/BiRefNet) | **SOTA general-purpose, hair/fur** |
| `birefnet-general-lite` | ~180 MB | BiRefNet (Swin-tiny) | 5× faster than full BiRefNet, 90% quality |
| `birefnet-portrait` | ~880 MB | BiRefNet | Headshots, portraits |
| `birefnet-dis` | ~880 MB | BiRefNet | Dichotomous segmentation (competition checkpoint) |
| `birefnet-hrsod` | ~880 MB | BiRefNet | **High-res salient object** (large product stills) |
| `birefnet-cod` | ~880 MB | BiRefNet | Camouflaged object detection (rare) |
| `birefnet-massive` | ~880 MB | BiRefNet | Trained on DIS5K+more, most robust |
| `birefnet-hr` | ~880 MB | BiRefNet (HR checkpoint) | **High-res 2048² training; best hair detail** |
| `birefnet-dynamic` | ~880 MB | BiRefNet (dynamic) | **Dynamic-resolution 256–2304px training; robust on any res** |
| `bria-rmbg` | ~175 MB | [briaai/RMBG-2.0](https://huggingface.co/briaai/RMBG-2.0) | **Commercial-grade quality, CC license caveat** |

> **Updated 2026-04-21:** BiRefNet released two significant new checkpoints in early 2025: **BiRefNet_HR** (February 2025, trained at 2048×2048, best hair/fine-detail accuracy) and **BiRefNet_dynamic** (March 2025, dynamic resolution 256–2304 px, most robust across arbitrary resolutions). A third specialty variant, **BiRefNet_HR-matting**, was also released February 2025 specifically for general matting use at 2K resolution. Rembg issue [#720](https://github.com/danielgatis/rembg/issues/720) tracks integration of these checkpoints into rembg's catalog — verify current support before depending on them via `new_session("birefnet-hr")`. The BiRefNet September 2025 update also upgraded Swin Transformer attention to PyTorch's official SDPA, yielding lower memory cost and potential inference acceleration.

**License note:** `bria-rmbg` weights are released by BRIA AI under a [non-commercial license unless you pay BRIA](https://huggingface.co/briaai/RMBG-2.0). rembg ships the loader, not the license. For any hosted generation backend, default to `isnet-general-use` (Apache-like DIS license) or `birefnet-general` (MIT) for clean legal posture.

## Model Picker Decision Tree

Logic to drive asset-category → model selection in the prompt-to-asset pipeline:

```text
asset_type == "logo" or "app_icon" or "favicon":
    → birefnet-general-lite        # flat, high-contrast, speed matters
    (fallback: isnet-general-use)

asset_type == "product_shot" (e-commerce, packaging):
    if needs_hair_fur_or_glass:
        → birefnet-general         # or birefnet-massive
    else:
        → isnet-general-use

asset_type == "portrait" / "headshot":
    → birefnet-portrait
    (fallback: u2net_human_seg)

asset_type == "illustration" (flat vector-ish, cartoon):
    → u2net                        # fewer hallucinated edges than isnet
    (fallback: birefnet-general-lite)

asset_type == "anime" / "manga":
    → isnet-anime

asset_type == "hero_image" / "marketing_banner":
    → birefnet-hrsod               # >= 2048px recommended

asset_type == "interactive_crop" (user clicks on object):
    → sam                          # with sam_prompt point/box
```

For the `prompt-to-asset` skills runtime, expose this as a single function:

```python
def pick_model(asset_type: str, *, hires: bool = False, hair: bool = False) -> str:
    if asset_type in {"logo", "icon", "favicon"}:
        return "birefnet-general-lite"
    if asset_type == "product":
        return "birefnet-general" if hair else "isnet-general-use"
    if asset_type == "portrait":
        return "birefnet-portrait"
    if asset_type == "anime":
        return "isnet-anime"
    if asset_type == "illustration":
        return "u2net"
    if hires:
        return "birefnet-hrsod"
    return "isnet-general-use"
```

## Performance Benchmarks

Publicly reported numbers (a 500-image product benchmark reported on [dev.to](https://dev.to/om_prakash_3311f8a4576605/birefnet-vs-rembg-vs-u2net-which-background-removal-model-actually-works-in-production-4830) and corroborated by [Civitai discussion](https://civitai.com/articles/12331/finding-the-best-background-removal-models)):

| Model | Hair acc. | Glass/transparent | Avg inference (GPU) | Overall quality |
|---|---|---|---|---|
| `u2net` | 71% | 48% | 0.8 s | Acceptable |
| `rembg / isnet-general-use` | 81% | 59% | 1.1 s | Good |
| `birefnet-general` | 94% | 78% | 1.4 s | Excellent |

**Apple Silicon (M1/M2/M3), CPU-only rembg, 1024×1024 input, approximate wall-clock:**

| Model | CPU (cold) | CPU (warm, reused session) |
|---|---|---|
| `u2netp` | ~2.0 s | ~0.6 s |
| `silueta` | ~3.5 s | ~1.2 s |
| `u2net` / `isnet-general-use` | ~8–10 s | ~3–4 s |
| `birefnet-general-lite` | ~6 s | ~2.5 s |
| `birefnet-general` | ~30 s+ | ~12 s |

With `onnxruntime-silicon` + CoreML EP, expect 2–4× speedups on `u2net`-class models; BiRefNet full variants are frequently **slower** on CoreML than CPU because some ops fall back to CPU anyway (see cansik/onnxruntime-silicon [issue #17](https://github.com/cansik/onnxruntime-silicon/issues/17)).

**Session reuse is the single biggest free win.** `new_session()` once, then pass `session=` into every `remove()` call. For HTTP server mode, sessions are cached per-model already. For batch workloads, use `rembg p` (folder) not a loop of `rembg i` calls — the latter re-inits ORT for every image.

## Integration Recipes

### CLI

Basic single file:

```bash
rembg i in.png out.png
```

Pick model + alpha matting for hair:

```bash
rembg i \
  -m birefnet-general \
  -a \
  -ae 15 \
  in.jpg out.png
```

Return only the mask (useful for vectorization pipeline):

```bash
rembg i -m isnet-general-use -om product.jpg mask.png
```

Batch folder:

```bash
rembg p -m birefnet-general-lite ./inputs ./outputs
```

Watch mode (processes new files as they drop in — ideal for a generation pipeline writing to a shared folder):

```bash
rembg p -w -m isnet-general-use ./inbox ./ready
```

SAM with a point prompt (pick a single object):

```bash
rembg i -m sam \
  -x '{"sam_prompt":[{"type":"point","data":[512,512],"label":1}]}' \
  photo.png out.png
```

Video pipeline with FFmpeg:

```bash
ffmpeg -i clip.mp4 -ss 10 -an -f rawvideo -pix_fmt rgb24 pipe:1 \
  | rembg b 1280 720 -o frames/frame-%04u.png
```

### Python

Minimal use, single call:

```python
from rembg import remove
from PIL import Image

img = Image.open("logo_on_white.png")
rgba = remove(img, post_process_mask=True)
rgba.save("logo_transparent.png")
```

Production pattern for the prompt-to-asset backend — one session per worker, alpha-matted for fine edges:

```python
from rembg import new_session, remove
from PIL import Image

SESSION = new_session(model_name="birefnet-general-lite")

def strip_bg(pil_img: Image.Image) -> Image.Image:
    return remove(
        pil_img,
        session=SESSION,
        alpha_matting=True,
        alpha_matting_foreground_threshold=240,
        alpha_matting_background_threshold=10,
        alpha_matting_erode_size=3,
        post_process_mask=True,
    )
```

Only the mask (for downstream vectorizer like `potrace`/`vtracer`):

```python
rgba = remove(pil_img, session=SESSION, only_mask=True)
```

Custom model path (bring-your-own ONNX) with checksum bypass:

```bash
export MODEL_CHECKSUM_DISABLED=1
```

```python
session = new_session(
    "u2net_custom",
    providers=["CoreMLExecutionProvider", "CPUExecutionProvider"],
)
# rembg will pass providers through to onnxruntime.InferenceSession
```

### Node.js / JavaScript

Three viable options, each with trade-offs:

1. **[`@tugrul/rembg`](https://www.npmjs.com/package/@tugrul/rembg)** (Nov 2025+) — native `onnxruntime-node` + `sharp`, supports BiRefNet + U2Net. No Python dependency. Preferred for greenfield Node backends.
2. **[`rembg-node`](https://github.com/makidoll/rembg-node)** — U2-Net only, unmaintained; the author's own README says "results are often not great". Avoid for new projects.
3. **[`litepacks/node-rembg`](https://github.com/litepacks/node-rembg)** — thin CLI wrapper that `spawn()`s the Python `rembg`. Fine if you already ship Python in your container.
4. **[Remove-Background-ai/rembg.js](https://github.com/Remove-Background-ai)** — TypeScript library, ~42 stars, smaller community, check activity before depending on it.

Recommended pattern for the prompt-to-asset website (Next.js backend):

```ts
import { Rembg } from "@tugrul/rembg";
import sharp from "sharp";

const remover = new Rembg({ model: "birefnet-general-lite" });
const buffer = await sharp(inputPath).toBuffer();
const rgba = await remover.process(buffer);
await sharp(rgba).png().toFile(outputPath);
```

### HTTP Server

The production-recommended way to expose rembg to a hosted generation backend. Launch:

```bash
rembg s --host 0.0.0.0 --port 7000 --log_level info --no-ui
```

The `--no-ui` flag disables the Gradio dashboard and measurably reduces idle CPU. Documentation auto-serves at `http://host:7000/api`.

Consume from any HTTP client — URL or multipart upload:

```bash
# by URL (rembg fetches for you)
curl "http://rembg:7000/api/remove?url=https://cdn.example.com/in.png&model=birefnet-general" -o out.png

# by upload
curl -F "file=@in.png" -F "model=isnet-general-use" \
  "http://rembg:7000/api/remove?a=true" -o out.png
```

Key query params the HTTP endpoint accepts (mirrors the CLI):

- `model` (e.g. `isnet-general-use`)
- `a` (bool) enable alpha matting
- `af`, `ab`, `ae` — foreground/background/erode thresholds
- `om` (bool) only-mask
- `ppm` (bool) post-process mask
- `bgc` (comma-separated ints) background color fill

**Docker-compose snippet** for the prompt-to-asset infra:

```yaml
services:
  rembg:
    image: danielgatis/rembg:latest
    command: s --host 0.0.0.0 --port 7000 --no-ui
    volumes:
      - rembg-models:/root/.u2net
    restart: unless-stopped
    ports:
      - "7000:7000"
volumes:
  rembg-models:
```

For horizontal scaling, stand up one replica per model family (rembg keeps all sessions in-process, so a single instance loading 3 BiRefNet variants can push 3 GB of RAM).

## Alternatives in the Neighborhood

### `transparent-background` (InSPyReNet)

- Repo: [plemeri/transparent-background](https://github.com/plemeri/transparent-background), 1.2k+ stars, MIT.
- Paper: [Kim et al., ACCV 2022 — *Revisiting Image Pyramid Structure for High Resolution Salient Object Detection*](https://openaccess.thecvf.com/content/ACCV2022/papers/Kim_Revisiting_Image_Pyramid_Structure_for_High_Resolution_Salient_Object_Detection_ACCV_2022_paper.pdf).
- Typical claim: **faster and sharper edges than rembg/u2net on large images** in `--mode fast` or with `--resize dynamic`. On small images without `--fast`, known to underperform.
- Python API:

  ```python
  from transparent_background import Remover
  from PIL import Image
  remover = Remover(mode="base", device="cuda:0")
  out = remover.process(Image.open("in.jpg"), type="rgba")
  out.save("out.png")
  ```

- Notable features vs. rembg: first-class **video** loop, webcam + virtual-cam (Linux/Windows/mac via OBS), built-in `blur`/`overlay`/color-replace types, GUI (`transparent-background-gui`), and GPU-accelerated foreground estimation via `pymatting` + CuPy.
- Weakness: single model family; no SAM, no anime-specialized checkpoint.
- Good pairing with rembg: use `transparent-background` for video, rembg for single images + the BiRefNet catalog.

### `backgroundremover` (nadermx)

- Repo: [nadermx/backgroundremover](https://github.com/nadermx/backgroundremover), ~7.8k stars, MIT.
- Runtime: PyTorch-based (not ONNX). Models: U2Netp, U2Net, and a U2Net_human_seg variant.
- Strengths: **video with `-tv`, matte-key output, `pytorch` flexibility**, simpler install on macOS than CUDA-rembg.
- Weakness: **no BiRefNet, no ISNet**, slower per image than rembg on the same model, less active development cadence.
- Use when: you already ship Torch, you need video with per-frame mattes, or you hit CUDA cuDNN hell with `onnxruntime-gpu`.

### BRIA RMBG-2.0 direct

- Model: [briaai/RMBG-2.0](https://huggingface.co/briaai/RMBG-2.0).
- License: **CC BY-NC 4.0** — non-commercial only unless you purchase a commercial license from BRIA. Weights are on a gated Hugging Face repo; you must accept the license terms to download. Superb quality, SOTA-class, but not safe to ship to end-users without a BRIA agreement.
- Usable via `rembg -m bria-rmbg` under the same legal constraint.

### BEN2 (Background Erase Network 2)

> **Updated 2026-04-21:** A notable new entrant since the original research. **BEN2** ([PramaLLC/BEN2](https://huggingface.co/PramaLLC/BEN2)) introduces a **Confidence Guided Matting (CGM)** pipeline: a base segmenter runs first, then a dedicated refiner network targets low-confidence boundary pixels — the exact failure zone of BiRefNet and BRIA on hair and fur. BEN2 claims to outperform BiRefNet-HR on the DIS5k + a 22K proprietary dataset, and is specifically noted for hair matting, 4K processing, and edge refinement. The base model is open source (Apache 2.0); the full API is commercial. Not yet integrated into rembg as of April 2026, but available via the web demo and fal.ai endpoint. Worth tracking as a BiRefNet-HR competitor for the 5% tail of hard hair/fur cases.

### InSPyReNet direct, DIS direct, BiRefNet direct

If you need custom training data or a specialized domain checkpoint, the *source* repos ([InSPyReNet](https://github.com/plemeri/InSPyReNet), [DIS](https://github.com/xuebinqin/DIS), [BiRefNet](https://github.com/ZhengPeng7/BiRefNet)) all provide training code. For the prompt-to-asset project this is out of scope — we consume, not train.

## Known Failures + Mitigations

### 1. White/colored halo around subject

**Cause:** premultiplied alpha with background color baked into the semi-opaque edge pixels; model output mask boundary doesn't align with true object edge ([mike-wiki overview](https://mike-wiki.win/index.php/Why_That_White_Glow_Appears_When_You_Remove_Backgrounds_-_and_How_to_Stop_It)).

**Mitigations:**

- Enable `alpha_matting=True` (`-a` on CLI).
- Tune `alpha_matting_erode_size` (`-ae`) between 3 and 15. Smaller = tighter, more likely to clip; larger = smoother but can swallow thin features.
- For deep-background subjects: after rembg, run a **color decontamination / defringe** pass — contract the alpha by 1–2 px (`PIL.ImageFilter.MinFilter(3)` on alpha channel) and recompute edge pixel colors from the unpremultiplied RGB using [`pymatting.estimate_foreground_ml`](https://pymatting.github.io/foreground.html).
- If shipping a full pipeline, use `transparent-background`'s `type="rgba"` which runs `estimate_foreground_ml` by default on the alpha output.

### 2. Semi-transparent hair / fur wiped to binary

**Cause:** `u2net`/`isnet` output is effectively binary; thin strands are either killed or fringed.

**Mitigations:**

- Switch model: `birefnet-general`, `birefnet-massive`, or `birefnet-portrait`.
- Enable alpha matting with "hair-tuned" triplet: `-af 240 -ab 10 -ae 3` (community-proven recipe from rembg [issue #33](https://github.com/danielgatis/rembg/issues/33)).
- Post-process with pymatting's `estimate_alpha_cf` + `estimate_foreground_ml` for true soft matte; this is the *only* reliable way to get wispy hair that composites cleanly onto arbitrary backgrounds.

### 3. Glass / transparent products

**Cause:** matting models trained on "object vs. background" assume the object is opaque. Transparent objects score ~48% (u2net) to ~78% (BiRefNet) in the 2025 benchmark.

**Mitigations:**

- Use `birefnet-general` or `birefnet-massive`; nothing else is competitive.
- If the asset is generated (not photographed), prompt the upstream T2I model to put the subject on a **solid color** that does not appear in the object (e.g. chartreuse for amber glass) — then rembg's job becomes trivial and you can skip alpha matting entirely.
- For stubborn cases, manual SAM point-prompts (`rembg i -m sam -x '{"sam_prompt": ...}'`) let a human (or a VLM like Gemini Vision) place a single click that disambiguates figure from ground.

### 4. "Trimap did not contain foreground values"

**Cause:** mask is too empty; `-af` threshold is higher than any pixel's confidence. Documented in rembg [issue #116](https://github.com/danielgatis/rembg/issues/116).

**Mitigation:** lower `-af` to 200 or 180, or disable alpha matting entirely on low-confidence masks. In Python, wrap `remove(..., alpha_matting=True)` in a try/except and fall back to `alpha_matting=False`.

### 5. Model auto-download failures in sandboxed/offline deploys

**Cause:** first-use downloads from GitHub Releases; blocked in corporate networks, airgapped containers, Lambda cold starts.

**Mitigation:**

- Pre-bake the `~/.u2net/` dir into the Docker image.
- Mount a shared volume across replicas.
- Use `U2NET_HOME=/opt/models` for predictable paths.
- For custom builds, set `MODEL_CHECKSUM_DISABLED=1`.

### 6. Apple Silicon slowness

**Cause:** plain `onnxruntime` on ARM64 macOS uses CPU EP only.

**Mitigation:** `pip install onnxruntime-silicon` (replaces onnxruntime), then set providers explicitly:

```python
session = new_session(
    "isnet-general-use",
    providers=["CoreMLExecutionProvider", "CPUExecutionProvider"],
)
```

Verify dispatch with `ort.get_available_providers()`. Expect 2–4× speedup on U2Net-class models; BiRefNet gains are marginal because of unsupported ops.

### 7. CUDA/cuDNN version hell

**Cause:** `onnxruntime-gpu 1.19+` requires cuDNN 9 + CUDA 12; older drivers silently fall back to CPU.

**Mitigation:** pin `onnxruntime-gpu==1.18.0` for CUDA 11.8 stacks. Or use the official Docker image built from `Dockerfile_nvidia_cuda_cudnn_gpu`.

## Alpha Post-Processing Cookbook

For the prompt-to-asset post-generation pipeline, do not ship raw rembg output. Always run this chain:

1. **Remove** with the best model for the asset category (see decision tree).
2. **Refine mask** with `post_process_mask=True` (fixes small holes & islands via morphological ops).
3. **Alpha-matte** with hair-tuned thresholds on portraits / furry subjects.
4. **Decontaminate** edges: pull edge pixel colors inward using `pymatting.estimate_foreground_ml` or a simple 1-px alpha erode.
5. **Feather** if target is a softly-lit composite (Gaussian 1–2 px on alpha only).
6. **Snap tiny alphas**: set `alpha < 8/255 → 0` to kill spurious semi-transparent noise in nominally empty regions.
7. **Trim canvas**: after alpha-matte, crop to non-transparent bbox with 2-px padding.

Pseudocode, drop-in:

```python
import numpy as np
from PIL import Image
from pymatting import estimate_foreground_ml

def finalize(rgba: Image.Image) -> Image.Image:
    arr = np.asarray(rgba).astype(np.float32) / 255.0
    rgb, alpha = arr[..., :3], arr[..., 3]
    alpha[alpha < 8 / 255] = 0
    rgb = estimate_foreground_ml(rgb, alpha)
    out = np.concatenate([rgb, alpha[..., None]], axis=-1)
    img = Image.fromarray(np.clip(out * 255, 0, 255).astype(np.uint8), "RGBA")
    return img.crop(img.getbbox())
```

## Integration Notes for `prompt-to-asset`

1. **Default model**: `isnet-general-use` for speed, `birefnet-general-lite` for quality-default. Expose as a `quality: "fast" | "balanced" | "best"` knob in the skill.
2. **Deploy as long-running HTTP service** (`rembg s --no-ui`) behind the asset generation API — avoids per-request ORT init (~1–3 s cold).
3. **Session keyed by model name.** Maintain a tiny LRU of `new_session(model)` in the backend; don't tear down between requests.
4. **Never expose `bria-rmbg` to the public endpoint** unless a BRIA commercial license is secured.
5. **Pair with vectorization.** For logo/icon asset types, chain `rembg -om` (mask only) → `potrace` / `vtracer` → SVG. See sibling angle 16b on vectorizers.
6. **Watchdog**: set a hard 30 s per-image timeout; BiRefNet on CPU can OOM on 4k images.
7. **Record metadata.** Log `{model, alpha_matting, elapsed_ms, bbox_area_ratio}` per call so the evaluation skill (category 03) can build a feedback loop on mask quality.

## References

### Primary repos & docs

- danielgatis, *rembg*, GitHub. <https://github.com/danielgatis/rembg>
- rembg README (current): <https://raw.githubusercontent.com/danielgatis/rembg/main/README.md>
- rembg USAGE examples: <https://github.com/danielgatis/rembg/blob/main/USAGE.md>
- rembg `bg.py` (alpha-matting implementation): <https://github.com/danielgatis/rembg/blob/main/rembg/bg.py>
- plemeri, *transparent-background*: <https://github.com/plemeri/transparent-background>
- plemeri, *InSPyReNet* (training source): <https://github.com/plemeri/InSPyReNet>
- nadermx, *backgroundremover*: <https://github.com/nadermx/backgroundremover>
- xuebinqin, *U-2-Net*: <https://github.com/xuebinqin/U-2-Net>
- xuebinqin, *DIS* (ISNet): <https://github.com/xuebinqin/DIS>
- ZhengPeng7, *BiRefNet*: <https://github.com/ZhengPeng7/BiRefNet>
- facebookresearch, *segment-anything*: <https://github.com/facebookresearch/segment-anything>
- SkyTNT, *anime-segmentation*: <https://github.com/SkyTNT/anime-segmentation>
- briaai, *RMBG-2.0* on HuggingFace: <https://huggingface.co/briaai/RMBG-2.0>

### Ecosystem wrappers

- `@tugrul/rembg` (npm): <https://www.npmjs.com/package/@tugrul/rembg>
- `rembg-node` (npm): <https://www.npmjs.com/package/rembg-node>
- `litepacks/node-rembg`: <https://github.com/litepacks/node-rembg>
- Remove-Background-ai `rembg.js`: <https://github.com/Remove-Background-ai>
- ComfyUI-Inspyrenet-Rembg: <https://github.com/john-mnz/ComfyUI-Inspyrenet-Rembg>

### Runtime acceleration

- ONNX Runtime install matrix: <https://onnxruntime.ai/getting-started>
- cansik, *onnxruntime-silicon*: <https://github.com/cansik/onnxruntime-silicon>
- ONNX Runtime CoreML EP docs: <https://onnxruntime.ai/docs/execution-providers/CoreML-ExecutionProvider.html>
- pymatting: <https://pymatting.github.io>
- Germer et al., 2020, *Multi-level closed-form foreground estimation*: <https://arxiv.org/abs/2006.14970>

### Issues & community sources

- rembg #33 — alpha matting parameters: <https://github.com/danielgatis/rembg/issues/33>
- rembg #76 — alpha matting in Python: <https://github.com/danielgatis/rembg/issues/76>
- rembg #116 — "Trimap did not contain foreground values": <https://github.com/danielgatis/rembg/issues/116>
- rembg #487 — onnxruntime-silicon inquiry: <https://github.com/danielgatis/rembg/issues/487>
- rembg #556 — Apple Silicon/MPS feature request: <https://github.com/danielgatis/rembg/issues/556>
- rembg #668 — CUDA/cuDNN install help: <https://github.com/danielgatis/rembg/issues/668>
- onnxruntime-silicon #17 — GPU on M1/M2: <https://github.com/cansik/onnxruntime-silicon/issues/17>
- Install rembg with CoreML (gist): <https://gist.github.com/fathonix/3b9bda262226ac8842338d65ae505673>

### Benchmarks & comparisons

- "BiRefNet vs rembg vs U2Net: Which Background Removal Model Actually Works in Production?" (dev.to, 2025): <https://dev.to/om_prakash_3311f8a4576605/birefnet-vs-rembg-vs-u2net-which-background-removal-model-actually-works-in-production-4830>
- "Finding the Best Background Removal Models" (Civitai, 2025): <https://civitai.com/articles/12331/finding-the-best-background-removal-models>
- Cloudflare, "Evaluating image segmentation models for background removal": <https://blog.cloudflare.com/background-removal>
- "Image Processing & Background Removal: Beyond rembg" (akadata, 2025): <https://articles.akadata.ltd/image-processing-background-removal-beyond-reblog/>
- "Building an AI Product Photography Pipeline" (dev.to, 2025): <https://dev.to/lucylll/building-an-ai-product-photography-pipeline-multi-model-workflows-async-tasks-and-real-costs-150p>

### Papers

- Qin et al., 2020, *U²-Net: Going Deeper with Nested U-Structure for Salient Object Detection* — <https://arxiv.org/abs/2005.09007>
- Qin et al., 2022, *Highly Accurate Dichotomous Image Segmentation (DIS / ISNet)* — <https://arxiv.org/abs/2203.03041>
- Kim et al., 2022, *Revisiting Image Pyramid Structure for High Resolution Salient Object Detection (InSPyReNet)* — ACCV 2022 — <https://openaccess.thecvf.com/content/ACCV2022/papers/Kim_Revisiting_Image_Pyramid_Structure_for_High_Resolution_Salient_Object_Detection_ACCV_2022_paper.pdf>
- Zheng et al., 2024, *BiRefNet: Bilateral Reference for High-Resolution Dichotomous Image Segmentation* — <https://arxiv.org/abs/2401.03407>
- BiRefNet_HR + BiRefNet_dynamic (2025 checkpoints) — <https://github.com/ZhengPeng7/BiRefNet>
- BEN2 (Background Erase Network 2, PramaLLC) — <https://huggingface.co/PramaLLC/BEN2>
- rembg issue #720 (BiRefNet_HR integration request) — <https://github.com/danielgatis/rembg/issues/720>
- Kirillov et al., 2023, *Segment Anything* — <https://arxiv.org/abs/2304.02643>
