Instructions to use mlx-community/BiRefNet_HR-matting-fp16 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use mlx-community/BiRefNet_HR-matting-fp16 with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] huggingface-cli download --local-dir BiRefNet_HR-matting-fp16 mlx-community/BiRefNet_HR-matting-fp16
- BiRefNet
How to use mlx-community/BiRefNet_HR-matting-fp16 with BiRefNet:
# Option 1: use with transformers from transformers import AutoModelForImageSegmentation birefnet = AutoModelForImageSegmentation.from_pretrained("mlx-community/BiRefNet_HR-matting-fp16", trust_remote_code=True)# Option 2: use with BiRefNet # Install from https://github.com/ZhengPeng7/BiRefNet from models.birefnet import BiRefNet model = BiRefNet.from_pretrained("mlx-community/BiRefNet_HR-matting-fp16") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
| license: mit | |
| base_model: ZhengPeng7/BiRefNet_HR-matting | |
| library_name: mlx | |
| tags: | |
| - mlx | |
| - image-segmentation | |
| - matting | |
| - background-removal | |
| - birefnet | |
| pipeline_tag: image-segmentation | |
| # BiRefNet_HR-matting-fp16 (MLX) | |
| [`mlx-community/BiRefNet_HR-matting-fp16`](https://huggingface.co/mlx-community/BiRefNet_HR-matting-fp16) is an | |
| **fp16 MLX** conversion of [`ZhengPeng7/BiRefNet_HR-matting`](https://huggingface.co/ZhengPeng7/BiRefNet_HR-matting) | |
| (MIT) β the same Swin-L + ASPP-Deformable architecture run at **2048Γ2048** for the crispest dense-hair detail. | |
| The high-resolution "best" matting tier (best all-rounder: crispest fine hair while retaining thin structures | |
| like whiskers). | |
| **Parity:** IoU **0.9905** vs the PyTorch reference (loads through the identical converter + model as the | |
| general weights, zero code change). fp16 runtime validated for production matting quality. ~2 s/image at 2048 | |
| on Apple Silicon (β18 GB peak β a pro-tier footprint). | |
| ## Use (Swift / MLX) | |
| Loaded by [`mlx-birefnet-swift`](https://github.com/xocialize/mlx-birefnet-swift): | |
| ```swift | |
| import BiRefNet | |
| var cfg = BiRefNetConfig.swinLargeDefault; cfg.inputSize = (2048, 2048) | |
| let pipeline = try BiRefNetPipeline.fromPretrained("model.safetensors", dtype: .float16, config: cfg) | |
| let matte = try pipeline(cgImage).maskCGImage() // source-resolution soft-alpha | |
| ``` | |
| Converted from the official PyTorch checkpoint via the package's `birefnet-convert`. Single-file | |
| `model.safetensors`. The fast tier is [`mlx-community/BiRefNet-fp16`](https://huggingface.co/mlx-community/BiRefNet-fp16). | |