SuperAPI AI Directory

FeyNoBg - Feyn Labs' open-source automatic background removal model

Author: AI小集 · Original source: AI工具集

What is FeyNoBg

FeyNoBg is an open-sourceautomatic background removalmodel from Feyn Labs, deeply improved based on the BiRefNet architecture, with 263 million parameters. In 8 benchmark tests including UHRSD-TE and HRSOD-TE, the model achieved SOTA results in 4, and the remaining 4 are within 2% of the best results. The team has also open-sourced the NoBg Python library, providing a unified interface for model running and training, supporting the Hugging Face ecosystem, and using the Apache-2.0 license.

FeyNoBg

FeyNoBg's main features

  • High-precision background removal: automatically identifies image foreground and generates an Alpha mask, supporting complex edges such as hair, fur, and thin lines.
  • Ultra-high-resolution support: leads in the UHRSD-TE benchmark covering 4K and 8K scenarios.
  • Image and video matting: supports background removal for single images, batches of images, and video frame sequences.
  • Open source and trainable: can be fine-tuned on custom datasets via the NoBg library, supporting replacement of loss functions and adjustment of resolution.
  • Hugging Face integration: both the model and processor are compatible with the transformers ecosystem, supporting one-click download and push.

FeyNoBg's technical principles

  • BiRefNet dual-module architecture: the localization module is responsible for foreground recognition, and the reconstruction module is responsible for boundary tracking; the two complement and cooperate with each other.
  • Deep expansion of the third stage: expands the third stage of the feature extractor from 18 blocks to 24 blocks, increasing parameters from 222 million to 263 million, retaining the original pretrained weights, and training only the newly added blocks from scratch to avoid knowledge forgetting.
  • Diverse data mixing: integrates 26,100 images from 10 datasets, covering crowded scenes, camouflage, high resolution, portraits, anime, and other types, with a cap of 4,000 images per source to prevent any single dataset from dominating.
  • Unified annotation format: uniformly converts the foreground masks of segmentation datasets and the Alpha channels of matting datasets into binary foreground masks, making the training objective consistent.
  • S-measure evaluation: uses the S-measure metric in the 0-1 range to reward both subject completeness and shape fidelity.
Dig into GitHub

Follow WeChat and reply "open source" to join theAI open-source project communication group

How to use FeyNoBg

  • Install the environment: install the library via pip install nobg , and ensure that Python ≥ 3.10 and torch ≥ 2.0 environments are ready.
  • Load the model: use AutoModel.from_pretrained("feyninc/FeyNobg") to download and load the pretrained weights from Hugging Face.
  • Load the processor: use AutoProcessor.from_pretrained("feyninc/FeyNobg") to initialize the image preprocessing module.
  • Read the image: convert the target image to RGB format to ensure the input meets the model's requirements.
  • Preprocess: call the processor to resize and normalize the image, generating the tensor input required by the model.
  • Model inference: under torch.inference_mode() , pass pixel_values into the model to obtain the raw output for background removal.
  • Post-process the mask: use post_process_alpha_matting Restore the model output to an Alpha mask of the original image size.
  • Generated result: Call the cutout method to composite the original image foreground with the Alpha mask, and save it as a transparent PNG file.

Core advantages of FeyNoBg

  • SOTA performance: Leads in 4 out of 8 benchmarks, with significant advantages in ultra-high-resolution scenarios.
  • Knowledge-preserving training: Preserves the original weights when extending network depth, avoiding catastrophic forgetting.
  • Engineering optimization: The NoBg library outperforms the original BiRefNet implementation at batch sizes 1/2/4, with higher throughput, lower latency, and less VRAM usage.
  • Ecosystem compatibility: Deeply integrates with Hugging Face transformers, supporting Trainer, Hub push, and half-precision inference.

FeyNoBg project address

  • Project website:https://usefeyn.com/blog/feynobg/
  • GitHub repository:https://github.com/feyninc/nobg
  • HuggingFace model library:https://huggingface.co/feyninc/FeyNobg

FeyNoBg application scenarios

  • E-commerce product image processing: FeyNoBg can batch-remove product backgrounds and generate transparent-background images, directly usable for listing and display on e-commerce platforms.
  • Advertising and marketing design: Designers can use FeyNoBg to quickly extract people or product subjects and composite them onto new backgrounds to create promotional posters.
  • Film and television post-production keying: FeyNoBg supports high-precision background removal for 4K and 8K video frames, and can replace traditional green-screen shooting and post-production keying workflows.
  • ID photo retouching: Users can use FeyNoBg to automatically separate people from complex backgrounds, change the background color, and optimize edge details such as hair strands.
  • AI training data generation: FeyNoBg can batch-produce high-quality foreground mask annotation data for downstream tasks such as image compositing and generative models.