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_in1k encoder + depthwise-separable UNet decoder + ResidualEdgeRefiner)
  • Parameters: 7,650,227 (7.65M)
  • Input: input β€” (B, 4, H, W) float32/float16, aspect-ratio letterboxed to 512Γ—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 (0 everywhere in Auto mode, or edge/box hint in [-1, 1])
  • Output: logits β€” (B, 1, H, W) raw foreground logits (apply sigmoid -> 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/BiRefNet using timm (mobilenetv4_conv_medium.e500_r256_in1k) along with DIS5K, DUTS, and curated wallpaper datasets.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support