explaingit

flybroken/sam2-tensorrt

Analysis updated 2026-05-18

35C++Audience · researcherComplexity · 5/5Setup · hard

TLDR

A C++ TensorRT port of Meta's SAM2 model for real-time object segmentation and tracking in video, running at about 33 FPS on an A10 GPU.

Mindmap

mindmap
  root((sam2-tensorrt))
    What it does
      Real-time segmentation
      Video object tracking
      Multi-object support
    Tech stack
      C++
      TensorRT
      CUDA
    Use cases
      Track single object
      Track multiple objects
      Low-latency inference
    Audience
      CV engineers
      GPU inference researchers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Track a single object across video frames in real time using a box or point prompt.

USE CASE 2

Track multiple objects simultaneously with per-object memory banks.

USE CASE 3

Run SAM2 segmentation at low latency on an NVIDIA GPU instead of the slower default PyTorch pipeline.

USE CASE 4

Build a real-time video tracking feature into a larger computer vision system.

What is it built with?

C++TensorRTCUDAOpenCVONNX RuntimeCMake

How does it compare?

flybroken/sam2-tensorrtsofiafvbiub2935447/fl-product-version-250xjbb/modulestomped
Stars353534
LanguageC++C++C++
Setup difficultyhardhardmoderate
Complexity5/51/54/5
Audienceresearchergeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · hard Time to first run · 1day+

Requires a matched set of CUDA, TensorRT, cuDNN, and CUDA-enabled OpenCV versions plus manually converting ONNX files to TensorRT engines before it runs.

In plain English

sam2-tensorrt is a C++ project that takes Meta's SAM2 video object segmentation model and rebuilds the inference pipeline in NVIDIA TensorRT so it can run fast on real video instead of just single images. SAM2 is a model that can find and outline a specific object in a video frame, given a starting box or point, and keep tracking that same object as the video plays. This project focuses purely on making that tracking run in real time on an NVIDIA GPU. On an NVIDIA A10 GPU, the project reports processing a single tracked target at around 30 milliseconds per frame, close to 33 frames per second, using 16 bit floating point precision across all six of the TensorRT engines that make up the pipeline. Optimizations described in the README include reusing GPU memory buffers instead of allocating new ones each frame, running image resizing and color conversion on the GPU, doing bounding box extraction on the GPU as well, and using a Kalman filter to help pick the most likely correct mask when tracking gets difficult, such as when an object is partly hidden or changes shape. The pipeline is split into six separate TensorRT engines covering image encoding, memory attention, mask decoding, and memory encoding, with a memory bank that stores past frames to help the model stay locked onto its target. It supports tracking a single object or multiple objects at once, each with its own memory bank. Using it requires a fairly involved native build: specific versions of CUDA, TensorRT, cuDNN, OpenCV built with CUDA support, ONNX Runtime, Intel TBB, and CMake, plus manually converting provided ONNX model files into TensorRT engine files before running the compiled binary on an image or video file. It is aimed at engineers building real time computer vision or video tracking systems who are comfortable with GPU inference tooling.

Copy-paste prompts

Prompt 1
Walk me through converting the ONNX models in sam2-tensorrt into TensorRT engine files with trtexec.
Prompt 2
Explain the six TensorRT engines in sam2-tensorrt and what each one does.
Prompt 3
Help me set up the CUDA, TensorRT, and OpenCV dependencies needed to build sam2-tensorrt.
Prompt 4
How does the Kalman filter in sam2-tensorrt help with occluded or deformed objects?

Frequently asked questions

What is sam2-tensorrt?

A C++ TensorRT port of Meta's SAM2 model for real-time object segmentation and tracking in video, running at about 33 FPS on an A10 GPU.

What language is sam2-tensorrt written in?

Mainly C++. The stack also includes C++, TensorRT, CUDA.

How hard is sam2-tensorrt to set up?

Setup difficulty is rated hard, with roughly 1day+ to a first successful run.

Who is sam2-tensorrt for?

Mainly researcher.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.