Downloads · 30 days
0
Grazier/birefnet-matting-deformconv
birefnet-matting-deformconv is a machine learning model from Grazier. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for onnxruntime.
由 ZhengPeng7/BiRefNet-matting 的 epoch100 权重重导,ONNX opset 19,使用原生 DeformConv。不是官方 GatherND 展开导出。
Downloads · 30 days
0
Access
Public
Updated Sep 14, 2026
Repo size
1.9 GB
Likes
0
Public
Click a slice to open those files.
.onnx1.9 GB · 100%
From the Hugging Face model README
由 ZhengPeng7/BiRefNet-matting 的 epoch_100 权重重导,ONNX opset 19,使用原生 DeformConv。不是官方 GatherND 展开导出。
原权重与本仓库均为 MIT。请保留上游版权与许可声明。
| 文件 | 输入(NCHW) |
|---|---|
birefnet_matting_deformconv_768x1152.onnx | 1×3×1152×768(高×宽,2:3) |
birefnet_matting_deformconv.onnx | 1×3×1024×1024 |
均为 float32。预处理:RGB → [0,1] → ImageNet mean/std
[0.485, 0.456, 0.406] / [0.229, 0.224, 0.225]。
建议 cover 到目标分辨率,不要 letterbox 垫边。输出为连续 alpha;若 logits 超出 [0,1] 则做 sigmoid。
ONNX Runtime CPU ≥ 1.25(建议 1.30)。更早版本没有 CPU DeformConv。
import numpy as np
import onnxruntime as ort
from PIL import Image
MEAN = np.array([0.485, 0.456, 0.406], dtype=np.float32)
STD = np.array([0.229, 0.224, 0.225], dtype=np.float32)
def cover(im, w, h):
im = im.convert("RGB")
s = max(w / im.width, h / im.height)
nw, nh = int(round(im.width * s)), int(round(im.height * s))
im = im.resize((nw, nh), Image.Resampling.LANCZOS)
l, t = (nw - w) // 2, (nh - h) // 2
return im.crop((l, t, l + w, t + h))
W, H = 768, 1152 # 1024² 权则改成 1024, 1024
x = np.asarray(cover(Image.open("photo.jpg"), W, H), dtype=np.float32) / 255.0
x = ((x - MEAN) / STD).transpose(2, 0, 1)[None].copy()
sess = ort.InferenceSession("birefnet_matting_deformconv_768x1152.onnx",
providers=["CPUExecutionProvider"])
name = sess.get_inputs()[0].name
alpha = np.squeeze(sess.run(None, {name: x})[0])
致谢