Image Segmentation
BiRefNet
Safetensors
Transformers
background-removal
mask-generation
Dichotomous Image Segmentation
Camouflaged Object Detection
Salient Object Detection
pytorch_model_hub_mixin
model_hub_mixin
custom_code
Instructions to use ZhengPeng7/BiRefNet with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- BiRefNet
How to use ZhengPeng7/BiRefNet with BiRefNet:
# Option 1: use with transformers from transformers import AutoModelForImageSegmentation birefnet = AutoModelForImageSegmentation.from_pretrained("ZhengPeng7/BiRefNet", 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("ZhengPeng7/BiRefNet") - Transformers
How to use ZhengPeng7/BiRefNet with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-segmentation", model="ZhengPeng7/BiRefNet", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForImageSegmentation model = AutoModelForImageSegmentation.from_pretrained("ZhengPeng7/BiRefNet", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download BiRefNet_github/test.sh from ZhengPeng7/BiRefNet: direct link, hf CLI and curl.
- Browser
- Download file 833 Bytes
-
https://huggingface.co/ZhengPeng7/BiRefNet/resolve/f10d16f80ea9b73cd2010793a90bc779ec1f45e1/BiRefNet_github/test.sh
- Command line
-
hf download hf://ZhengPeng7/BiRefNet@f10d16f80ea9b73cd2010793a90bc779ec1f45e1/BiRefNet_github/test.sh
-
curl -L -o test.sh https://huggingface.co/ZhengPeng7/BiRefNet/resolve/f10d16f80ea9b73cd2010793a90bc779ec1f45e1/BiRefNet_github/test.sh
833 Bytes
| devices=${1:-0} | |
| pred_root=${2:-e_preds} | |
| # Inference | |
| CUDA_VISIBLE_DEVICES=${devices} python inference.py --pred_root ${pred_root} | |
| echo Inference finished at $(date) | |
| # Evaluation | |
| log_dir=e_logs && mkdir ${log_dir} | |
| task=$(python3 config.py) | |
| case "${task}" in | |
| "DIS5K") testsets='DIS-VD,DIS-TE1,DIS-TE2,DIS-TE3,DIS-TE4' ;; | |
| "COD") testsets='CHAMELEON,NC4K,TE-CAMO,TE-COD10K' ;; | |
| "HRSOD") testsets='DAVIS-S,TE-HRSOD,TE-UHRSD,DUT-OMRON,TE-DUTS' ;; | |
| "DIS5K+HRSOD+HRS10K") testsets='DIS-VD' ;; | |
| "P3M-10k") testsets='TE-P3M-500-P,TE-P3M-500-NP' ;; | |
| esac | |
| testsets=(`echo ${testsets} | tr ',' ' '`) && testsets=${testsets[@]} | |
| for testset in ${testsets}; do | |
| nohup python eval_existingOnes.py --pred_root ${pred_root} --data_lst ${testset} > ${log_dir}/eval_${testset}.out 2>&1 & | |
| done | |
| echo Evaluation started at $(date) | |