Back to Model List

FeyNoBg – An Open-Source Automatic Background Removal Model from Feyn Labs

AI Tech Editorial
RSS Feed
FeyNoBg – An Open-Source Automatic Background Removal Model from Feyn Labs official screenshot
(Image source: official screenshot)

Executive Summary:

FeyNoBg is an open-source automatic background removal model developed by Feyn Labs, built upon the BiRefNet architecture with deep optimization, and features 263 million parameters. The model achieve...

1. What is FeyNoBg

FeyNoBg is an open-source automatic background removal model developed by Feyn Labs, built upon the BiRefNet architecture with deep optimization, and features 263 million parameters. The model achieves state-of-the-art (SOTA) results in four out of eight benchmark tests, including UHRSD-TE and HRSOD-TE, and performs within 2% of the best results in the remaining four. Additionally, the team has open-sourced the NoBg Python library, which provides a unified interface for model execution and training, deeply integrated with the Hugging Face ecosystem, and is released under the Apache-2.0 open-source license, significantly lowering the barrier for developers to perform secondary development.

feynobg-feyn-labs official website screenshot
Image source: Official article
Image source: official article

Technical positioning and domain: It belongs to the image segmentation and matting domain in computer vision, focusing specifically on high-precision, high-resolution automatic background removal tasks. Unlike traditional matting models, FeyNoBg has been specially optimized for 4K/8K ultra-high-resolution scenarios and complex edges (such as hair strands and fur), achieving leading performance in multiple benchmarks.

Development background: Developed by the Feyn Labs team based on in-depth research into the BiRefNet architecture. The team found that the original BiRefNet had performance limitations in ultra-high-resolution scenarios, so they enhanced the model's capabilities by expanding network depth and improving training strategies, and chose to open-source it to promote community development.

Core value: It addresses the issue of insufficient accuracy in existing open-source background removal models for high-resolution and complex foreground edge scenarios. At the same time, it provides the unified training library NoBg, enabling researchers and developers to easily fine-tune or train models on custom datasets, avoiding the tedious process of building training pipelines from scratch.

Technical features: Key innovations include expanding the depth of the third stage of BiRefNet (from 18 blocks to 24 blocks) while retaining pre-trained weights to prevent catastrophic forgetting; training with a mix of 10 datasets covering a wide range of scenarios; and using the S-measure evaluation metric to simultaneously focus on subject integrity and shape fidelity.

2. Key Features

  • High-precision background removal: Automatically identifies the image foreground and generates an Alpha mask, with precise handling of complex edges such as hair, fur, and fine lines, producing high-quality images with transparent backgrounds. Compared to traditional color-key-based background removal methods, this approach demonstrates stronger robustness for irregular edges.

  • Ultra-high resolution support: The model outperforms on benchmarks such as UHRSD-TE for ultra-high resolution, capable of processing 4K and 8K images without detail loss, making it suitable for professional film and photography post-production.

  • Image and video background removal: Supports background removal for single images, batch images, and video frame sequences. Users can process video frame by frame to achieve background replacement effects, eliminating the need for green screen filming.

  • Open source and trainable: Through the NoBg library, users can fine-tune the model on custom datasets, with flexible configurations such as replacing the loss function and adjusting input resolution, meeting optimization needs for specific scenarios.

  • Hugging Face integration: The model and processor are fully compatible with the Hugging Face transformers ecosystem, supporting one-click download, loading, and pushing, facilitating integration with existing workflows.

  • Knowledge-preservation training strategy: When expanding network depth, the pre-trained weights of the original BiRefNet are retained, with only the newly added blocks trained from scratch. This effectively prevents catastrophic forgetting and ensures the model maintains its existing capabilities while improving performance.

  • Engineering optimization and high-performance inference: The NoBg library performs better than the original BiRefNet implementation across batch sizes of 1, 2, and 4, offering higher throughput, lower latency, and reduced memory usage, making it suitable for deployment in production environments.

  • Diverse data mixture training: Integrates 10 datasets containing a total of 26,100 images, covering types such as crowded scenes, camouflage, high resolution, portraits, and anime, with a maximum of 4,000 images from each source to prevent dominance by a single dataset and enhance the model's generalization ability.

