|
| 1 | +# Perception Ownership Split (Python vs. Rust) |
| 2 | + |
| 3 | +This document defines the architectural boundary between Python-based prototyping and Rust-based performance/determinism for the HoopSense perception layer. |
| 4 | + |
| 5 | +## Current State (Stage 1: Python-Heavy) |
| 6 | +- **Ingestion:** Python (OpenCV) |
| 7 | +- **Detection & Tracking:** Python (Ultralytics BoT-SORT) |
| 8 | +- **Pose Estimation:** Python (Ultralytics YOLOv8-pose) |
| 9 | +- **Spatial Resolution:** Rust (SpatialResolver via Bridge) |
| 10 | +- **Behavior Engine:** Python (PossessionEngine + DSL Evaluator) |
| 11 | +- **Ledger:** Rust (GameStateLedger) |
| 12 | + |
| 13 | +## Proposed Target State (Stage 2: Deterministic Core) |
| 14 | + |
| 15 | +### 1. The Python Frontier (The "Eye") |
| 16 | +**Responsibility:** Rapid experimentation with SOTA ML models. |
| 17 | +- **ML Inference:** Detection, Pose, and OCR models should remain in Python to leverage optimized PyTorch/TensorRT ecosystems. |
| 18 | +- **Audio Analysis:** Python (AudioHead) for referee whistle detection. |
| 19 | +- **Initial JSONL Production:** Emitting raw "Shush-P" streams. |
| 20 | + |
| 21 | +### 2. The Rust Interior (The "Brain") |
| 22 | +**Responsibility:** Performance-critical processing, temporal consistency, and geometric grounding. |
| 23 | +- **Track Management (Move from Python):** Implementation of the `TrackManager` and Kalman Filters should migrate to Rust. This ensures that track-state is consistent between real-time inference and offline re-processing. |
| 24 | +- **Kinematic Lifting (Move from Python):** The `lift_keypoints_to_3d` logic should be entirely in Rust to ensure bone-length constraints are enforced at the type-system level. |
| 25 | +- **Possession Logic (Move from Python):** The `PossessionEngine` should migrate to Rust. Global ball-player proximity is a geometric query that belongs in the `GeometricReferee`. |
| 26 | + |
| 27 | +## Migration Rationale |
| 28 | + |
| 29 | +| Component | Target | Rationale | |
| 30 | +| :--- | :--- | :--- | |
| 31 | +| **TrackManager** | Rust | High-frequency update loop; memory safety for large track sets. | |
| 32 | +| **Kalman Filter** | Rust | Deterministic floating-point math; reusable by multiple agents. | |
| 33 | +| **PossessionEngine**| Rust | Transitions system from perception to rules; must be bug-free. | |
| 34 | +| **Model Inference** | Python | Fragility of ML library bindings in Rust; Python ecosystem is superior. | |
| 35 | + |
| 36 | +## First Migration Target: TrackManager |
| 37 | +The `TrackManager` is the ideal first candidate for migration (L3.37). By moving tracking state to Rust, we can: |
| 38 | +1. Remove the `deque` history management in Python. |
| 39 | +2. Perform multi-track spatial reasoning without crossing the bridge for every player. |
| 40 | +3. Ensure that track persistence logic is identical across ARM64 and x86 targets. |
0 commit comments