BiRefNet Portrait TensorRT is a high-performance background removal model optimized for NVIDIA GPUs using TensorRT. It delivers 5.3x speedup over standard PyTorch inference with a median latency of 123ms at 1024x1024 resolution (RTX 3060, FP16).
This model is a TensorRT-optimized version of BiRefNet trained specifically for portrait matting, ideal for real-time selfie and photo background removal applications.
Model type: Image Segmentation / Portrait Matting
License: See original BiRefNet repository for license details
Selfie background removal - Real-time processing of portrait photos
Video conferencing - Virtual background for live video
Photo editing - Batch background removal for portrait photography
Portrait matting - High-quality alpha extraction for compositing
Limitations
Input constraints: Optimized for 1024×1024 resolution; resizing required for other sizes
Subject matter: Trained primarily on human portraits; performance may vary on non-human subjects
Background complexity: Works best with distinct foreground/background separation
Hardware: Requires NVIDIA GPU with TensorRT support
Batch size: Currently optimized for single-image inference (batch=1)
How to Get Started with the Model
This TensorRT engine file (birefnet_portrait.trt) can be used in two ways:
Option 1: Using Transformers (Recommended for Python)
python
1from transformers import pipeline
23# Load the pipeline with TensorRT support4remover = pipeline("image-segmentation", model="israellaguan/birefnet-portrait-tensorrt")56# Process an image7result = remover("input.jpg")
Option 2: Using Official TensorRT APIs
For production deployment or C++ applications, use the official TensorRT runtime as documented in the NVIDIA TensorRT Quick Start Guide:
python
1import tensorrt as trt
2import pycuda.driver as cuda
3import pycuda.autoinit
45# Load engine6logger = trt.Logger(trt.Logger.WARNING)7withopen("birefnet_portrait.trt","rb")as f:8 runtime = trt.Runtime(logger)9 engine = runtime.deserialize_cuda_engine(f.read())1011# Create execution context12context = engine.create_execution_context()1314# Allocate buffers and run inference15# See NVIDIA TensorRT documentation for complete examples
Option 3: Using the Provided Python Package
This repository includes a complete Python package in the rmbg/ folder with CLI and API for running the TensorRT model. See rmbg/README.md for detailed usage:
bash
1# CLI usage2python -m rmbg.cli process input.jpg -o output/
34# With options5python -m rmbg.cli process input.jpg -o output/ --verbose --warmup
The rmbg/ package provides:
CLI tool (cli.py) - Command-line interface with progress bars
Python API (tools/) - Pipeline and BackgroundRemover classes
Portrait model (used here):BiRefNet-portrait-epoch_150.pth
General purpose:BiRefNet-general-epoch_240.pth
High-resolution matting: Various task-specific models available
Note on prior work: Previous BiRefNet TensorRT implementations (lbq779660843/BiRefNet-Tensorrt and yuanyang1991/birefnet_tensorrt) were published 2 years ago and provide only conversion directions without downloadable pre-built models. This repository provides a ready-to-use TensorRT engine.
Citation
If you use this model, please cite the original BiRefNet paper:
bibtex
1@article{biRefNet2024,
2 title={BiRefNet: Bilateral Reference Network for High-Resolution Dichotomous Image Segmentation},
3 author={Zheng, Peng and Gao, Dehong and Fan, Guolei and Li, Sheng and Sarkar, Berihun},
4 journal={arXiv preprint},
5 year={2024}
6}