3. How to Use

  1. Environment Requirements and Installation: Ensure that the Python version is ≥ 3.10, PyTorch ≥ 2.0, and CUDA is installed (NVIDIA GPU is recommended, with at least 4GB of video memory). Install the NoBg library and its dependencies using the command pip install nobg. If training functionality is required, additional dependencies (such as wandb, tensorboard, etc.) must also be installed.

  2. Model and Processor Loading: Use Hugging Face transformers to load the pre-trained model and processor:

    from transformers import AutoModel, AutoProcessor
    model = AutoModel.from_pretrained("feyninc/FeyNobg")
    processor = AutoProcessor.from_pretrained("feyninc/FeyNobg")
    

    The weights will be automatically downloaded during the first load, and can then be used offline.

  3. Image Preprocessing: Read the target image and convert it to RGB format. Use the processor to resize and normalize the image, generating the tensor input pixel_values required by the model. The processor defaults to resizing the image to the input size used during model training (e.g., 1024×1024), but this can be adjusted via parameters.

  4. Model Inference and Post-processing: Pass pixel_values into the model within the torch.inference_mode() context to obtain the raw output. Then use the post_process_alpha_matting method to restore the output to the original image size as an Alpha mask. Finally, use the cutout method to composite the foreground of the original image with the Alpha mask, saving the result as a transparent PNG file. Example code:

    import torch
    from PIL import Image
    inputs = processor(images=image, return_tensors="pt")
    with torch.inference_mode():
        outputs = model(**inputs)
    alpha = processor.post_process_alpha_matting(outputs, target_size=image.size)
    result = processor.cutout(image, alpha)
    result.save("output.png")
    
  5. Video Frame Processing (Optional): For video matting, read each frame of the video individually, apply the above process to each frame, and then reassemble the video. Note that temporal consistency between frames may require additional processing, such as using optical flow or temporal smoothing.

  6. Custom Training (Advanced): Use the training interface provided by the NoBg library. Prepare a custom dataset (images + foreground masks), adjust parameters such as the loss function and resolution in the configuration file, and launch the training script for fine-tuning. Specific instructions can be found in the examples and documentation within the GitHub repository.

4. Pros and Cons Analysis

Pros
SOTA Performance: Achieved optimal results in 4 out of 8 benchmark tests, with significant advantages in ultra-high resolution scenarios and outstanding capabilities in handling complex edges.
Open Source and Trainable: Licensed under the Apache-2.0 protocol, the NoBg training library is provided, supporting custom fine-tuning and reducing the threshold for secondary development.
Excellent Engineering Optimization: The NoBg library outperforms the original BiRefNet implementation in throughput, latency, and memory usage, making it suitable for production deployment.
Strong Ecosystem Compatibility: Deeply integrated with Hugging Face transformers, allowing one-click loading and pushing, which facilitates integration into existing workflows.

5. Comparative Analysis with Similar Tools

Comparison Dimension FeyNoBg rembg MODNet
Core Architecture Improved BiRefNet with deep expansion in the third stage U2Net, fully convolutional encoder-decoder Lightweight real-time matting network with MobileNetV2 backbone
Number of Parameters 263 million Approximately 40 million Approximately 6 million
Benchmark Performance 4 SOTA results in 8 benchmarks, others <2% difference Performs well on simple backgrounds, poor on complex edges High real-time performance, but average accuracy
High-Resolution Support Specifically optimized, leading in 4K/8K Does not support ultra-high resolution, commonly used in low resolution Does not support high resolution
Training Flexibility Open-source training library, supports custom fine-tuning Provides training code, but requires self-adaptation Provides training code, but requires self-adaptation
Open Source License Apache-2.0 MIT MIT
Community Ecosystem Newer, integrated with Hugging Face Mature community, widely used Active community, lightweight

