๐ค GPU Backend Setup Guide
Run the AI analysis engine locally
Prerequisitesโ
| Tool | Version | Notes |
|---|---|---|
| Python | 3.11.x | Required exactly โ CatBoost + MediaPipe do not support 3.12+ |
| uv | Latest | Python package + venv manager (this workstation's standard) |
| CUDA | 11.8+ | Optional, for NVIDIA GPU acceleration |
| Git | Latest | Repository access |
:::warning Python Version Python 3.11.x is a hard requirement. CatBoost (bounce detection) and MediaPipe (pose estimation) do not have compatible wheels for Python 3.12+. :::
Hardware Recommendationsโ
| Component | Minimum | Recommended |
|---|---|---|
| GPU | CPU-only (slow) | NVIDIA RTX 3080+ or Apple Silicon (MPS) |
| RAM | 8 GB | 16 GB |
| Storage | 5 GB (models + output) | 10 GB |
| VRAM | N/A | 8 GB+ |
Installationโ
1. Clone the Repositoryโ
git clone <repo-url>
cd acesense-gpu-backend
2. Create a Virtual Environmentโ
uv venv --python 3.11
source .venv/bin/activate # On Windows: .venv\Scripts\activate
3. Install Dependenciesโ
uv pip install -r requirements/requirements.txt
:::note RunPod image vs local
The RunPod serverless Docker image is built on a prebuilt PyTorch/CUDA base and installs requirements/base.txt (plus linux-cuda.txt) โ it does not use requirements.txt. requirements/ is split per platform: base.txt, linux-cpu.txt, linux-cuda.txt, mac.txt.
:::
Running Locallyโ
Basic Analysisโ
python main.py --path_input_video input_videos/sample.mp4
Development Mode (with cache)โ
Dev cache stores intermediate results so subsequent runs skip expensive ML inference:
# First run โ builds cache (~90s for 30s video)
python main.py --path_input_video input_videos/sample.mp4 --dev
# Subsequent runs โ uses cache (~3s, 96% faster)
python main.py --path_input_video input_videos/sample.mp4 --dev
All CLI Optionsโ
python main.py --path_input_video VIDEO.mp4 [OPTIONS]
Options:
--path_output_video OUTPUT.mp4 Output video path
--dev Enable dev cache (fast iteration)
--save-shot-videos Save individual shot videos
--no-save-shot-videos Skip shot videos (faster)
--cloud Upload to Firebase Storage
--firebase_bucket BUCKET Firebase bucket name
--firebase_credentials PATH Path to service account JSON
Cloud Uploadโ
python main.py \
--path_input_video video.mp4 \
--cloud \
--firebase_bucket your-bucket.firebasestorage.app \
--firebase_credentials firebasecred/firebase-admin.json
Project Structureโ
acesense-gpu-backend/
โโโ main.py # Unified entry point โ auto-detects serverless vs local
โ # via src.serverless (is_serverless_mode / start_serverless)
โโโ src/ # Core processing modules
โ โโโ pipeline/ # ACTIVE orchestrator: game_processor.py::process_video(sport, ...),
โ โ # phase6_outputs.py (emits insights.json), registry, stages glue
โ โโโ stages/ # Stage implementations: ball_tracking/, surface/, events/, physics/
โ โโโ core/ # Shared constants
โ โโโ insights/ # Insight engine (candidates, scorer, ranker, templates)
โ โโโ serverless/ # Vendor-isolated serverless runtime adapter (RunPod)
โ โโโ tracking/ # Ball tracking (TrackNet)
โ โโโ surface/ # Court detection
โ โโโ players/ # Player detection
โ โโโ events/ # Bounce & shot detection
โ โโโ classification/ # Shot classification
โ โโโ analysis/ fusion/ # Game analytics + sensor fusion
โ โโโ export/ # analysis_export.py (schema 1.5.0), report generation
โ โโโ io/ # Video I/O, Firebase
โ โโโ render/ # Visualization overlays
โ โโโ preprocessing/ # Frame prep / resize
โ โโโ utils/ # Utilities & dev cache
โโโ games/ # Tennis config + models
โโโ input_videos/ # Local input clips (ignored)
โโโ tests/ # Test suite
โโโ requirements/ # Dependencies (base + per-platform)
Pre-Trained Modelsโ
Models are included in the repository:
| Model | File | Purpose |
|---|---|---|
| TrackNet | games/tennis/models/tracknet_ball.pt | Ball tracking |
| CourtDetectorNet | games/tennis/models/courtnet_keypoints.pt | Court detection |
| CatBoost | games/tennis/models/bounce_classifier.cbm | Bounce detection |
Processing Pipelineโ
Video Input
โ
Ball Tracking (TrackNet)
โ
Court Detection (CourtDetectorNet)
โ
Player Detection (FasterRCNN + MediaPipe)
โ
Bounce Detection (CatBoost)
โ
Shot Detection (Pose Analysis)
โ
Shot Classification (Sequence Classifier)
โ
Game Analysis (Stats + Recommendations)
โ
Export (Video, PDF, JSON, Minimaps)
Outputโ
Analysis creates a timestamped directory:
.dev/output/sample_video_19122030/
โโโ output_video.mp4 # Annotated video
โโโ analysis_report.pdf # Performance report
โโโ sample_video_analysis.json # Canonical analysis JSON (schema 1.5.0, embeds "insights")
โโโ insights.json # Ranked insight candidates (Phase 6, also embedded in analysis JSON)
โโโ ball_trajectory_3d.json # Physics-based 3D trajectory
โโโ events_timeline.json # Event frames
โโโ shots/ # Per-shot metadata/pose
Dev Cacheโ
# Cache location
.dev/cache/<video_hash>/
โโโ ball_tracking.pkl
โโโ court_detection.pkl
โโโ player_detection.pkl
โโโ bounces.pkl
โโโ shots.pkl
# Clear cache
rm -rf .dev/cache/
Running Testsโ
pytest tests/ -v
Performance Benchmarks (RTX 3080)โ
| Stage | Time |
|---|---|
| Ball Tracking | ~30s |
| Court Detection | ~10s |
| Player Detection | ~40s (CPU bottleneck on Apple Silicon) |
| Analysis & Export | ~10s |
| Total | ~90s for 30s video |
| With Dev Cache | ~3s (96% faster) |
Troubleshootingโ
| Error | Solution |
|---|---|
catboost requires Python 3.11.x | Use Python 3.11.x exactly |
Device: cpu (MPS/CUDA not detected) | Check GPU drivers; CPU fallback works but is slower |
CUDA out of memory | Reduce video resolution or batch size |
ModuleNotFoundError | Ensure venv is activated and deps installed |
| FFmpeg not found | Install FFmpeg: brew install ffmpeg (macOS) or apt install ffmpeg (Linux) |
Relatedโ
- GPU Backend Overview - AI models and architecture
- Architecture - System design
- Firebase Functions - Job triggers
- Configuration Reference - All environment variables
Was this page helpful?