Instructions to use moonbox-dev/efficientvit-TensorRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TensorRT
How to use moonbox-dev/efficientvit-TensorRT with TensorRT:
# 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
- Notebooks
- Google Colab
- Kaggle
|
Download README.md from moonbox-dev/efficientvit-TensorRT: direct link, hf CLI and curl.
- Browser
- Download file 19.6 kB
-
https://huggingface.co/moonbox-dev/efficientvit-TensorRT/resolve/main/README.md
- Command line
-
hf download hf://moonbox-dev/efficientvit-TensorRT/README.md
-
curl -L -o README.md https://huggingface.co/moonbox-dev/efficientvit-TensorRT/resolve/main/README.md
19.6 kB
| license: apache-2.0 | |
| pipeline_tag: mask-generation | |
| library_name: tensorrt | |
| tags: | |
| - tensorrt | |
| - moonbox | |
| - efficientvit | |
| - efficientvit-sam | |
| - segment-anything | |
| - image-segmentation | |
| # EfficientViT-SAM TensorRT | |
| TensorRT engines of [EfficientViT-SAM](https://github.com/mit-han-lab/efficientvit), 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 | | |
| |---|---|---|---|---| | |
| | fp32 | [`fp32/decoder.engine`](https://huggingface.co/moonbox-dev/efficientvit-TensorRT/blob/main/fp32/decoder.engine) | 75.1 MB | `a2e0a324e55b` | no TF32: mask IoU vs the ONNX fp32 build (CPU) 0.9999 mean / 0.9977 worst (32 masks); encoder 19.3 ms vs 43.6 ms | | |
| | fp32 | [`fp32/encoder.engine`](https://huggingface.co/moonbox-dev/efficientvit-TensorRT/blob/main/fp32/encoder.engine) | 293.6 MB | `75711f129358` | no TF32: mask IoU vs the ONNX fp32 build (CPU) 0.9999 mean / 0.9977 worst (32 masks); encoder 19.3 ms vs 43.6 ms | | |
| | fp32 | [`fp32/pipeline.py`](https://huggingface.co/moonbox-dev/efficientvit-TensorRT/blob/main/fp32/pipeline.py) | 4.2 kB | `3cee6dcd2a80` | no TF32: mask IoU vs the ONNX fp32 build (CPU) 0.9999 mean / 0.9977 worst (32 masks); encoder 19.3 ms vs 43.6 ms | | |
| | fp32 | [`fp32/pipeline_trt.py`](https://huggingface.co/moonbox-dev/efficientvit-TensorRT/blob/main/fp32/pipeline_trt.py) | 3.9 kB | `fb1791cf9e66` | no TF32: mask IoU vs the ONNX fp32 build (CPU) 0.9999 mean / 0.9977 worst (32 masks); encoder 19.3 ms vs 43.6 ms | | |
| | fp32 | [`fp32/trt_runner.py`](https://huggingface.co/moonbox-dev/efficientvit-TensorRT/blob/main/fp32/trt_runner.py) | 3.3 kB | `0da2222f799a` | no TF32: mask IoU vs the ONNX fp32 build (CPU) 0.9999 mean / 0.9977 worst (32 masks); encoder 19.3 ms vs 43.6 ms | | |
| ## How to run | |
| EfficientViT-SAM (L0: an EfficientViT image encoder with SAM's mask decoder) as TensorRT engines plus | |
| `pipeline_trt.py`. It follows the repository's EfficientViTSamPredictor like this model's ONNX `pipeline.py`: | |
| - **Picture:** the longest side resized to 512, SAM's pixel mean / std, padded to 512 x 512. | |
| - **Prompts:** given in the 1024 frame; point prompts give three masks, box prompts one. | |
| ```python | |
| import sys | |
| import numpy as np | |
| from PIL import Image | |
| sys.path.insert(0, "fp32") | |
| from pipeline_trt import EfficientViTSAMTrt | |
| p = EfficientViTSAMTrt("fp32") | |
| rgb = np.asarray(Image.open("photo.jpg").convert("RGB")) | |
| emb, size = p.embed(rgb) # the image embedding, once per picture | |
| masks, scores = p.point(emb, size, [[410, 300]]) # 3 masks [3, H, W] (bool) for a foreground point | |
| mask, score = p.box(emb, size, [100, 80, 620, 540]) # 1 mask for a box | |
| ``` | |
| Or `python fp32/pipeline_trt.py photo.jpg masks.npz --point 410 300 --box 100 80 620 540`. It needs numpy, Pillow, | |
| TensorRT and Polygraphy; opencv-python makes the final mask resize fast. | |
| **The engines.** | |
| - `encoder.engine`: `image` [1, 3, 512, 512] -> `image_embeddings` [1, 256, 64, 64]. | |
| - `decoder.engine`: SAM's ONNX decoder wrapper up to its low-resolution masks. | |
| - Inputs: `image_embeddings`, `point_coords` [1, N, 2] with N from 1 to 10, `point_labels`, `mask_input`, | |
| `has_mask_input`. | |
| - Outputs: `iou_predictions` and `low_res_masks` [1, 4, 256, 256]. | |
| - **Resizing to the picture:** `pipeline_trt.py` does it with the same bilinear arithmetic, because TensorRT can't | |
| take the picture size as a float shape input. | |
| **Precisions.** `fp32/` only, as this model's ONNX build: its BatchNorm scales reach 602, and an fp16 build loses | |
| masks (worst IoU 0.12). The engines are built without TF32, full fp32 math. That matters: ONNX Runtime's CUDA | |
| provider uses TF32 by default, and with it this model's worst mask in the benchmark drops to IoU 0.16 against an | |
| exact fp32 run. If you run the ONNX build on CUDA, set `use_tf32` to 0. | |
| **Benchmark.** | |
| - **Data:** the first 8 photos of DIS5K-250, with a point prompt (3 masks) and the box prompt (1 mask) per photo, both | |
| from the ground truth: 32 masks. | |
| - **Run:** the engines through `pipeline_trt.py`, on an RTX 3080 Laptop GPU. | |
| - **Reference:** the ONNX `fp32/` build through its `pipeline.py` on ONNX Runtime's CPU provider (exact fp32). That | |
| build is within IoU 0.999 of the original (EfficientViTSamPredictor, fp32) on every mask. | |
| - **Pass mark:** IoU >= 0.99 against the reference on every mask. | |
| | | mask IoU vs the ONNX build (CPU): mean / worst | encoder alone | | |
| |---|---|---| | |
| | ONNX `fp32/`, CUDA with TF32 off | - | 43.6 ms | | |
| | TensorRT `fp32/` | 0.9999 / 0.9977 | 19.3 ms | | |
| ## How these were made | |
| From [EfficientViT-SAM](https://github.com/mit-han-lab/efficientvit) at revision `de7d7733cc`: 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 | |
| # Efficient Vision Foundation Models for High-Resolution Generation and Perception | |
| [](https://paperswithcode.com/sota/image-generation-on-imagenet-512x512?p=deep-compression-autoencoder-for-efficient) | |
| ## News | |
| - (🔥 New) [2025/09/05] We will no longer maintain this codebase. All future updates and announcements will be made on [DC-Gen](https://github.com/dc-ai-projects/DC-Gen). | |
| - (🔥 New) [2025/01/24] We released DC-AE-SANA-1.1: [doc](https://github.com/mit-han-lab/efficientvit/blob/master/assets/docs/dc_ae_sana_1.1.md). | |
| - (🔥 New) [2025/01/23] DC-AE and SANA are accepted by ICLR 2025. | |
| - (🔥 New) [2025/01/14] We released **DC-AE+USiT models**: [model](https://huggingface.co/collections/mit-han-lab/dc-ae-diffusion-670dbb8d6b6914cf24c1a49d), [training](https://github.com/mit-han-lab/efficientvit/blob/master/applications/dc_ae/README.md#dc-ae--usit). Using the default training settings and sampling strategy, DC-AE+USiT-2B achieves 1.72 FID on ImageNet 512x512, surpassing the SOTA diffusion model EDM2-XXL and SOTA auto-regressive image generative models (MAGVIT-v2 and MAR-L). | |
| ______________________________________________________________________ | |
| - (🔥 New) [2024/12/24] **diffusers** supports DC-AE models. All [DC-AE models in diffusers safetensors](https://huggingface.co/collections/mit-han-lab/dc-ae-670085b9400ad7197bb1009b) are released. [Usage](https://github.com/mit-han-lab/efficientvit/tree/master/applications/dc_ae#deep-compression-autoencoder-diffusers). | |
| - [2024/10/21] DC-AE and EfficientViT block are used in our latest text-to-image diffusion model SANA! Check the [project page](https://nvlabs.github.io/Sana/) for more details. | |
| - [2024/10/15] We released **Deep Compression Autoencoder (DC-AE)**: [link](#deep-compression-autoencoder-for-efficient-high-resolution-diffusion-models-paper-readme)! | |
| - [2024/07/10] EfficientViT is used as the backbone in [Grounding DINO 1.5 Edge](https://arxiv.org/pdf/2405.10300) for efficient open-set object detection. | |
| - [2024/07/10] EfficientViT-SAM is used in [MedficientSAM](https://github.com/hieplpvip/medficientsam), the 1st place model in [CVPR 2024 Segment Anything In Medical Images On Laptop Challenge](https://www.codabench.org/competitions/1847/). | |
| - [2024/04/06] EfficientViT-SAM is accepted by [eLVM@CVPR'24](https://sites.google.com/view/elvm/home?authuser=0). | |
| - [2024/03/19] Online demo of EfficientViT-SAM is available: [https://evitsam.hanlab.ai/](https://evitsam.hanlab.ai/). | |
| - [2024/02/07] We released [EfficientViT-SAM](https://arxiv.org/abs/2402.05008), the first accelerated SAM model that matches/outperforms SAM-ViT-H's zero-shot performance, delivering the SOTA performance-efficiency trade-off. | |
| - [2023/11/20] EfficientViT is available in the [NVIDIA Jetson Generative AI Lab](https://www.jetson-ai-lab.com/tutorial_efficientvit.html). | |
| - [2023/09/12] EfficientViT is highlighted by [MIT home page](https://www.mit.edu/archive/spotlight/efficient-computer-vision/) and [MIT News](https://news.mit.edu/2023/ai-model-high-resolution-computer-vision-0912). | |
| - [2023/07/18] EfficientViT is accepted by ICCV 2023. | |
| ## Content | |
| ### [ICLR 2025] Deep Compression Autoencoder for Efficient High-Resolution Diffusion Models [[paper](https://arxiv.org/abs/2410.10733)] [[readme](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/dc_ae/README.md)] [[poster](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/assets/dc_ae_poster.pdf)] | |
| **Deep Compression Autoencoder (DC-AE) is a new family of high-spatial compression autoencoders with a spatial compression ratio of up to 128 while maintaining reconstruction quality. It accelerates all latent diffusion models regardless of the diffusion model architecture.** | |
| #### Demo | |
|  | |
| <p align="center"> | |
| <b> Figure 1: We address the reconstruction accuracy drop of high spatial-compression autoencoders. | |
| </p> | |
|  | |
| <p align="center"> | |
| <b> Figure 2: DC-AE speeds up latent diffusion models. | |
| </p> | |
| <p align="center"> | |
| <img src="https://huggingface.co/mit-han-lab/dc-ae-f64c128-in-1.0/resolve/main/assets/dc_ae_sana.jpg" width="1200"> | |
| </p> | |
| <p align="center"> | |
| <b> Figure 3: DC-AE enables efficient text-to-image generation on the laptop: <a href="https://nvlabs.github.io/Sana/">SANA</a>. | |
| </p> | |
| - [Usage of Deep Compression Autoencoder](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/dc_ae/README.md#deep-compression-autoencoder) | |
| - [Usage of DC-AE-Diffusion](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/dc_ae/README.md#efficient-diffusion-models-with-dc-ae) | |
| - [Evaluate Deep Compression Autoencoder](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/dc_ae/README.md#evaluate-deep-compression-autoencoder) | |
| - [Demo DC-AE-Diffusion Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/dc_ae/README.md#demo-dc-ae-diffusion-models) | |
| - [Evaluate DC-AE-Diffusion Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/dc_ae/README.md#evaluate-dc-ae-diffusion-models) | |
| - [Train DC-AE-Diffusion Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/dc_ae/README.md#train-dc-ae-diffusion-models) | |
| - [Reference](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/dc_ae/README.md#reference) | |
| ### [CVPR 2024 eLVM Workshop] EfficientViT-SAM: Accelerated Segment Anything Model Without Accuracy Loss [[paper](https://arxiv.org/abs/2402.05008)] [[online demo](https://evitsam.hanlab.ai/)] [[readme](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_sam/README.md)] | |
| **EfficientViT-SAM is a new family of accelerated segment anything models by replacing SAM's heavy image encoder with EfficientViT. It delivers a 48.9x measured TensorRT speedup on A100 GPU over SAM-ViT-H without sacrificing accuracy.** | |
| <p align="left"> | |
| <img src="https://huggingface.co/mit-han-lab/efficientvit-sam/resolve/main/sam_zero_shot_coco_mAP.png" width="500"> | |
| </p> | |
| - [Pretrained EfficientViT-SAM Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_sam/README.md#pretrained-efficientvit-sam-models) | |
| - [Usage of EfficientViT-SAM](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_sam/README.md#usage) | |
| - [Evaluate EfficientViT-SAM](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_sam/README.md#evaluation) | |
| - [Visualize EfficientViT-SAM](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_sam/README.md#visualization) | |
| - [Deploy EfficientViT-SAM](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_sam/README.md#deployment) | |
| - [Train EfficientViT-SAM](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_sam/README.md#training) | |
| - [Reference](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_sam/README.md#reference) | |
| ### [ICCV 2023] EfficientViT-Classification [[paper](https://arxiv.org/abs/2205.14756)] [[readme](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_cls/README.md)] | |
| **Efficient image classification models with EfficientViT backbones.** | |
| <p align="left"> | |
| <img src="https://huggingface.co/han-cai/efficientvit-cls/resolve/main/efficientvit_cls_results.png" width="600"> | |
| </p> | |
| - [Pretrained EfficientViT Classification Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_cls/README.md#pretrained-efficientvit-classification-models) | |
| - [Usage of EfficientViT Classification Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_cls/README.md#usage) | |
| - [Evaluate EfficientViT Classification Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_cls/README.md#evaluation) | |
| - [Export EfficientViT Classification Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_cls/README.md#export) | |
| - [Train EfficientViT Classification Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_cls/README.md#training) | |
| - [Reference](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_cls/README.md#reference) | |
| ### [ICCV 2023] EfficientViT-Segmentation [[paper](https://arxiv.org/abs/2205.14756)] [[readme](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_seg/README.md)] | |
| **Efficient semantic segmantation models with EfficientViT backbones.** | |
|  | |
| - [Pretrained EfficientViT Segmentation Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_seg/README.md#pretrained-efficientvit-segmentation-models) | |
| - [Usage of EfficientViT Segmentation Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_seg/README.md#usage) | |
| - [Evaluate EfficientViT Segmentation Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_seg/README.md#evaluation) | |
| - [Visualize EfficientViT Segmentation Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_seg/README.md#visualization) | |
| - [Export EfficientViT Segmentation Models](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_seg/README.md#export) | |
| - [Reference](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_seg/README.md#reference) | |
| ### EfficientViT-GazeSAM [[readme](https://raw.githubusercontent.com/mit-han-lab/efficientvit/de7d7733cc0329f391b33f1f459271562ec27bd5/applications/efficientvit_gazesam/README.md)] | |
| **Gaze-prompted image segmentation models capable of running in real time with TensorRT on an NVIDIA RTX 4070.** | |
|  | |
| ## Getting Started | |
| ```bash | |
| conda create -n efficientvit python=3.10 | |
| conda activate efficientvit | |
| pip install -U -r requirements.txt | |
| ``` | |
| ## Third-Party Implementation/Integration | |
| - [NVIDIA Jetson Generative AI Lab](https://www.jetson-ai-lab.com/tutorial_efficientvit.html) | |
| - [timm](https://github.com/huggingface/pytorch-image-models): [link](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/efficientvit_mit.py) | |
| - [X-AnyLabeling](https://github.com/CVHub520/X-AnyLabeling): [link](https://github.com/CVHub520/X-AnyLabeling/blob/main/anylabeling/services/auto_labeling/efficientvit_sam.py) | |
| - [Grounding DINO 1.5 Edge](https://github.com/IDEA-Research/Grounding-DINO-1.5-API): [link](https://arxiv.org/pdf/2405.10300) | |
| ## Contact | |
| [Han Cai](http://hancai.ai/) | |
| ## Reference | |
| If EfficientViT or EfficientViT-SAM or DC-AE is useful or relevant to your research, please kindly recognize our contributions by citing our paper: | |
| ```bibtex | |
| @inproceedings{cai2023efficientvit, | |
| title={Efficientvit: Lightweight multi-scale attention for high-resolution dense prediction}, | |
| author={Cai, Han and Li, Junyan and Hu, Muyan and Gan, Chuang and Han, Song}, | |
| booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision}, | |
| pages={17302--17313}, | |
| year={2023} | |
| } | |
| ``` | |
| ```bibtex | |
| @article{zhang2024efficientvit, | |
| title={EfficientViT-SAM: Accelerated Segment Anything Model Without Performance Loss}, | |
| author={Zhang, Zhuoyang and Cai, Han and Han, Song}, | |
| journal={arXiv preprint arXiv:2402.05008}, | |
| year={2024} | |
| } | |
| ``` | |
| ```bibtex | |
| @article{chen2024deep, | |
| title={Deep Compression Autoencoder for Efficient High-Resolution Diffusion Models}, | |
| author={Chen, Junyu and Cai, Han and Chen, Junsong and Xie, Enze and Yang, Shang and Tang, Haotian and Li, Muyang and Lu, Yao and Han, Song}, | |
| journal={arXiv preprint arXiv:2410.10733}, | |
| year={2024} | |
| } | |
| ``` | |