tamserve: High-Performance Real-Time Object Tracking for Live Video
Overview
tamserve is a specialized serving engine designed to bring Meta's state-of-the-art object tracking models—SAM 2, SAM 2.1, and EdgeTAM—to live, multi-camera environments. While original implementations of these models were built for processing single recorded videos, tamserve applies continuous batching techniques similar to those used in LLM serving (like vLLM). This allows a single copy of a model to track multiple objects across numerous camera feeds simultaneously, resulting in significantly lower GPU memory consumption and higher throughput without sacrificing mask accuracy.
Why tamserve for Live Tracking
The primary bottleneck in deploying models like SAM 2 for live video is memory scaling. Standard implementations require a separate model instance per camera, causing memory usage to grow linearly with the number of feeds.
tamserve optimizes this by sharing one model instance across all cameras. By batching requests, it achieves:
- Reduced Memory Footprint: Running 8 cameras requires approximately 2.2 GB of VRAM with tamserve, compared to 8.6 GB using standard implementations.
- Higher Throughput: It enables faster processing speeds by managing GPU queues more efficiently, reducing the number of synchronization waits between the CPU and GPU.
- Dynamic Flexibility: It supports starting or stopping tracking for any object mid-stream and handles camera feeds that may come and go.
Core Functionality and Architecture
tamserve acts as an orchestration layer between the tracking model and the user's application. It does not handle video decoding itself, allowing users to integrate it with any frame source (e.g., RTSP streams via OpenCV).
Tracking Methods
- Manual Prompting: Users can initiate tracking by providing a bounding box, a set of clicks, or an existing mask. Once initialized, the engine maintains the object's state across frames.
- Automated Tracking (Tracker/PeopleTracker): Using Meta's SAM 3 model, users can track objects by name (e.g., "dog" or "person"). The engine intelligently balances the heavy computational cost of SAM 3 by performing periodic detections and using the lighter EdgeTAM or SAM 2.1 models for frame-to-frame tracking in between.
Performance Optimizations
- Continuous Batching: Every object across every camera shares the same pass through the model.
- Memory Efficiency: An object only retains the memory required for the model to function—specifically the prompt frame, the last 6 frames, and a summary of the last 15 frames.
- Compiled Execution: Using PyTorch compilation, the engine can be optimized for specific hardware, significantly increasing frames-per-second (FPS) at the cost of an initial compilation time.
Multi-GPU Support
For large-scale deployments, tamserve includes a Router component. The router distributes camera feeds across multiple GPUs, running a worker process on each. This allows for horizontal scaling where each worker manages its own decoding and tracking, ensuring that video data does not need to be transferred between GPUs.
Community Insights
Discussion on Hacker News highlighted alternative approaches for browser-based tracking. User @sroussey noted that other projects, such as those leveraging Transformers.js, are exploring similar real-time capabilities directly within the browser environment, providing a different trade-off profile compared to server-side GPU-accelerated solutions like tamserve.
"Nice. You should check this out, not by me and different model, but handling live video and runs in the browser." — @sroussey
Getting Started
tamserve is available via pip install tamserve. It requires Python 3.10+ and an NVIDIA GPU. For advanced tracking by name, users can install the SAM 3 extension via pip install "tamserve[sam3]" and authenticate with Hugging Face to access the gated model weights.