SubCut
Lightweight ~7.7 MB subject cutout and alpha matting model distilled from ZhengPeng7/BiRefNet, designed for fast CPU inference (~280 ms per image at 512Γ512) on desktop and edge devices.
Model Details
- Architecture:
SubCut(mobilenetv4_conv_medium.e500_r256_in1kencoder + depthwise-separable UNet decoder +ResidualEdgeRefiner) - Parameters: 7,650,227 (7.65M)
- Input:
inputβ(B, 4, H, W)float32/float16, aspect-ratio letterboxed to512Γ512- Channels 0β2: ImageNet-normalized RGB (
mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225]) - Channel 3: Optional hint / box prompt channel (
0everywhere in Auto mode, or edge/box hint in[-1, 1])
- Channels 0β2: ImageNet-normalized RGB (
- Output:
logitsβ(B, 1, H, W)raw foreground logits (applysigmoid-> alpha matte in[0, 1]) - Opset: ONNX opset 17 (dynamic batch, height, width)
Files
| File | Format | Size | Notes |
|---|---|---|---|
subcut_int8.onnx |
Weight-INT8 ONNX (DequantizeLinear) |
7.74 MB | Default fast CPU model (~281 ms median on CPU) |
subcut_fp16.onnx |
FP16 ONNX | 14.91 MB | DirectML / GPU half-precision (elemType=10) |
subcut_fp32.onnx |
FP32 ONNX | 29.77 MB | DirectML / GPU full-precision (~41 ms steady on RTX 3050 DML) |
best.pt |
PyTorch Checkpoint | 30.80 MB | Epoch 7 weights (use_refiner=True, in_chans=4) |
model.py |
PyTorch Source | β | SubCut architecture definition |
Quick Usage (ONNX Runtime / Python)
import cv2
import numpy as np
import onnxruntime as ort
def letterbox(img, size=512):
h, w = img.shape[:2]
scale = size / max(h, w)
nh, nw = max(1, round(h * scale)), max(1, round(w * scale))
rs = cv2.resize(img, (nw, nh), interpolation=cv2.INTER_AREA if scale < 1 else cv2.INTER_LINEAR)
top, left = (size - nh) // 2, (size - nw) // 2
canvas = np.zeros((size, size, 3), dtype=np.uint8)
canvas[top:top+nh, left:left+nw] = rs
return canvas, (top, left, nh, nw)
bgr = cv2.imread("wallpaper.jpg")
rgb = cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB)
lb, (top, left, nh, nw) = letterbox(rgb, 512)
mean = np.array([0.485, 0.456, 0.406], dtype=np.float32)
std = np.array([0.229, 0.224, 0.225], dtype=np.float32)
norm = (lb.astype(np.float32) / 255.0 - mean) / std
zeros = np.zeros((512, 512, 1), dtype=np.float32)
x = np.concatenate([norm, zeros], axis=-1).transpose(2, 0, 1)[None, ...]
sess = ort.InferenceSession("subcut_int8.onnx", providers=["CPUExecutionProvider"])
logits = sess.run(["logits"], {"input": x})[0][0, 0]
alpha = 1.0 / (1.0 + np.exp(-np.clip(logits, -20.0, 20.0)))
alpha = cv2.resize(alpha[top:top+nh, left:left+nw], (rgb.shape[1], rgb.shape[0]), interpolation=cv2.INTER_LINEAR)
License & Attribution
- Copyright: Copyright (c) 2026 Deepak S
- License: CC BY-NC 4.0 (Non-Commercial use only).
- Credits: Distilled from
ZhengPeng7/BiRefNetusingtimm(mobilenetv4_conv_medium.e500_r256_in1k) along with DIS5K, DUTS, and curated wallpaper datasets.