DEV Community

Cover image for A beginner's guide to the Birefnet_portrait model by M-Kunz on Replicate
aimodels-fyi
aimodels-fyi

Posted on Originally published at aimodels.fyi

A beginner's guide to the Birefnet_portrait model by M-Kunz on Replicate

This is a simplified guide to an AI model called Birefnet_portrait maintained by M-Kunz. If you like these kinds of analysis, you should join AImodels.fyi or follow us on Twitter.

Overview

birefnet_portrait is a background removal model specialized for human portraits, built on the BiRefNet architecture developed by m-kunz. The model implements bilateral reference mechanisms for high-resolution dichotomous image segmentation, originally published as "Bilateral Reference for High-Resolution Dichotomous Image Segmentation" in CAAI AIR 2024. This portrait-specific variant fine-tunes the general BiRefNet approach to prioritize accuracy on human faces and upper-body compositions, making it substantially better at preserving fine hair details, facial edges, and clothing boundaries compared to general-purpose background removal tools. The model supports configurable input sizes (default 1024×1024) and can return either the masked image with transparent background or the segmentation mask itself. It runs on Replicate's infrastructure, making it accessible via API without requiring local GPU resources.

Best use cases

Professional portrait photography editing: Use this model to quickly remove backgrounds from headshots, corporate portraits, and professional photography galleries. The model preserves fine facial details and hair strands that generic background removal often destroys, producing results suitable for printing or professional portfolios without extensive manual touch-up work.

E-commerce product photos with human models: Remove backgrounds from fashion, jewelry, and cosmetics product images where a model is wearing or demonstrating the product. The portrait-specific training ensures that clothing edges and skin tones remain sharp while the background disappears cleanly, enabling consistent product catalog images without hiring a full photography studio.

Social media profile pictures and avatars: Generate clean, transparent-background versions of profile images for LinkedIn, Discord, game avatars, and streaming platforms. The model handles varied lighting conditions and head angles common in casual portrait photography, producing results that work well at both thumbnail and full-size scales.

Dating app and networking profile photos: Remove distracting or unprofessional backgrounds from personal photos while maintaining the most flattering representation of the subject's face and upper body. The portrait optimization ensures skin tone accuracy and natural-looking edges around facial features, critical for applications where first impressions matter.

Podcast and video creator assets: Extract clean headshot images from video frames or casual photos to use as overlays, thumbnails, or guest cards in streaming content. The model's speed and consistent quality enable batch processing of multiple photos, useful for creator tooling that needs automated asset generation.

Limitations

The model's portrait-specific optimization creates its primary limitation: it performs poorly on non-human subjects. Backgrounds in images containing animals, objects, or mixed scenes where the person is not the dominant subject will not segment correctly. The model assumes human faces or upper-body portraits as the primary foreground content.

Input resolution is constrained to the configurable size parameter (default 1024×1024). While the underlying BiRefNet architecture supports variable resolutions, this particular Replicate deployment uses fixed square sizes. Very wide aspect ratio images (panoramas) or extremely high-resolution source images will be downsampled or cropped to fit, potentially losing context or requiring multiple API calls.

The model struggles with transparent or semi-transparent foreground elements—glass, water, smoke, or translucent clothing. It performs binary segmentation (foreground/background) rather than alpha matting, so fine transparency gradients are lost. The output is either fully opaque or fully transparent for each pixel.

Complex hair with wispy edges, curly textures, or backlit rim lighting present challenges. While better than generic models, the portrait-specific training still has difficulty with individual hair strands extending into the background, sometimes producing visible halos or over-aggressive cropping around hair boundaries.

The model requires images where the person occupies a meaningful portion of the frame. Distant shots, group photos where multiple people compete for attention, or images where the subject is heavily obscured will produce suboptimal results.

Processing speed depends on the configured input size. At default 1024×1024, inference completes quickly on modern GPUs, but requesting larger sizes (up to 2K+ on the general BiRefNet variants) increases latency and compute requirements.

How it compares

birefnet by sprited offers the complete BiRefNet ecosystem with all 10 official model variants plus the ToonOut anime specialist, giving you the flexibility to choose between general-purpose, high-resolution, matting, and anime-specific models from a single endpoint. Choose birefnet_portrait if you exclusively process human portraits and want a model pre-optimized for that use case with reliable edge quality on faces; choose the full birefnet if you need the flexibility to switch between models or process mixed content types without redeploying.

birefnet-toonout by sprited specializes in anime and cartoon character backgrounds removal, making it the right choice for illustration, manga, and animated content. birefnet_portrait targets photorealistic human faces and bodies, so use this model for photograph-based content and reserve ToonOut for digital art and animated media.

remove-bg by fottoai provides custom model support for improved results on specific use cases. If you have proprietary requirements or custom training data, remove-bg's flexibility may exceed birefnet_portrait's fixed optimization; however, for standard portrait removal without customization, the portrait-specific tuning in this model typically produces better results faster and more directly.

bshm-portrait by twn39 targets portrait segmentation with similar intentions. Both models focus on human portraits, but birefnet_portrait benefits from the broader BiRefNet research foundation and active maintenance from the original paper authors, potentially offering better edge quality and more consistent performance across diverse portrait styles.

portraitplus_lora by cloneofsimo is a LoRA-based portrait enhancement tool designed for stylization and improvement rather than background removal. Choose birefnet_portrait specifically for background removal; use portraitplus_lora if you need portrait enhancement, relighting, or style transfer applied after background removal.

