AI

How to achieve 30+ FPS with Segment Anything Model (SAM) for live video?

RI Asked by Richard Thompson · 29-01-2024
0 upvotes 22,361 views 0 comments
The question

I’m trying to integrate Meta’s Segment Anything Model (SAM) into a live robotics feed, but the image encoder is a total bottleneck. Currently, I’m getting about 2 frames per second on an RTX 3090, which is nowhere near real-time. I’ve heard about "MobileSAM" and "FastSAM," but how do they compare in terms of accuracy? Also, are there specific TensorRT optimizations or quantization tricks (INT8/FP16) that can speed up the ViT (Vision Transformer) backbone without losing the "segment anything" magic?

3 answers

0
BR
Answered on 12-02-2024

If you must use the original high-accuracy SAM weights, you need to look into TensorRT and FP16/INT8 Quantization.

ST 16-02-2024

We managed to hit 20 FPS with the standard SAM by converting it to a TensorRT engine. The key is "Decoupled Inference." Since the image encoder produces a constant embedding, you only run the encoder once per frame, and then you can run the Mask Decoder multiple times for different points or boxes at virtually zero cost (sub-5ms). Also, try INT8 Post-Training Quantization (PTQ). Recent frameworks like PTQ4SAM allow you to compress the weights to 8-bit or even 6-bit with less than a 1% drop in mIoU, which provides a massive throughput boost on NVIDIA's Tensor Cores.

0
KI
Answered on 14-02-2024

To get SAM running in real-time, you have to address the Image Encoder, which accounts for ~95% of the computation time. In 2026, the standard approach is to move away from the original ViT-H backbone. You have three main paths:

  1. Switch to SAM 2: Meta's latest version is natively designed for video. It uses a Memory Bank to propagate masks across frames, meaning it only needs to "think" hard about the first frame and then tracks the object with a much lighter mask decoder in subsequent frames.
     
  2. Use MobileSAM: This replaces the heavy ViT-H encoder with a Tiny-ViT. It’s about 60x smaller and can run in ~10ms on a decent GPU.
  3. FastSAM: This approach actually uses a YOLOv8-seg backbone. It’s technically a "segment everything" model that mimics SAM’s behavior but at the speed of a standard object detector.

0
LI
Answered on 18-02-2024

For those on a budget or edge devices (like Jetson Orin), the "Furious Changes" approach is best. Use Torch-TensorRT to compile the model with "AOTInductor" (Ahead-of-Time) and enable FlashAttention-2.

RI 22-02-2024

Exactly, Steven. FlashAttention-2 is a lifesaver for the transformer blocks in the encoder. It reduces memory bandwidth bottlenecks significantly. One last tip: if you are doing video, don't re-encode every frame. Only run the heavy encoder every 5th or 10th frame and use a lightweight optical flow or the SAM 2 memory attention to "warp" the mask in between. That’s how we got our drone feed to stay buttery smooth at 60 FPS.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session