FeyNoBg - Feyn Labs' open-source automatic background removal model
FeyNoBg is an open-source automatic background removal model from Feyn Labs. It's based on the BiRefNet architecture with significant improvements and boasts 263 million parameters. The model achieved excellent results in 4 out of 8 benchmark tests, including UHRSD-TE and HRSOD-TE...
What is FeyNoBg?
FeyNoBg is an open-source automatic background removal model from Feyn Labs. It's a deeply improved version of the BiRefNet architecture with 263 million parameters. The model achieved state-of-the-art (SOTA) results in 4 out of 8 benchmark tests, including UHRSD-TE and HRSOD-TE, with the remaining 4 results within 2% of the best. The team has also open-sourced the NoBg Python library, providing a unified interface for model execution and training, supporting the Hugging Face ecosystem, and using the Apache 2.0 license.
FeyNoBg's main functions
-
High-precision background removalAutomatically identifies the foreground of an image and generates an alpha mask, supporting complex edges such as hair, fine lines, etc.
-
Ultra-high resolution supportUHRSD-TE benchmark performance is leading in 4K and 8K scenarios.
-
Image and video cutoutSupports background removal for single images, batch images, and video frame sequences.
-
Open source trainableThe NoBg library allows for fine-tuning on custom datasets, supporting the replacement of loss functions and adjustment of resolution.
-
Hugging Face integrationBoth the model and the processor are compatible.
transformersThe ecosystem supports one-click download and push notifications.
FeyNoBg's technical principles
-
BiRefNet dual-module architectureThe localization module is responsible for foreground recognition, while the reconstruction module is responsible for boundary tracking; the two complement each other and work together.
-
Phase 3 Deep ExpansionThe third stage of the feature extractor was expanded from 18 blocks to 24 blocks, and the number of parameters increased from 222 million to 263 million. The original pre-trained weights were retained, and only the newly added blocks were trained from scratch to avoid knowledge forgetting.
-
Diverse data mixingIt integrates 26,100 images from 10 datasets, covering types such as crowded scenes, camouflage, high resolution, portraits, and animation, with a maximum of 4,000 images per source to prevent single data from dominating.
-
Standardized annotation formatThe foreground mask of the segmentation dataset and the alpha channel of the matting dataset are uniformly converted into binary foreground masks to ensure consistency in training objectives.
-
S-measure assessmentThe S-measure metric in the 0-1 range simultaneously rewards both subject integrity and shape fidelity.
Follow us on WeChat and reply with "open source",join inAI open source project discussion group
How to use FeyNoBg
-
Installation Environment:pass
pip install nobgInstall the libraries and ensure that your Python ≥ 3.10 and torch ≥ 2.0 environments are ready. -
Loading Model:use
AutoModel.from_pretrained("feyninc/FeyNobg")Download and load pre-trained weights from Hugging Face. -
Load processor:use
AutoProcessor.from_pretrained("feyninc/FeyNobg")Initialize the image preprocessing module. -
Reading imagesConvert the target image to RGB format to ensure the input meets the model requirements.
-
PreprocessingThe processor is called to resize and normalize the image, generating the tensor input required by the model.
-
Model Inference:exist
torch.inference_mode()Next, pass pixel_values to the model to get the raw output after background removal. -
Post-processing mask:use
post_process_alpha_mattingThe model output is restored to an alpha mask of the original image size. -
Result: call
cutoutThe method combines the foreground of the original image with an alpha mask and saves it as a transparent PNG file.
FeyNoBg's core advantages
-
SOTA performanceIt leads in 4 out of 8 benchmarks, demonstrating significant advantages in ultra-high resolution scenarios.
-
Knowledge Retention TrainingPreserve the original weights when expanding network depth to avoid catastrophic forgetting.
-
Engineering optimizationThe NoBg library outperforms the original BiRefNet implementation at batch sizes of 1/2/4, offering higher throughput, lower latency, and less memory usage.
-
Eco-compatibleDeep integration with Hugging Face
transformersIt supports Trainer, Hub push and half-precision inference.
FeyNoBg's project address
- Project official website:https://usefeyn.com/blog/feynobg/
- GitHub repository:https://github.com/feyninc/nobg
- HuggingFace model library:https://huggingface.co/feyninc/FeyNobg
Application Scenarios of FeyNoBg
- E-commerce product image processingFeyNoBg can batch remove product backgrounds and generate transparent base images, which can be directly used for listing and display on e-commerce platforms.
- Advertising and marketing designDesigners can use FeyNoBg to quickly extract people or product subjects and composite them into a new background to create promotional posters.
- Post-production chroma keying in film and televisionFeyNoBg supports high-precision background removal for 4K and 8K video frames, replacing traditional green screen shooting and post-production keying processes.
- ID photo retouchingUsers can use FeyNoBg to automatically separate people from complex backgrounds, change the background color, and optimize edge details such as hair.
- AI training data generationFeyNoBg can generate high-quality foreground mask annotation data in batches for downstream tasks such as image synthesis and generative models.