BiRefNet β ONNX (high-resolution background removal)
BiRefNet (Zheng et al., "Bilateral Reference for High-Resolution Dichotomous Image Segmentation") exported to ONNX. MIT β code and weights. All credit to the BiRefNet authors.
Mirrored for QtMeshEditor (issue #1016, epic #818 Track C2) as the Best matting tier for image-to-3D, alongside U2Net as the Fast tier.
The file QtMeshEditor downloads at runtime lives in the shared
fernandotonon/QtMeshEditor-modelsrepo underrembg/. This repo is the standalone model card + mirror.
Why it exists
Image-to-3D quality is bounded by the cutout. U2Net runs at 320x320 and visibly loses hair and fur edges, which the reconstruction then turns into surface noise. BiRefNet runs at 1024x1024 and is measurably crisper:
| model | input | ambiguous edge pixels |
|---|---|---|
| U2Net | 320x320 | 2.56% |
| BiRefNet | 1024x1024 | 0.86% |
(Fraction of pixels with alpha strictly between 0.05 and 0.95 on a reference photo β lower is a cleaner cut. BiRefNet is ~3x crisper.)
Comparison of final result, generating the model in QtMeshEditor with TRELLIS.2 after U2Net(Viewport1) or BiRefNet(Viewport2) background removal

I/O
input pixel_values float32 [1,3,1024,1024] ImageNet-normalised RGB (NCHW)
output alpha float32 [1,1,1024,1024] foreground matte in [0,1]
Normalisation: mean = [0.485, 0.456, 0.406], std = [0.229, 0.224, 0.225].
The sigmoid is folded INTO the graph, and only the final refined map is
returned β upstream forward() emits a list of progressively refined logits,
which would otherwise leave a consumer guessing which output is authoritative.
Spatial dims are pinned (only batch is dynamic).
Export notes
BiRefNet is not straightforwardly exportable; three issues had to be solved:
- The published checkpoint carries fp16 weights, so tracing with an fp32 input fails. Exported as fp32.
torchvision::deform_conv2dhas no ONNX representation, and it is not optional β the checkpoint carries 150 deformable tensors, so disabling ASPPDeformable would discard trained weights. The exporter decomposes it into GridSample + MatMul, verified againsttorchvision.ops.deform_conv2dto ~7e-07 on every kernel size BiRefNet uses (1x1, 3x3, 7x7), modulation mask included.birefnet.pydoesfrom torchvision.ops import deform_conv2d, so patching torchvision after import silently has no effect.
Export script:
scripts/export-birefnet-onnx.py
(opset 17). It asserts torch-vs-ORT parity (1.5e-07) and refuses to write a
graph with non-finite output or a near-constant matte.
License
MIT, inherited from
ZhengPeng7/BiRefNet.
Credit: Peng Zheng et al.
Model tree for fernandotonon/QtMeshEditor-birefnet-onnx
Base model
ZhengPeng7/BiRefNet