Selection Recommendations: If high accuracy and high-resolution support are priorities, especially for processing 4K/8K images and complex edges (e.g., hair), FeyNoBg is a strong open-source option, although it has a larger parameter count and requires a mid-to-high-end GPU. For lightweight real-time matting in mobile or live streaming scenarios, MODNet is more suitable, albeit with some compromise in accuracy. rembg is ideal for quick and simple background removal with low hardware requirements, but its effectiveness is limited in complex scenarios. BackgroundMattingV2 offers high accuracy when background frames are available, but its application is restricted. For teams with customization needs, FeyNoBg's trainability provides greater flexibility.

6. Editor's Summary

FeyNoBg demonstrates solid innovation on a technical level. Its core improvement—extending the depth of the third stage of BiRefNet while retaining pre-trained weights—cleverly balances model capacity with knowledge preservation, avoiding the common issue of catastrophic forgetting in large-scale training. The diverse data mixing strategy and unified annotation format further enhance the model's generalization ability, enabling it to achieve or even surpass the current state-of-the-art performance on multiple benchmark tests. In terms of practical value, FeyNoBg not only provides high-precision background removal capabilities, but also significantly lowers the barriers to usage and secondary development through the NoBg library and Hugging Face integration, making both direct inference and custom training relatively convenient. Its target users span multiple groups, including e-commerce designers, film and video post-production professionals, and AI researchers, particularly those requiring high-resolution performance in professional scenarios. In the future, with increased community contributions and improved documentation, FeyNoBg has the potential to make further breakthroughs in areas such as temporal optimization for video matting and handling of semi-transparent objects, becoming a significant open-source force in the background removal field.

7. Application Scenarios

  • E-commerce Product Image Processing: Merchants can use FeyNoBg to batch remove product backgrounds and generate images with transparent backgrounds, which can be directly used for e-commerce platform displays. Its high-precision edge processing capabilities ensure clear product outlines, eliminating the need for manual refinement and significantly improving work efficiency.

  • Advertising and Marketing Design: Designers can leverage FeyNoBg to quickly extract human subjects or product elements and composite them onto creative backgrounds to produce promotional posters. It supports high-resolution images, ensuring rich detail even when scaled up.

  • Film and Video Post-production Keying: For 4K/8K video frames, FeyNoBg can perform background removal on a frame-by-frame basis, replacing traditional green screen filming. In complex scenarios (such as hair or transparent objects), its Alpha matte quality surpasses that of conventional chroma keying.

  • ID Photo Refinement: Users can automatically separate subjects from backgrounds using FeyNoBg to change the background color and optimize hair strand edges, resulting in ID photos that meet standard requirements.

  • AI Training Data Generation: It can generate high-quality foreground mask annotation data in bulk for downstream tasks such as image synthesis and generative adversarial networks, reducing the cost of manual annotation.

8. FAQ

Q: What hardware requirements does FeyNoBg have?
A: It is recommended to use an NVIDIA GPU with CUDA support and at least 4GB of VRAM. For 4K image processing, VRAM of 8GB or more is recommended. CPU inference is slower and only suitable for small-sized images.

Q: Does it support batch processing of images?
A: Yes. You can process multiple images at once by looping through the model with a script or using the batch processing feature provided by the NoBg library.

Q: How to handle video background removal?
A: You need to read the video frame by frame, apply background removal to each frame, and then reassemble the video. There is currently no temporal optimization for video streams, but post-processing can reduce flickering.

Q: Can the model be fine-tuned on a custom dataset?
A: Yes. The NoBg library provides a training interface. Users need to prepare images and their corresponding foreground masks (binary images), adjust the configuration file, and then run the training script. Specific formats can be referenced from the example in the GitHub repository.

Q: What advantages does FeyNoBg have over rembg?
A: FeyNoBg achieves significantly higher accuracy in ultra-high resolution and complex edge scenarios (such as hair). It also supports training and fine-tuning. However, the model parameters are larger, and the inference speed is slower than rembg, making it suitable for scenarios with high quality requirements.

Q: Does the model support half-precision inference for acceleration?
A: Yes. Since it is compatible with Hugging Face transformers, you can load the half-precision version (fp16) for inference, reducing VRAM usage and improving speed.

9. Project Links

Related AI Model Articles

© All Rights Reserved. Some content on this site is partially generated by AI with human review.