BiRefNet Portrait
ZhengPeng7/BiRefNet-portrait
published May 2024 · updated Feb 2026
BiRefNet Portrait is a segmentation model for high-resolution portrait matting and background removal.
specs
| Task | Portrait Matting / Dichotomous Image Segmentation |
| Architecture | Bilateral Reference Network (BiRefNet) |
| License | MIT |
about this model
ZhengPeng7/BiRefNet-portrait is a segmentation model for high-resolution dichotomous image segmentation, specifically fine-tuned for portrait matting. It uses a bilateral reference mechanism to capture both global object location and fine boundary details.
Architecture and training
The model consists of a Localization Module (LM) for global object localization and a Reconstruction Module (RM) that applies bilateral reference (BiRef) using hierarchical image patches as source reference and gradient maps as target reference. Auxiliary gradient supervision sharpens the model’s focus on fine edges. The architecture is based on Swin Transformer with attention implemented via PyTorch SDPA (since September 2025), reducing memory cost and enabling acceleration.
Training and validation data
- Training sets: P3M-10k (excluding TE-P3M-500-P) and TR-humans.
- Validation set: TE-P3M-500-P.
Benchmark performance
| Dataset | Method | Smeasure | maxFm | meanEm | MAE | maxEm | meanFm | wFmeasure | adpEm | adpFm | HCE |
|---|---|---|---|---|---|---|---|---|---|---|---|
| TE-P3M-500-P | BiRefNet-portrait (epoch 150) | .983 | .996 | .991 | .006 | .997 | .988 | .990 | .933 | .965 | .000 |
Additional details
- Published in CAAI Artificial Intelligence Research (2024, volume 3, page 9150038, DOI 10.26599/AIR.2024.9150038).
- Licensed under MIT.
- Supports tasks including image segmentation, background removal, mask generation, dichotomous image segmentation, camouflaged object detection, and salient object detection.
- Performance optimization (June 2025):
refine_foregroundaccelerated by 8×, reaching ~80ms on RTX 5090 via GPU implementation of fast-fg-est.
The model validates on multiple segmentation benchmarks and outperforms prior task-specific state-of-the-art methods across dichotomous image segmentation, camouflaged object detection, and salient object detection tasks.
best for
- ·Remove background from portrait photos with high precision
- ·Automate human subject extraction for photo editing and compositing
- ·Enable high-resolution portrait segmentation for mobile apps
FAQ
Input is a high-resolution image; output is a binary segmentation mask indicating the portrait region.
MIT license.
On TE-P3M-500-P, it achieves Smeasure 0.983, maxFm 0.996, and MAE 0.006.
Use the gigarouter OpenAI-compatible endpoint with your API key, passing an image URL or base64-encoded image.
We're benchmarking and onboarding BiRefNet Portrait as a hosted, OpenAI-compatible API. Sign in for free credit and be ready when it lands, or tell us you want it and we'll prioritize it.