Technical specifications

BiRefNet uses a hierarchical architecture with a Swin Transformer backbone and bilateral reference modules that progressively refine segmentation masks at multiple scales. The model employs a multi-scale refinement strategy that processes image features at different resolutions simultaneously, enabling high-fidelity edge preservation without excessive computational cost.

The portrait-specific variant is a fine-tuned adaptation of the general BiRefNet model, trained on portrait-focused datasets to emphasize facial features, hair boundaries, and upper-body contours. The underlying architecture supports both standard PyTorch inference and ONNX export formats.

Key technical parameters:

  • Input size: configurable array of integers (default [1024, 1024]), accepts variable resolutions as square or rectangular dimensions
  • Output: URI-formatted segmented image or mask file
  • Model format: PyTorch with FP16 inference support available on compatible hardware
  • Memory efficiency: The general BiRefNet model runs in approximately 3.45GB GPU memory at 1024×1024 resolution on RTX 4090 hardware
  • Processing speed: Achieves approximately 17 FPS at 1024×1024 resolution on RTX 4090 with FP16 inference
  • Supported input formats: Common image formats (JPEG, PNG, WebP) via URI
  • Output format: PNG with alpha channel for transparent backgrounds, or binary mask as grayscale PNG
  • License: MIT (permissive for commercial use)
  • Training approach: BiRefNet was trained on diverse image datasets covering general objects, high-resolution salient objects, transparent objects, camouflaged objects, and portraiture; the portrait variant applies additional fine-tuning specifically on portrait datasets

Model inputs and outputs

Inputs

  • image (string, URI format, required): Input image URL or path. Accepts JPEG, PNG, WebP, and other common image formats.
  • size (array of integers, default [1024, 1024]): Dimensions for inference as [height, width]. Controls the resolution at which the model processes the image. Larger values increase precision but also increase computation time and memory requirements.
  • mask (boolean, default false): When false, returns the original image with background removed (transparent PNG). When true, returns only the binary segmentation mask as a grayscale image.

Outputs

  • Output (string, URI format): Returns a URI pointing to the processed image file. The file format depends on the mask parameter: a PNG with alpha transparency when mask=false, or a grayscale mask PNG when mask=true.

Getting started

import replicate

# Remove background from a portrait image
input_image_url = "https://example.com/portrait.jpg"

output = replicate.run(
    "m-kunz/birefnet_portrait:67e9d8d9e625ad68308740f5a0ed2b7dd1b5a94daa6c46eca1d08ea9313f4486",
    input={
        "image": input_image_url,
        "size": [1024, 1024],
        "mask": False
    }
)

print(f"Background removed image: {output}")

# Get only the segmentation mask
mask_output = replicate.run(
    "m-kunz/birefnet_portrait:67e9d8d9e625ad68308740f5a0ed2b7dd1b5a94daa6c46eca1d08ea9313f4486",
    input={
        "image": input_image_url,
        "size": [1024, 1024],
        "mask": True
    }
)

print(f"Segmentation mask: {mask_output}")
Enter fullscreen mode Exit fullscreen mode

Frequently asked questions

Q: Can I use this model for commercial applications?

A: Yes. The model is licensed under the MIT license, which permits commercial use, modification, and distribution as long as you include the original license notice. This makes it suitable for production applications, SaaS tools, and commercial products.

Q: What happens if I submit an image with multiple people in it?

A: The model is optimized for single-subject portraits. With multiple people in the frame, it may treat the entire group as foreground, remove only parts of the background inconsistently, or produce unpredictable results. For best results, submit headshots or images where one person is clearly dominant.

Q: How does the "size" parameter affect output quality?

A: The size parameter controls the resolution at which the model processes your image. Larger sizes (e.g., [2048, 2048]) preserve finer details like individual hair strands and facial features but increase processing time and memory usage. Default 1024×1024 balances quality and speed for most portrait use cases. If your source image is larger than the specified size, it will be downsampled; if smaller, it will be upsampled, which may reduce quality.

Q: What's the difference between mask=true and mask=false?

A: With mask=false (default), you get your original portrait image with the background made transparent (suitable for compositing or direct use). With mask=true, you get only the binary segmentation mask as a grayscale image where white represents the person and black represents the background—useful for post-processing, refining, or feeding into other computer vision pipelines.

Q: Does this model work with black and white or very low-contrast portraits?

A: The model handles grayscale images, but segmentation performance may degrade with very low contrast or silhouette-style portraits where facial features lack tonal separation from the background. It performs best on portraits with clear lighting that defines the subject's edges against the background.

Q: Can I use this model for video background removal?

A: This model processes individual images. For video, you would need to extract frames, process each frame individually via the API, and reassemble them—which is feasible but not optimized for video workflows. The underlying BiRefNet repository includes video inference examples if you need lower-latency processing.

Q: How does this compare to dedicated matting models?

A: birefnet_portrait performs binary segmentation (fully opaque or fully transparent), while matting models produce alpha channel gradients for semi-transparent areas. For sharp, solid background removal on portraits, this model excels. For complex cases with transparent elements, feathered edges, or professional-grade compositing that requires precise alpha values, a dedicated matting model would be better suited. The BiRefNet library does include a matting variant (BiRefNet-matting) available through other implementations for that use case.

Click here to read the full guide to Birefnet_portrait

Top comments (0)