How to use from the
Use from the
TensorRT library
# No code snippets available yet for this library.

# To use this model, check the repository files and the library's documentation.

# Want to help? PRs adding snippets are welcome at:
# https://github.com/huggingface/huggingface.js

ORMBG TensorRT

TensorRT engines of ORMBG, made by Moonbox for NVIDIA RTX GPUs. Each precision is one folder holding the engine, trt_runner.py (a small numpy runner: TensorRT plus Polygraphy, no PyTorch) and a script that does the rest of the pipeline. What the engine takes and returns is under How to run.

Compatibility. The engines are built hardware compatible (Ampere and newer: RTX 30, 40 and 50 series) and version compatible (any TensorRT 10.x from 10.13 on, through its lean runtime). That costs a little speed against an engine built for one GPU, but no rebuild is needed. Install the runtime with pip install "tensorrt-cu12>=10.13,<11" "tensorrt-lean-cu12>=10.13,<11" polygraphy numpy.

Files

The last column is the benchmark (details under How to run).

Precision File Size sha256 Benchmark
fp16 fp16/config.json 0.0 kB 5b1a91adebb1 vs fp32: IoU 0.9969, MAE 0.0005; DIS5K MAE 0.1461, S 0.720; 197 ms a picture (ONNX fp16 176 ms), 461 MiB
fp16 fp16/cutout_trt.py 1.7 kB 5c0a5d2a60e5 vs fp32: IoU 0.9969, MAE 0.0005; DIS5K MAE 0.1461, S 0.720; 197 ms a picture (ONNX fp16 176 ms), 461 MiB
fp16 fp16/model.engine 142.2 MB a6e9c7b72e89 vs fp32: IoU 0.9969, MAE 0.0005; DIS5K MAE 0.1461, S 0.720; 197 ms a picture (ONNX fp16 176 ms), 461 MiB
fp16 fp16/trt_runner.py 2.2 kB efa8ba97631b vs fp32: IoU 0.9969, MAE 0.0005; DIS5K MAE 0.1461, S 0.720; 197 ms a picture (ONNX fp16 176 ms), 461 MiB

How to run

ORMBG (trained for pictures of people) as a TensorRT engine built from Moonbox's fp16 ONNX graph of the official model.

import sys
from PIL import Image
sys.path.insert(0, "fp16")
import json, cutout_trt
from trt_runner import Engine
e = Engine("fp16/model.engine")
cfg = json.load(open("fp16/config.json"))
img = Image.open("photo.jpg").convert("RGB")
img.putalpha(cutout_trt.matte(e, img, cfg)); img.save("cutout.png")

Or python fp16/cutout_trt.py photo.jpg cutout.png. The engine takes the picture resized to 1024 x 1024, RGB in 0-1 with no normalization (RGB in 0-1), as [1, 3, 1024, 1024]. It returns the matte as output 0 (the others are side outputs), rescaled to 0-1 as the original inference does. cutout_trt.py resizes the matte back to the picture's size.

Precisions. fp16 only: the fp16 ONNX graph's weights and math (fp32 inputs and outputs). No int8: the ONNX int8 build is weight-only, while TensorRT's int8 needs calibrated activations.

Benchmark.

  • Data: the DIS5K test sets, 250 pictures (DIS-TE1..4 and DIS-VD, 50 each), on an RTX 3080 Laptop GPU.
  • Fidelity: agreement with the fp32 ONNX graph's mattes: IoU of the masks at 0.5, mean absolute difference.
  • Quality: MAE and S-measure against the ground truth (PySODMetrics, on masks shrunk to at most 2048 px).
  • Pass mark: MAE <= 0.005 and IoU >= 0.98 against fp32, as for this model's other builds.
vs fp32: IoU / MAE DIS5K MAE / S-measure ms a picture peak GPU memory
ONNX fp32 (reference) - 0.1462 / 0.720 197 1717 MiB
ONNX fp16 0.9986 / 0.0003 0.1461 / 0.720 176 836 MiB
TensorRT fp16/ 0.9969 / 0.0005 0.1461 / 0.720 197 461 MiB

The times are medians per picture, including the resizing to and from 1024 x 1024. The ONNX rows used ONNX Runtime's CUDA provider.

How these were made

From ORMBG at revision 6253b31824: each engine was built with TensorRT's builder from Moonbox's published ONNX graph of the same model and precision. The network is strongly typed: every tensor keeps the precision the ONNX graph gives it, so an fp16 engine computes what the fp16 ONNX build computes. Built on an RTX 3080 Laptop GPU, it was benchmarked against the original before upload, and the sha256 column above is what the files must hash to.

License

Apache-2.0. These files are a derivative of the original model and carry its license: it is copied in this repository, and it governs your use of these files. The original model card follows unchanged.


Original model card

Open Remove Background Model (ormbg)

>>> DEMO <<<

Join our Research Discord Group!

This model is a fully open-source background remover optimized for images with humans. It is based on Highly Accurate Dichotomous Image Segmentation research.

Inference

python ormbg/inference.py

Training

Install dependencies:

conda env create -f environment.yaml
conda activate ormbg

Replace dummy dataset with training dataset.

python3 ormbg/train_model.py

Research

I started training the model with synthetic images of the Human Segmentation Dataset crafted with LayerDiffuse. However, I noticed that the model struggles to perform well on real images.

Synthetic datasets have limitations for achieving great segmentation results. This is because artificial lighting, occlusion, scale or backgrounds create a gap between synthetic and real images. A "model trained solely on synthetic data generated with naïve domain randomization struggles to generalize on the real domain", see PEOPLESANSPEOPLE: A Synthetic Data Generator for Human-Centric Computer Vision (2022).

Next steps:

  • Expand dataset with synthetic and real images
  • Research on state of the art loss functions

Latest changes (26/07/2024):

  • Created synthetic dataset with 10k images, crafted with BlenderProc
  • Removed training data created with LayerDiffuse, since it lacks the accuracy needed
  • Improved model performance (after 100k iterations):

05/07/2024

  • Added P3M-10K dataset for training and validation
  • Added AIM-500 dataset for training and validation
  • Added PPM-100 dataset for training and validation
  • Applied Grid Dropout to make the model smarter
Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for moonbox-dev/ormbg-TensorRT

Quantized
(9)
this model

Paper for moonbox-dev/ormbg-TensorRT