SAVRN
Search Contact SAVRN

Open-weight model · Image segmentation

birefnet-lite-512

by Studio Ludens studioludens/birefnet-lite-512

A 512×512 ONNX re-export of ZhengPeng7/BiRefNetlite that actually runs in a browser — solving the OOM wall that blocks every 1024×1024 variant from loading in onnxruntime-web.

Parameters
Context
Weights290.4 MB
Licensemit
AccessOpen weights
Monthly Downloads13.4k

Model Card

By Studio Ludens, published under mit, revision 4a3c40c36c94.

A 512×512 ONNX re-export of ZhengPeng7/BiRefNetlite that actually runs in a browser — solving the OOM wall that blocks every 1024×1024 variant from loading in onnxruntime-web. Drop it in with @huggingface/transformers to get high-quality alpha mattes entirely client-side, with no server round-trip. Used in production by Repper for per-motif matte refinement during foreground extraction. The 1024×1024 ONNX variants — including onnx-community/BiRefNetlite-ONNX — fail in every browser backend we tested: Root cause: BiRefNetlite's decoder produces very large intermediate tensors at 1024×1024 (multi-scale feature maps with 1024-way concatenations). The onnxruntime-web WASM heap is hardcoded at…

Read Studio Ludens's full model card

BiRefNet_lite 512×512 (browser-ready ONNX)

A 512×512 ONNX re-export of ZhengPeng7/BiRefNet_lite that actually runs in a browser — solving the OOM wall that blocks every 1024×1024 variant from loading in onnxruntime-web. Drop it in with @huggingface/transformers to get high-quality alpha mattes entirely client-side, with no server round-trip.

Used in production by Repper for per-motif matte refinement during foreground extraction.

Quickstart (transformers.js, WebGPU)

import { AutoModel, AutoProcessor, RawImage } from '@huggingface/transformers';

const model = await AutoModel.from_pretrained('studioludens/birefnet-lite-512', {
    dtype: 'fp16',     // or 'fp32'
    device: 'webgpu',  // falls back to 'wasm' on unsupported hardware
});
const processor = await AutoProcessor.from_pretrained('studioludens/birefnet-lite-512');

const image = await RawImage.read('https://example.com/photo.jpg');
const { pixel_values } = await processor(image);

const { logits } = await model({ input_image: pixel_values });
// Apply sigmoid, upscale back to original resolution, use as alpha matte.

Why this repo exists — variant comparison

Variant Input res Runtime Works in browser?
ZhengPeng7/BiRefNet_lite 1024×1024 PyTorch — (not ONNX)
onnx-community/BiRefNet_lite-ONNX 1024×1024 ONNX No (OOM)
studioludens/birefnet-lite-512 (this repo) 512×512 ONNX Yes

The 1024×1024 ONNX variants — including onnx-community/BiRefNet_lite-ONNX — fail in every browser backend we tested:

Backend Variant Failure
WebGPU fp16, cascaded std::bad_alloc during OrtRun
WebGPU fp32, cascaded unaligned accesses
WASM fp32, cascaded std::bad_alloc during OrtRun
WASM fp32, original std::bad_alloc during OrtRun

Root cause: BiRefNet_lite's decoder produces very large intermediate tensors at 1024×1024 (multi-scale feature maps with 1024-way concatenations). The onnxruntime-web WASM heap is hardcoded at ~2–4 GB and cannot be raised at runtime, so peak working-set exceeds available memory regardless of backend or precision.

Reducing to 512×512 shrinks intermediate tensors by 4×. At 512×512 the graph also naturally uses max 7 storage buffers per shader stage, comfortably inside WebGPU's maxStorageBuffersPerShaderStage limit (10 on older Apple Silicon adapters, 16 on Chrome ≥146), so no graph surgery is needed.

For crop-level matte refinement this is a fair trade: the crop is already small, and edge quality is indistinguishable from the 1024 reference in our tests.

Variants

File Precision Size
onnx/model.onnx fp32 183 MB
onnx/model_fp16.onnx fp16 94 MB

config.json sets transformers.js_config.dtype = "fp16" by default. Override at load time if you want fp32.

Input / output

  • Input: RGB image, resized to 512×512, ImageNet normalization (mean = [0.485, 0.456, 0.406], std = [0.229, 0.224, 0.225]), rescale factor 1/255. Layout NCHW, input tensor name input_image.
  • Output: Single-channel logits at 512×512. Apply sigmoid externally to get the alpha matte in [0, 1]. Resize back to original image dimensions with bilinear interpolation.

The preprocessor_config.json uses ViTFeatureExtractor, so AutoProcessor.from_pretrained(...) works out of the box.

How it was built

