{"id":50418775,"url":"https://github.com/developer0hye/candle-birefnet","last_synced_at":"2026-05-31T07:05:03.897Z","repository":{"id":344625771,"uuid":"1182478009","full_name":"developer0hye/candle-birefnet","owner":"developer0hye","description":"BiRefNet inference for Hugging Face Candle","archived":false,"fork":false,"pushed_at":"2026-03-16T02:44:55.000Z","size":1907,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-16T04:33:32.957Z","etag":null,"topics":["birefnet","candle","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/developer0hye.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-15T15:21:22.000Z","updated_at":"2026-03-16T02:44:58.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/developer0hye/candle-birefnet","commit_stats":null,"previous_names":["developer0hye/candle-birefnet"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/developer0hye/candle-birefnet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer0hye%2Fcandle-birefnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer0hye%2Fcandle-birefnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer0hye%2Fcandle-birefnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer0hye%2Fcandle-birefnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/developer0hye","download_url":"https://codeload.github.com/developer0hye/candle-birefnet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer0hye%2Fcandle-birefnet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33722189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["birefnet","candle","rust"],"created_at":"2026-05-31T07:05:03.138Z","updated_at":"2026-05-31T07:05:03.891Z","avatar_url":"https://github.com/developer0hye.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# candle-birefnet\n\n[BiRefNet](https://github.com/ZhengPeng7/BiRefNet) (Bilateral Reference Network) inference for [Hugging Face Candle](https://github.com/huggingface/candle).\n\nPure Rust, no custom kernels — works on all Candle backends (CPU, CUDA, Metal, WASM).\n\n## Supported Models\n\n| Model | Backbone | Weights | Constructor |\n|-------|----------|---------|-------------|\n| [BiRefNet](https://huggingface.co/ZhengPeng7/BiRefNet) | Swin-V1-Large | 444 MB (FP16) | `BiRefNet::new(vb)` |\n| [BiRefNet_lite](https://huggingface.co/ZhengPeng7/BiRefNet_lite) | Swin-V1-Tiny | 178 MB (FP32) / 85 MB (FP16) / **43 MB (INT8)** | `BiRefNet::new_lite(vb)` |\n\nINT8 weights use PyTorch Post-Training Quantization with DUTS-TE calibration. See [INT8 Quantization Guide](docs/INT8_QUANTIZATION.md) for details.\n\n## Results\n\nPyTorch (left) vs **Candle/Rust** (right). Each panel shows: Input | Segmentation Mask | Composite.\n\n*Sample images from [BiRefNet demo](https://huggingface.co/spaces/ZhengPeng7/BiRefNet_demo).*\n\n### BiRefNet (Swin-V1-Large)\n\nUsing [`ZhengPeng7/BiRefNet`](https://huggingface.co/ZhengPeng7/BiRefNet) pretrained weights.\n\n#### 1024x1024\n\n| PyTorch | Candle (Rust) |\n|---------|---------------|\n| ![PyTorch](examples/helicopter_result_pytorch_1024.png) | ![Candle](examples/helicopter_result_candle_1024.png) |\n| ![PyTorch](examples/windmill_result_pytorch_1024.png) | ![Candle](examples/windmill_result_candle_1024.png) |\n\n#### 384x384\n\n| PyTorch | Candle (Rust) |\n|---------|---------------|\n| ![PyTorch](examples/helicopter_result_pytorch_384.png) | ![Candle](examples/helicopter_result_candle_384.png) |\n| ![PyTorch](examples/windmill_result_pytorch_384.png) | ![Candle](examples/windmill_result_candle_384.png) |\n\n### BiRefNet_lite (Swin-V1-Tiny)\n\nUsing [`ZhengPeng7/BiRefNet_lite`](https://huggingface.co/ZhengPeng7/BiRefNet_lite) pretrained weights.\n\n#### 1024x1024\n\n| PyTorch | Candle (Rust) |\n|---------|---------------|\n| ![PyTorch](examples/helicopter_result_pytorch_lite_1024.png) | ![Candle](examples/helicopter_result_candle_lite_1024.png) |\n| ![PyTorch](examples/windmill_result_pytorch_lite_1024.png) | ![Candle](examples/windmill_result_candle_lite_1024.png) |\n\n#### 384x384\n\n| PyTorch | Candle (Rust) |\n|---------|---------------|\n| ![PyTorch](examples/helicopter_result_pytorch_lite_384.png) | ![Candle](examples/helicopter_result_candle_lite_384.png) |\n| ![PyTorch](examples/windmill_result_pytorch_lite_384.png) | ![Candle](examples/windmill_result_candle_lite_384.png) |\n\n### BiRefNet_lite INT8 (Quantized, 43 MB)\n\nFP32 (top) vs **INT8 dequantized** (bottom) at 512x512. Each panel shows: Input | Segmentation Mask | Composite.\n\n| FP32 | INT8 |\n|------|------|\n| ![FP32](examples/helicopter_result_candle_lite_512.png) | ![INT8](examples/helicopter_result_int8_512.png) |\n| ![FP32](examples/windmill_result_candle_lite_512.png) | ![INT8](examples/windmill_result_int8_512.png) |\n\nFP32 vs INT8 difference (amplified 10x):\n\n| Helicopter | Windmill |\n|------------|----------|\n| ![Helicopter](examples/helicopter_fp16_vs_int8_comparison.png) | ![Windmill](examples/windmill_fp16_vs_int8_comparison.png) |\n\n*Comparison panels: Input \\| FP32 Mask \\| INT8 Mask \\| Diff(10x) \\| FP32 Composite \\| INT8 Composite*\n\n## Architecture\n\nConfigurable Swin-V1 backbone + ASPPDeformable decoder.\n\nDepends on:\n- [candle-swin](https://github.com/developer0hye/candle-swin) — Swin Transformer V1 backbone\n- [candle-dcnv2](https://github.com/developer0hye/candle-dcnv2) — Deformable Convolution V2\n\n## Quick Start\n\n```bash\n# BiRefNet (Swin-V1-Large, default)\ncargo run --example inference --release -- --image your_image.jpg --size 1024\n\n# BiRefNet_lite (Swin-V1-Tiny, smaller \u0026 faster)\ncargo run --example inference --release -- --image your_image.jpg --size 1024 --lite\n```\n\n### As a library\n\n```rust\nuse candle_core::{Device, DType, Tensor};\nuse candle_nn::VarBuilder;\nuse candle_birefnet::BiRefNet;\n\nlet device = \u0026Device::Cpu;\nlet vb = unsafe {\n    VarBuilder::from_mmaped_safetensors(\u0026[\"model.safetensors\"], DType::F32, device)?\n};\n\n// Swin-V1-Large (default)\nlet model = BiRefNet::new(vb)?;\n\n// Or Swin-V1-Tiny (lite)\n// let model = BiRefNet::new_lite(vb)?;\n\n// Input: [B, 3, H, W] ImageNet-normalized RGB tensor\nlet outputs = model.forward(\u0026input)?;\n// outputs[0]: [B, 1, H, W] segmentation logits (apply sigmoid for mask)\n```\n\n## Validation\n\nEnd-to-end inference output matches PyTorch BiRefNet:\n\n| Model | Format | Resolution | Max Error | Mean Error | IoU vs FP32 |\n|-------|--------|-----------|-----------|------------|-------------|\n| BiRefNet (Swin-L) | FP32 | 384x384 | 6.87e-5 | — | — |\n| BiRefNet (Swin-L) | FP32 | 1024x1024 | 1.63e-4 | — | — |\n| BiRefNet_lite (Swin-T) | FP32 | 384x384 | 5.15e-5 | — | — |\n| BiRefNet_lite (Swin-T) | **INT8 PTQ** | 512x512 | 2.04e-1 | 3.75e-4 | **0.9986** |\n\nINT8 quantized with [DUTS-TE](https://saliencydetection.net/duts/) calibration (500 images). See [INT8 Quantization Guide](docs/INT8_QUANTIZATION.md).\n\n## Note on candle-core Conv2d Bug\n\nThis project uses a [patched candle-core](https://github.com/developer0hye/candle/tree/fix/conv2d-tiled-bug) that works around a `conv2d_tiled` bug ([huggingface/candle#3404](https://github.com/huggingface/candle/issues/3404)). The patch switches the default Conv2d implementation from `TiledIm2Col` to `FullIm2Col`. Once the upstream fix is merged, this project will switch back to the official candle release.\n\n## Reference\n\n- [BiRefNet: Bilateral Reference for High-Resolution Dichotomous Image Segmentation](https://arxiv.org/abs/2401.03407)\n\n## License\n\nApache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloper0hye%2Fcandle-birefnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeveloper0hye%2Fcandle-birefnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloper0hye%2Fcandle-birefnet/lists"}