--- license: mit library_name: onnx pipeline_tag: image-segmentation base_model: ZhengPeng7/BiRefNet_lite-2K tags: - background-removal - dichotomous-image-segmentation - onnx - webgpu - birefnet --- # BiRefNet_lite-2K — ONNX fp16 (dynamic input size, low-memory graph) ONNX export of [ZhengPeng7/BiRefNet_lite-2K](https://huggingface.co/ZhengPeng7/BiRefNet_lite-2K) (Swin-T backbone, 44M params, trained for 2560×1440), made for in-browser inference with [`birefnet-webgpu`](https://github.com/anudit/birefnet-webgpu). | file | precision | input | output | size | |---|---|---|---|---| | `onnx/model_fp16.onnx` | fp16 weights, fp32 I/O | `input_image` `[1,3,H,W]` (ImageNet-normalised RGB) | `output_image` `[1,1,H,W]` logits (apply sigmoid) | ~91 MB | **H and W are dynamic but must both be multiples of 64** (Swin patch merging, including the half-resolution multi-scale path). Resize your image to such a size (the 2K model was trained at 2560×1440; `birefnet-webgpu` buckets the long side to 512 / 1024 / 1536 / 2048 / 2560 and keeps the aspect ratio), run, then resize the mask back. Verified against PyTorch at 512², 640×960, 1024², 1536×1024 and 1472×2560. ## What is different from a plain `torch.onnx.export` A naive export needs ~11 GB of activations at 2560×1440, which is impossible in a browser tab. This graph computes the same function with ~0.45 GB peak live activations at 2560×1472 (~1.1 GB allocated on GPU in the WebGPU engine; far less at smaller sizes): * Deformable convolutions use the standard ONNX **`DeformConv`** op (opset 19+) instead of an im2col gather chain. * The 5-branch ASPP concat (1280 ch) followed by a 1×1 conv is rewritten as a sum of five 1×1 convs. * The full-resolution decoder tail (bilinear upsample → concat → 1×1 conv, and the `ipt_blk1` branch) is algebraically collapsed into a 1×1 conv at low resolution plus one 5×5 conv on the input image, with the branch's bias response built exactly from a single-channel conv over a ones image. This is exact except for a ~1 px outer ring where zero-padding interacts with the folded convolutions (max logit difference ≈ 0.64 there, ≤ 7e-3 anywhere else). * GELU is exported as the `Gelu` op (opset 20). fp32 graph IoU vs the original PyTorch model: ≥ 0.999997 on the test sizes; fp16 graph IoU 0.9995 (2560×1440, ORT CPU). Requires a runtime that implements `DeformConv` and `Gelu` (verified with onnxruntime on CPU; the `birefnet-webgpu` engine on WebGPU). ## License / credits Weights and architecture: Zheng Peng et al., [BiRefNet](https://github.com/ZhengPeng7/BiRefNet) (MIT). Please check the upstream card for the training-data (DIS5K) terms before commercial use.