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/train.sh from ZhengPeng7/BiRefNet: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/ZhengPeng7/BiRefNet/resolve/f10d16f80ea9b73cd2010793a90bc779ec1f45e1/BiRefNet_github/train.sh
- Command line
-
hf download hf://ZhengPeng7/BiRefNet@f10d16f80ea9b73cd2010793a90bc779ec1f45e1/BiRefNet_github/train.sh
-
curl -L -o train.sh https://huggingface.co/ZhengPeng7/BiRefNet/resolve/f10d16f80ea9b73cd2010793a90bc779ec1f45e1/BiRefNet_github/train.sh
1.42 kB
| # Run script | |
| # Settings of training & test for different tasks. | |
| method="$1" | |
| task=$(python3 config.py) | |
| case "${task}" in | |
| "DIS5K") epochs=600 && val_last=100 && step=5 ;; | |
| "COD") epochs=150 && val_last=50 && step=5 ;; | |
| "HRSOD") epochs=150 && val_last=50 && step=5 ;; | |
| "DIS5K+HRSOD+HRS10K") epochs=250 && val_last=50 && step=5 ;; | |
| "P3M-10k") epochs=150 && val_last=50 && step=5 ;; | |
| esac | |
| testsets=NO # Non-existing folder to skip. | |
| # testsets=TE-COD10K # for COD | |
| # Train | |
| devices=$2 | |
| nproc_per_node=$(echo ${devices%%,} | grep -o "," | wc -l) | |
| to_be_distributed=`echo ${nproc_per_node} | awk '{if($e > 0) print "True"; else print "False";}'` | |
| echo Training started at $(date) | |
| if [ ${to_be_distributed} == "True" ] | |
| then | |
| # Adapt the nproc_per_node by the number of GPUs. Give 8989 as the default value of master_port. | |
| echo "Multi-GPU mode received..." | |
| CUDA_VISIBLE_DEVICES=${devices} \ | |
| torchrun --nproc_per_node $((nproc_per_node+1)) --master_port=${3:-8989} \ | |
| train.py --ckpt_dir ckpt/${method} --epochs ${epochs} \ | |
| --testsets ${testsets} \ | |
| --dist ${to_be_distributed} | |
| else | |
| echo "Single-GPU mode received..." | |
| CUDA_VISIBLE_DEVICES=${devices} \ | |
| python train.py --ckpt_dir ckpt/${method} --epochs ${epochs} \ | |
| --testsets ${testsets} \ | |
| --dist ${to_be_distributed} \ | |
| --resume ckpt/xx/ep100.pth | |
| fi | |
| echo Training finished at $(date) | |