Export toolchain (why it's tricky)

BiRefNet uses torchvision.ops.deform_conv2d (deformable convolution), which has no canonical ONNX symbolic. Exporting cleanly is the hard part, and every "obvious" path fails:

PyTorch Approach Result
2.0.1 deform_conv2d_onnx_exporter (unpatched) NoneType + int — shape info not propagated
2.1.2 Same Same error
2.6.0 Same Same error
2.6.0 New torch.onnx.dynamo_export DispatchError: No ONNX function for deform_conv2d
2.6.0 Simplified Conv symbolic (drop offset) Export works but 62% pixel error — unusable

The fix is Kazuhito00's patch to deform_conv2d_onnx_exporter (_get_tensor_dim_size stride-based fallback), which only works against PyTorch 2.0.1's legacy tracer. Newer PyTorch versions route deform_conv2d through a different export path where the patch doesn't apply.

Why Docker

Installing PyTorch 2.0.1 locally is painful — the matching wheels are EOL, pip install torch==2.0.1 tends to pull a binary incompatible with current Python / glibc / macOS, and the surrounding torchvision / transformers pins are finicky. The reliable path is a pinned Docker image:

Python 3.10
torch==2.0.1
torchvision (compatible with 2.0.1)
transformers + deform-conv2d-onnx-exporter (Kazuhito00's patched version)

Export recipe

# Build once
docker build -t birefnet-export ./docker/

# Mount HF cache and output dir, run export
docker run --rm \
  -v "$(pwd)/docker":/work \
  -v "$HOME/.cache/huggingface":/root/.cache/huggingface \
  birefnet-export python /work/export_512_patched.py

The export script:

  1. Loads ZhengPeng7/BiRefNet_lite via transformers.AutoModelForImageSegmentation.
  2. Applies Kazuhito00's patched deform_conv2d_onnx_exporter before calling torch.onnx.export.
  3. Exports with opset=17, fixed 512×512 input shape, constant folding enabled.
  4. Writes model.onnx (fp32, ~183 MB, 17,488 nodes, max 7 bindings, 80 GatherND ops).

fp16 is produced separately via onnxruntime.transformers.float16.convert_float_to_float16 applied to the fp32 export.

Validation

Pixel-by-pixel comparison against the PyTorch forward pass on reference images. The 512 export matches PyTorch exactly (zero pixel diff when both are resized to the same output resolution).

What didn't work

  • Graph surgery on the 1024 model — cascading Concat/Split ops into chains of ≤8 inputs/outputs passes the WebGPU binding-limit check, but the OOM is about intermediate tensor size, not binding count.
  • onnxslim optimization — collapses cascaded ops back into the originals and inflates file size.
  • Newer PyTorch exporters (2.1.x, 2.6.x dynamo) — all fail to produce correct deform_conv2d. PyTorch 2.0.1 is the working configuration.
  • WebNN — Chrome-only, still behind a flag, GatherND support unconfirmed, and requires bypassing transformers.js.

Differences from upstream BiRefNet_lite

  • Input resolution 512×512 instead of 1024×1024 (unblocks browser inference).
  • Correct deform_conv2d export via patched exporter on PyTorch 2.0.1 — output matches PyTorch reference exactly.
  • fp16 variant shipped alongside fp32.
  • No graph surgery — not needed at 512×512.

For full-image matting at 1024×1024, prefer the upstream PyTorch model or server-side ONNX. This export is tuned for browser deployment.

Limitations

  • 512×512 input limits edge detail on large images — use on crops or smaller inputs for best results.
  • Adapters with fewer than ~10 storage buffers per shader stage fall back to WASM; the model still runs, just slower.
  • No INT8 quantization yet. A quantized variant could roughly halve the fp16 size but hasn't been validated.

Citation

@article{zheng2024birefnet,
  title={Bilateral Reference for High-Resolution Dichotomous Image Segmentation},
  author={Zheng, Peng and Gao, Dehong and Fan, Deng-Ping and Liu, Li and Laaksonen, Jorma and Ouyang, Wanli and Sebe, Nicu},
  journal={CAAI Artificial Intelligence Research},
  year={2024}
}

Configuration

Model type
swin

Identity and Version

Repository
studioludens/birefnet-lite-512
Publisher
Studio Ludens
Task
Image segmentation
Modality
Image
Library
transformers.js
Parameters
Not stated by the source
Languages
Not stated by the source
Revision
4a3c40c36c94093cc1e724d9ea428b8fa4b57dc7
First published
2026-04-17
Last updated
2026-04-17

Files and Weights

6 files, 290.4 MB in total. The weights are 2 files totalling 290.4 MB in onnx.

Weights2 files · 290.4 MB
Configuration2 files · 470 B
Documentation1 file · 8.3 KB
Repository1 file · 1.5 KB
Every file
FileTypeSizeSHA-256
onnx/model.onnxWeights191.9 MB 1cb0fb360dad
onnx/model_fp16.onnxWeights98.5 MB eff9216bb2f9
config.jsonConfiguration81 B
preprocessor_config.jsonConfiguration389 B
README.mdDocumentation8.3 KB
.gitattributesRepository1.5 KB

License and Download

License
mit
Access
Open weights, no gate
Download size
290.4 MB
Download from Studio Ludens

Released by Studio Ludens through its official repository on Hugging Face. Read the license.

Built From

Memory Requirements

PrecisionWeights in memory
As published290.4 MB

Weights only, from the published parameter count; the key-value cache and runtime add to this.

Questions About birefnet-lite-512

Can I use birefnet-lite-512 commercially?

Yes. birefnet-lite-512 is released under MIT License. The MIT License is a short permissive license. It permits commercial use, modification and redistribution, provided the copyright notice and permission notice are included.

Similar Models

Model · Image segmentation

segformer-b2-finetuned-ade-512-512

NVIDIA

SegFormer model fine-tuned on ADE20k at resolution 512x512. It was introduced in the paper SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers by Xie et al. and first released in this repository. Disclaimer: The team releasing SegFormer did not write a model card for this model so this model card has been written by the Hugging Face team. SegFormer consists of a hierarchical Transformer encoder and a lightweight all-MLP decode head to achieve great results on semantic segmentation benchmarks such as ADE20K and Cityscapes. The hierarchical Transformer is first pre-trained on ImageNet-1k, after which a decode head is added and fine-tuned altogether on a…

Open weights other transformers

Model · Image segmentation

segformer-b3-finetuned-ade-512-512

NVIDIA

SegFormer model fine-tuned on ADE20k at resolution 512x512. It was introduced in the paper SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers by Xie et al. and first released in this repository. Disclaimer: The team releasing SegFormer did not write a model card for this model so this model card has been written by the Hugging Face team. SegFormer consists of a hierarchical Transformer encoder and a lightweight all-MLP decode head to achieve great results on semantic segmentation benchmarks such as ADE20K and Cityscapes. The hierarchical Transformer is first pre-trained on ImageNet-1k, after which a decode head is added and fine-tuned altogether on a…

Open weights other transformers

Model · Image segmentation

oneformer_ade20k_swin_large

SHI Labs

OneFormer model trained on the ADE20k dataset (large-sized version, Swin backbone). It was introduced in the paper OneFormer: One Transformer to Rule Universal Image Segmentation by Jain et al. and first released in this repository. OneFormer is the first multi-task universal image segmentation framework. It needs to be trained only once with a single universal architecture, a single model, and on a single dataset, to outperform existing specialized models across semantic, instance, and panoptic segmentation tasks. OneFormer uses a task token to condition the model on the task in focus, making the architecture task-guided for training, and task-dynamic for inference, all with a single…

Open weights mit transformers

Model · Image segmentation

segformer-b1-finetuned-ade-512-512

NVIDIA

SegFormer model fine-tuned on ADE20k at resolution 512x512. It was introduced in the paper SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers by Xie et al. and first released in this repository. Disclaimer: The team releasing SegFormer did not write a model card for this model so this model card has been written by the Hugging Face team. SegFormer consists of a hierarchical Transformer encoder and a lightweight all-MLP decode head to achieve great results on semantic segmentation benchmarks such as ADE20K and Cityscapes. The hierarchical Transformer is first pre-trained on ImageNet-1k, after which a decode head is added and fine-tuned altogether on a…

Open weights other transformers

Model · Image segmentation

segformer-b0-finetuned-ade-512-512

Joshua

https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512 with ONNX weights to be compatible with Transformers.js. If you haven't already, you can install the Transformers.js JavaScript library from NPM using: Example: Image segmentation with Xenova/segformer-b0-finetuned-ade-512-512. You can visualize the outputs with: Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using Optimum and structuring your repo like this one (with ONNX weights located in a subfolder named onnx).

Open weights transformers.js

Model · Image segmentation

DelineateAnything

Mykola Lavreniuk

Delineate Anything v2 extends Delineate Anything into a globally representative, resolution-agnostic foundation model that scales agricultural field boundary detection to a planetary level from any imagery source. Trained on FBIS-73M, a massive 73-million-instance dataset spanning 61 countries with diverse imagery sources ranging from 0.25m to 10m resolution, built through a resolution-specific curation pipeline that solves the parcel-versus-field mismatch, Delineate Anything v2 sets a new state-of-the-art in global zero-shot delineation. It delivers a +103.3% relative gain in [email protected] over Delineate Anything while maintaining extreme efficiency, mapping all of Ukraine (603,000 km²) in 5.4…

Open weights agpl-3.0 ultralytics