BiRefNet-matting(原生 DeformConv ONNX)

ZhengPeng7/BiRefNet-mattingepoch_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])

致谢

  • 模型:ZhengPeng7/BiRefNet(CAAI AIR 2024),matting 权 ZhengPeng7/BiRefNet-matting
  • 本仓库只提供同权的原生 DeformConv ONNX,未重新训练
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