withoutBG Open Weights (ONNX)
Open-source background removal and alpha matting from RGB images. This repository hosts the OSS variant exported as a self-contained ONNX graph for ONNX Runtime.
- Try it live: withoutBG on Hugging Face Spaces
- Website: withoutbg.com/open-weights-model
- Benchmarks: withoutbg.com/open-weights-model/results
Model details
| Field | Value |
|---|---|
| Variant | oss |
| Version | 4.1.0 |
| Format | ONNX (opset 18) |
| Precision | fp32 |
| Canvas size | 1024 |
| Size | ~495 MB |
| SHA256 | 927adb4f9a4bd498f1ea5620ae1befdcd45dc3e14b2a791f8fb48ddd69662774 |
Files
withoutbg-openweights.onnxโ inference graph (WBGNet pipeline with OSS upstreams)withoutbg-openweights.onnx.jsonโ sidecar metadata (I/O names, shapes, SHA256)
Input / output contract
The graph expects a letterboxed 1024ร1024 RGB tensor:
| Name | Shape | Dtype | Range | |
|---|---|---|---|---|
| Input | rgb |
[1, 3, 1024, 1024] |
float32 | [0, 1], NCHW |
| Output | alpha |
[1, 1, 1024, 1024] |
float32 | [0, 1] |
Preprocessing (required):
- Convert image to RGB.
- Resize longest side to 1024, preserve aspect ratio.
- Paste at top-left on a black 1024ร1024 canvas.
- Normalize to float32
[0, 1], transpose HWC โ CHW, add batch dim.
Postprocessing (required):
- Crop alpha to the resized (non-padded) region.
- Resize alpha back to the original image dimensions.
- Attach as PNG alpha channel for cutout output.
Usage
from pathlib import Path
import json
import numpy as np
import onnxruntime as ort
from PIL import Image
model_path = Path("withoutbg-openweights.onnx")
sidecar = json.loads(model_path.with_suffix(model_path.suffix + ".json").read_text())
canvas = sidecar.get("canvas_size", 1024)
input_name = sidecar.get("input_name", "rgb")
session = ort.InferenceSession(str(model_path), providers=["CPUExecutionProvider"])
image = Image.open("input.jpg").convert("RGB")
orig_w, orig_h = image.size
scale = canvas / max(orig_w, orig_h)
new_w = max(1, round(orig_w * scale))
new_h = max(1, round(orig_h * scale))
resized = image.resize((new_w, new_h), Image.Resampling.BILINEAR)
padded = Image.new("RGB", (canvas, canvas), (0, 0, 0))
padded.paste(resized, (0, 0))
rgb = np.asarray(padded, dtype=np.float32) / 255.0
rgb = np.transpose(rgb, (2, 0, 1))[None, ...]
alpha_canvas = session.run(None, {input_name: rgb})[0][0, 0]
alpha_crop = alpha_canvas[:new_h, :new_w]
alpha_u8 = np.clip(alpha_crop * 255.0, 0, 255).astype(np.uint8)
alpha = Image.fromarray(alpha_u8, "L").resize((orig_w, orig_h), Image.Resampling.BILINEAR)
out = image.copy()
out.putalpha(alpha)
out.save("output.png")
License
Apache-2.0 โ see withoutbg.com/open-weights-model/license.
Third-party terms
This model uses DINOv3 as an upstream component. See the DINOv3 license.