Skip to main content

๐Ÿค– GPU Backend Setup Guide

Run the AI analysis engine locally


Prerequisitesโ€‹

ToolVersionNotes
Python3.11.xRequired exactly โ€” CatBoost + MediaPipe do not support 3.12+
uvLatestPython package + venv manager (this workstation's standard)
CUDA11.8+Optional, for NVIDIA GPU acceleration
GitLatestRepository 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โ€‹

ComponentMinimumRecommended
GPUCPU-only (slow)NVIDIA RTX 3080+ or Apple Silicon (MPS)
RAM8 GB16 GB
Storage5 GB (models + output)10 GB
VRAMN/A8 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:

ModelFilePurpose
TrackNetgames/tennis/models/tracknet_ball.ptBall tracking
CourtDetectorNetgames/tennis/models/courtnet_keypoints.ptCourt detection
CatBoostgames/tennis/models/bounce_classifier.cbmBounce 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)โ€‹

StageTime
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โ€‹

ErrorSolution
catboost requires Python 3.11.xUse Python 3.11.x exactly
Device: cpu (MPS/CUDA not detected)Check GPU drivers; CPU fallback works but is slower
CUDA out of memoryReduce video resolution or batch size
ModuleNotFoundErrorEnsure venv is activated and deps installed
FFmpeg not foundInstall FFmpeg: brew install ffmpeg (macOS) or apt install ffmpeg (Linux)