trackflow-python-tensorrt 0.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
trackflow/types.py ADDED
@@ -0,0 +1,235 @@
1
+ """Core data models shared across detectors, trackers, Re-ID, spatial analytics, and sinks."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from typing import Any
7
+
8
+ import numpy as np
9
+
10
+
11
+ @dataclass(slots=True)
12
+ class Detection:
13
+ """Single object detection in pixel coordinates (x1, y1, x2, y2)."""
14
+
15
+ bbox: tuple[float, float, float, float]
16
+ confidence: float
17
+ class_id: int
18
+ class_name: str
19
+ embedding: np.ndarray | None = field(default=None, repr=False)
20
+
21
+ @property
22
+ def width(self) -> float:
23
+ return max(0.0, self.bbox[2] - self.bbox[0])
24
+
25
+ @property
26
+ def height(self) -> float:
27
+ return max(0.0, self.bbox[3] - self.bbox[1])
28
+
29
+ @property
30
+ def area(self) -> float:
31
+ return self.width * self.height
32
+
33
+ @property
34
+ def center(self) -> tuple[float, float]:
35
+ return ((self.bbox[0] + self.bbox[2]) * 0.5, (self.bbox[1] + self.bbox[3]) * 0.5)
36
+
37
+ @property
38
+ def foot_point(self) -> tuple[float, float]:
39
+ """Bottom-center ground contact point used for floorplan homography."""
40
+ return ((self.bbox[0] + self.bbox[2]) * 0.5, self.bbox[3])
41
+
42
+
43
+ @dataclass(slots=True)
44
+ class Track:
45
+ """Active tracked object at a specific frame."""
46
+
47
+ track_id: int
48
+ bbox: tuple[float, float, float, float]
49
+ confidence: float
50
+ class_id: int
51
+ class_name: str
52
+ age: int = 1
53
+ hits: int = 1
54
+ recovered: bool = False
55
+ coasting: bool = False # predicted position of a briefly-missed track (display only)
56
+ query_score: float | None = None
57
+ query_match: bool = True
58
+ world_xy: tuple[float, float] | None = None
59
+ zone: str | None = None
60
+ reid_merged_from: int | None = None
61
+
62
+ @property
63
+ def width(self) -> float:
64
+ return max(0.0, self.bbox[2] - self.bbox[0])
65
+
66
+ @property
67
+ def height(self) -> float:
68
+ return max(0.0, self.bbox[3] - self.bbox[1])
69
+
70
+ @property
71
+ def foot_point(self) -> tuple[float, float]:
72
+ return ((self.bbox[0] + self.bbox[2]) * 0.5, self.bbox[3])
73
+
74
+ def to_record(self, frame_idx: int, timestamp_s: float) -> dict[str, Any]:
75
+ x1, y1, x2, y2 = self.bbox
76
+ return {
77
+ "frame_idx": int(frame_idx),
78
+ "timestamp_s": round(float(timestamp_s), 4),
79
+ "track_id": int(self.track_id),
80
+ "class_id": int(self.class_id),
81
+ "class_name": str(self.class_name),
82
+ "confidence": round(float(self.confidence), 4),
83
+ "x1": round(float(x1), 2),
84
+ "y1": round(float(y1), 2),
85
+ "x2": round(float(x2), 2),
86
+ "y2": round(float(y2), 2),
87
+ "width": round(float(x2 - x1), 2),
88
+ "height": round(float(y2 - y1), 2),
89
+ "age": int(self.age),
90
+ "hits": int(self.hits),
91
+ "recovered": bool(self.recovered),
92
+ "query_score": None if self.query_score is None else round(float(self.query_score), 4),
93
+ "query_match": bool(self.query_match),
94
+ "world_x": None if self.world_xy is None else round(float(self.world_xy[0]), 3),
95
+ "world_y": None if self.world_xy is None else round(float(self.world_xy[1]), 3),
96
+ "zone": self.zone,
97
+ }
98
+
99
+
100
+ @dataclass(slots=True)
101
+ class FrameResult:
102
+ """Per-frame tracking output and timing telemetry."""
103
+
104
+ frame_idx: int
105
+ timestamp_s: float
106
+ tracks: list[Track]
107
+ num_detections: int
108
+ inference_ms: float
109
+ tracking_ms: float
110
+ events: list[dict[str, Any]] = field(default_factory=list)
111
+
112
+
113
+ @dataclass(slots=True)
114
+ class TrackCard:
115
+ """Persistent entity summary for a tracked person/object across its lifetime."""
116
+
117
+ track_id: int
118
+ class_name: str
119
+ first_frame: int
120
+ last_frame: int
121
+ first_timestamp_s: float
122
+ last_timestamp_s: float
123
+ frame_count: int
124
+ best_confidence: float
125
+ best_frame: int
126
+ best_bbox: tuple[float, float, float, float]
127
+ thumbnail_relpath: str | None = None
128
+ embedding: list[float] | None = None
129
+ query_score: float | None = None
130
+ query_match: bool = True
131
+ merged_track_ids: list[int] = field(default_factory=list)
132
+ zones_visited: list[str] = field(default_factory=list)
133
+ dwell_seconds: dict[str, float] = field(default_factory=dict)
134
+
135
+ @property
136
+ def duration_s(self) -> float:
137
+ return max(0.0, self.last_timestamp_s - self.first_timestamp_s)
138
+
139
+ def to_dict(self, include_embedding: bool = True) -> dict[str, Any]:
140
+ data: dict[str, Any] = {
141
+ "track_id": self.track_id,
142
+ "class_name": self.class_name,
143
+ "first_frame": self.first_frame,
144
+ "last_frame": self.last_frame,
145
+ "first_timestamp_s": round(self.first_timestamp_s, 3),
146
+ "last_timestamp_s": round(self.last_timestamp_s, 3),
147
+ "duration_s": round(self.duration_s, 3),
148
+ "frame_count": self.frame_count,
149
+ "best_confidence": round(self.best_confidence, 4),
150
+ "best_frame": self.best_frame,
151
+ "best_bbox": [round(float(v), 2) for v in self.best_bbox],
152
+ "thumbnail": self.thumbnail_relpath,
153
+ "query_score": None if self.query_score is None else round(self.query_score, 4),
154
+ "query_match": self.query_match,
155
+ "merged_track_ids": list(self.merged_track_ids),
156
+ "zones_visited": list(self.zones_visited),
157
+ "dwell_seconds": {k: round(v, 3) for k, v in self.dwell_seconds.items()},
158
+ }
159
+ if include_embedding and self.embedding is not None:
160
+ data["embedding"] = self.embedding
161
+ return data
162
+
163
+
164
+ @dataclass(slots=True)
165
+ class HomographyPoint:
166
+ """A 2D image-to-floorplan calibration correspondence."""
167
+
168
+ image_xy: tuple[float, float]
169
+ world_xy: tuple[float, float]
170
+
171
+
172
+ @dataclass(slots=True)
173
+ class RunSummary:
174
+ """Aggregate summary of a completed Trackflow run."""
175
+
176
+ source: str
177
+ model: str
178
+ tracker: str
179
+ device: str
180
+ total_frames: int
181
+ processed_frames: int
182
+ source_fps: float
183
+ avg_fps: float
184
+ avg_inference_ms: float
185
+ avg_tracking_ms: float
186
+ total_detections: int
187
+ total_track_observations: int
188
+ unique_tracks: int
189
+ recovered_tracks: int
190
+ reid_merges: int
191
+ elapsed_s: float
192
+ frame_width: int
193
+ frame_height: int
194
+ classes: list[str]
195
+ query: str | None = None
196
+ anonymize_mode: str = "none"
197
+ output_files: dict[str, str] = field(default_factory=dict)
198
+ zone_dwell_totals_s: dict[str, float] = field(default_factory=dict)
199
+ line_counts: dict[str, dict[str, int]] = field(default_factory=dict)
200
+ frame_stride: int = 1
201
+ model_revision: str | None = None
202
+ precision: str | None = None
203
+ tracking_threshold: float | None = None
204
+
205
+ def to_dict(self) -> dict[str, Any]:
206
+ return {
207
+ "source": self.source,
208
+ "model": self.model,
209
+ "model_revision": self.model_revision,
210
+ "precision": self.precision,
211
+ "tracking_threshold": self.tracking_threshold,
212
+ "tracker": self.tracker,
213
+ "device": self.device,
214
+ "total_frames": self.total_frames,
215
+ "processed_frames": self.processed_frames,
216
+ "source_fps": round(self.source_fps, 2),
217
+ "frame_stride": self.frame_stride,
218
+ "avg_fps": round(self.avg_fps, 2),
219
+ "avg_inference_ms": round(self.avg_inference_ms, 2),
220
+ "avg_tracking_ms": round(self.avg_tracking_ms, 2),
221
+ "total_detections": self.total_detections,
222
+ "total_track_observations": self.total_track_observations,
223
+ "unique_tracks": self.unique_tracks,
224
+ "recovered_tracks": self.recovered_tracks,
225
+ "reid_merges": self.reid_merges,
226
+ "elapsed_s": round(self.elapsed_s, 3),
227
+ "frame_width": self.frame_width,
228
+ "frame_height": self.frame_height,
229
+ "classes": self.classes,
230
+ "query": self.query,
231
+ "anonymize_mode": self.anonymize_mode,
232
+ "output_files": self.output_files,
233
+ "zone_dwell_totals_s": {k: round(v, 2) for k, v in self.zone_dwell_totals_s.items()},
234
+ "line_counts": self.line_counts,
235
+ }
@@ -0,0 +1,367 @@
1
+ Metadata-Version: 2.5
2
+ Name: trackflow-python-tensorrt
3
+ Version: 0.6.1
4
+ Summary: Stream or export multi-object tracks with ONNX and optional Transformers detectors, ByteTrack, BoT-SORT, OC-SORT or BoostTrack, text search, floorplan projection, and anonymization. (NVIDIA TensorRT FP16 build with bundled CUDA 13/cuDNN/TensorRT 10 runtimes.)
5
+ Project-URL: Homepage, https://obendidi.github.io/trackflow/
6
+ Project-URL: Repository, https://github.com/obendidi/trackflow
7
+ Project-URL: Issues, https://github.com/obendidi/trackflow/issues
8
+ Author: Ouail Bendidi
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: boosttrack,botsort,bytetrack,clip,computer-vision,d-fine,homography,mot,multi-object-tracking,object-tracking,ocsort,onnxruntime,parquet,people-tracking,re-identification,rf-detr,rtdetr,siglip,video-tracking,webgpu
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Multimedia :: Video
24
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
26
+ Requires-Python: >=3.11
27
+ Requires-Dist: huggingface-hub>=0.24
28
+ Requires-Dist: numpy>=1.26
29
+ Requires-Dist: onnxruntime-gpu[cuda,cudnn]>=1.28
30
+ Requires-Dist: opencv-python-headless>=4.9
31
+ Requires-Dist: pyarrow>=15.0
32
+ Requires-Dist: rich>=13.7
33
+ Requires-Dist: scipy>=1.11
34
+ Requires-Dist: tensorrt-cu13-libs<11,>=10
35
+ Requires-Dist: tokenizers>=0.19
36
+ Requires-Dist: typer>=0.12
37
+ Provides-Extra: dev
38
+ Requires-Dist: pytest>=8.0; extra == 'dev'
39
+ Requires-Dist: ruff>=0.6; extra == 'dev'
40
+ Provides-Extra: display
41
+ Requires-Dist: opencv-python>=4.9; extra == 'display'
42
+ Provides-Extra: transformers
43
+ Requires-Dist: sentence-transformers<7,>=6.1; extra == 'transformers'
44
+ Requires-Dist: torch>=2.6; extra == 'transformers'
45
+ Requires-Dist: torchvision>=0.21; extra == 'transformers'
46
+ Requires-Dist: transformers<6,>=5.18; extra == 'transformers'
47
+ Description-Content-Type: text/markdown
48
+
49
+ # Trackflow
50
+
51
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/obendidi/trackflow/blob/main/LICENSE)
52
+ [![Python](https://img.shields.io/badge/Python-3.10%2B-3776AB.svg)](https://pypi.org/project/trackflow-python/)
53
+
54
+ Real-time people and object tracking in Python and in the browser. Trackflow runs current detectors (RF-DETR, RT-DETRv2, D-FINE, DEIMv2, YOLO26) with ByteTrack, BoT-SORT, OC-SORT or BoostTrack, streams or exports track data (Parquet, JSONL, CSV, MOTChallenge, HTML), and includes text-based track search, a local run inspector with 4-point floorplan projection, and anonymization.
55
+
56
+ ![Trackflow tracking people crossing Yonge and Dundas in Toronto, with an ID, box and trail on each person](https://raw.githubusercontent.com/obendidi/trackflow/main/docs/demo.webp)
57
+
58
+ *`trackflow run crossing.mp4` with the default settings, at 12 FPS on an Apple M4 Pro CPU. Footage: 8 seconds of [DiagonalCrosswalkYongeDundas.webm](https://commons.wikimedia.org/wiki/File:DiagonalCrosswalkYongeDundas.webm) by Raysonho, CC0.*
59
+
60
+ ![Trackflow Inspector showing live video playback, recovery jumps, two natural-language track searches ("person in white shirt" and "woman in pink shirt"), and ByteTrack vs BoT-SORT comparison](https://raw.githubusercontent.com/obendidi/trackflow/main/docs/inspect-demo.webp)
61
+
62
+ *`trackflow inspect` on the same clip: scrubbing with live video frames, jumping to recovery events, searching Track Cards with natural language, and comparing ByteTrack against BoT-SORT.*
63
+
64
+ Try it in the browser without installing anything: [obendidi.github.io/trackflow](https://obendidi.github.io/trackflow/).
65
+
66
+ ## Quickstart
67
+
68
+ One command for your hardware — no system CUDA Toolkit, cuDNN, or TensorRT setup required:
69
+
70
+ | Environment | Zero-install (`uvx`) | Installed (`pip`) | Notes |
71
+ | :--- | :--- | :--- | :--- |
72
+ | **CPU / macOS** *(default)* | `uvx trackflow-python run street.mp4` | `pip install trackflow-python` | Auto-pins Apple Silicon to P-cores (~14 FPS on M4 Pro CPU) |
73
+ | **macOS GPU (CoreML)** | `uvx trackflow-python run street.mp4 --device coreml` | `pip install trackflow-python` | Runs detector + static-batch OSNet Re-ID on Apple GPU |
74
+ | **NVIDIA CUDA** | `uvx trackflow-python-cuda run street.mp4` | `pip install trackflow-python-cuda` | Bundles CUDA + cuDNN; auto-selects CUDA (~37–105 FPS on T4) |
75
+ | **NVIDIA TensorRT** *(Py 3.11+)* | `uvx trackflow-python-tensorrt run street.mp4` | `pip install trackflow-python-tensorrt` | Bundles CUDA 13 + TensorRT 10 FP16; cached engines (~94–136 FPS on T4) |
76
+
77
+ Or run via Docker with zero Python setup (`--target cpu`, `cuda`, or `tensorrt` in [Dockerfile](Dockerfile)):
78
+
79
+ ```bash
80
+ docker build --target tensorrt -t trackflow:tensorrt .
81
+ docker run --rm --gpus all -v "$PWD:/work" \
82
+ -v "$HOME/.cache/huggingface:/root/.cache/huggingface" \
83
+ -v "$HOME/.cache/trackflow:/root/.cache/trackflow" \
84
+ trackflow:tensorrt run /work/street.mp4
85
+ ```
86
+
87
+ After a run finishes, open the local visual inspector:
88
+
89
+ ```bash
90
+ trackflow inspect # opens the most recent run
91
+ trackflow info # checks GPU, execution providers, and recommended command
92
+ ```
93
+
94
+ Each run writes to a new folder (`runs/run-1`, `runs/run-2`, …). Pass `-o <dir>` to choose one yourself; it must be empty, so a new run never mixes with files from an old one.
95
+
96
+ Model weights download from Hugging Face on first run and are cached locally. Every preset is pinned to a specific model revision, so the same command gives the same weights later. ONNX Runtime picks CUDA or CPU automatically; `--device cpu|cuda|coreml|tensorrt` forces one and fails loudly with the exact install command if the matching runtime isn't present. TensorRT builds and caches its engine once per model under `~/.cache/trackflow/trt_cache/` (subsequent runs load in <1s) and automatically keeps `rfdetr-*` in FP32 so DINOv2 activations don't overflow. *Never keep both `onnxruntime` and `onnxruntime-gpu` in the same environment—they share the `onnxruntime` import path and silently break GPU providers.*
97
+
98
+ <details>
99
+ <summary>Verified NVIDIA T4 GPU throughput & parity (CUDA FP32 vs TensorRT 10 FP16)</summary>
100
+
101
+ Measured on an isolated venv (system CUDA/TRT paths stripped, proving zero-config pip library preloading) on an NVIDIA Tesla T4 (`vtest.avi`, 5-frame box IoU parity vs CPU + 40-frame steady-state timing):
102
+
103
+ | Model | CUDA FP32 | TensorRT FP16 *(warm)* | Speedup vs CUDA | Mean IoU vs CPU | Cold build → Warm load |
104
+ | :--- | ---: | ---: | ---: | ---: | :--- |
105
+ | `rtdetr-v2-r18` *(default)* | 26.4 ms (37.9 FPS) | **8.95 ms (111.7 FPS)** | **3.0x** | 0.988 (`37/37`) | 205 s → **0.95 s** |
106
+ | `dfine-s` | 21.5 ms (46.5 FPS) | **8.21 ms (121.8 FPS)** | **2.6x** | 0.980 (`54/53`) | 262 s → **0.68 s** |
107
+ | `dfine-m` | 33.7 ms (29.6 FPS) | **10.65 ms (93.9 FPS)** | **3.2x** | 0.984 (`42/42`) | 247 s → **1.32 s** |
108
+ | `yolo26n` *(AGPL)* | 11.5 ms (86.8 FPS) | **7.37 ms (135.6 FPS)** | **1.6x** | 0.985 (`26/26`) | 261 s → **0.16 s** |
109
+ | `rfdetr-nano` | **18.1 ms (55.4 FPS)** | FP32 (`trt_fp16=False`) | — | 1.000 (`30/30`) | Kept in FP32 (FP16 overflows DINOv2) |
110
+ | `rfdetr-medium` | **40.5 ms (24.7 FPS)** | FP32 (`trt_fp16=False`) | — | 1.000 (`31/31`) | Kept in FP32 (FP16 overflows DINOv2) |
111
+ | `osnet` Re-ID *(8 crops)* | 19.2 ms | **10.5 ms** *(static B=8)* | **1.8x** | 1.000 cos (`0.99996`) | 0.15 s load |
112
+
113
+ </details>
114
+
115
+ ## Usage
116
+
117
+ ### Tracking and exports
118
+
119
+ ```bash
120
+ trackflow run crowd.mp4 \
121
+ --model rfdetr-medium \
122
+ --tracker botsort --reid osnet \
123
+ --classes person,backpack \
124
+ --export parquet,jsonl,csv,mot,html
125
+ ```
126
+
127
+ The source can be a video file, a folder of images (read in natural order, `frame_2` before `frame_10`; set the rate with `--fps`), an RTSP/HTTP stream URL, or a camera index. Press Ctrl-C to stop a run: Trackflow stops reading frames and still writes every output, including the track cards that `trackflow search` and `trackflow inspect` read. A second Ctrl-C aborts without writing them.
128
+
129
+ The Parquet export can be queried directly with DuckDB:
130
+
131
+ ```sql
132
+ SELECT track_id, COUNT(*) AS frames, AVG(confidence) AS avg_conf
133
+ FROM 'runs/run-1/tracks.parquet'
134
+ GROUP BY track_id ORDER BY frames DESC;
135
+ ```
136
+
137
+ `--export mot` writes `tracks.txt` in MOTChallenge format, which [TrackEval](https://github.com/JonathonLuiten/TrackEval) scores directly (HOTA, IDF1, MOTA).
138
+
139
+ ### Trackers
140
+
141
+ | `--tracker` | Algorithm | How it works |
142
+ | :--- | :--- | :--- |
143
+ | `bytetrack` *(default)* | [ByteTrack](https://arxiv.org/abs/2110.06864) (ECCV 2022) | Matches boxes by overlap, then uses low-confidence detections to keep tracks through partial occlusion. The fastest option. |
144
+ | `botsort` | [BoT-SORT](https://arxiv.org/abs/2206.14651) (2022) | ByteTrack plus camera-motion compensation, and appearance matching with `--reid osnet`. |
145
+ | `ocsort` | [OC-SORT](https://arxiv.org/abs/2203.14360) (CVPR 2023) | Trusts detections over motion predictions: after an occlusion it re-matches a track to its last observed box and corrects the motion model along the gap. |
146
+ | `boosttrack` | [BoostTrack++](https://arxiv.org/abs/2408.13003) (2024) | Raises the confidence of weak detections that fit a track or look like a new object, and matches with motion, shape and, with `--reid osnet`, appearance. Compensates for camera motion. |
147
+
148
+ All four keep a person and a bag in the same box as separate tracks, and only give out an ID once a track has been seen on more than one frame. OC-SORT and BoostTrack report a track again after a miss once it has matched three frames in a row; in between, the annotated video shows it as a coasting box. The browser playground uses ByteTrack.
149
+
150
+ #### Benchmarks across 4 official datasets (81 videos, ~59,800 frames)
151
+
152
+ ![Trackflow vs. Roboflow trackers speed and quality Pareto frontier and per-benchmark academic SOTA context](https://raw.githubusercontent.com/obendidi/trackflow/main/docs/benchmarks-trackers.png)
153
+
154
+ Every tracker below receives the exact same detections from Trackflow's default Apache-2.0 detector (`rtdetr-v2-r18`, confidence threshold `0.45`, Apple M4 Pro) so the comparison isolates the tracking algorithm.
155
+
156
+ | Tracker | DanceTrack (25) | SportsMOT (45) | MOT17 (7) | MOT20 (4) | Mean HOTA | Total ID switches | Tracker FPS | End-to-End FPS |
157
+ | :--- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
158
+ | **`botsort --reid osnet`** | **39.0** | 45.0 | **46.9** | **24.4** | **38.8** | 6,435 | 205 | 5.5 |
159
+ | **`ocsort`** *(no Re-ID)* | 37.9 | **46.0** | 46.3 | 23.3 | **38.4** | **5,501** | 203 | 9.2 |
160
+ | **`boosttrack`** *(no Re-ID)* | 37.5 | 44.4 | **46.9** | 24.0 | **38.2** | 5,549 | 201 | 9.2 |
161
+ | **`botsort`** *(no Re-ID)* | 36.7 | 44.3 | 46.5 | 24.3 | **37.9** | 6,475 | 221 | 9.3 |
162
+ | `bytetrack` *(also in browser)* | 33.1 | 39.8 | 45.1 | 23.5 | 35.4 | 7,038 | **2,900** | **9.7** |
163
+ | *Roboflow `cbiou` (`0.45/0.50`)* | 36.0 | 43.4 | 46.4 | 24.2 | 37.5 | 7,533 | 2,072 | 9.6 |
164
+ | *Roboflow `botsort` (`0.45/0.50`)* | 35.9 | 43.6 | 46.3 | 24.0 | 37.4 | 6,922 | 194 | 9.2 |
165
+ | *Roboflow `ocsort+cmc` (`0.45`)* | 33.4 | 43.8 | 44.2 | 15.9 | 34.3 | 8,057 | 196 | 9.2 |
166
+ | *Roboflow `botsort` (defaults `0.60/0.70`)* | 39.6 | 50.0 | 42.6 | 13.6 | 36.4 | 4,349 | 207 | 9.2 |
167
+
168
+ **How to read this chart and table:**
169
+ - **HOTA (0–100, higher is better)**: Overall tracking accuracy. It combines two halves equally: finding the right people in each frame and keeping the same ID on each person as they move and cross paths.
170
+ - **ID switches (lower is better)**: How many times a tracker accidentally swaps or resets a person's ID mid-video.
171
+ - **Tracker FPS vs. End-to-End FPS**: Tracker FPS is the matching step alone; End-to-End FPS includes running the object detector (and person Re-ID crops when enabled) on every frame on a laptop.
172
+ - **The 4 benchmarks**: **DanceTrack** (25 videos of dancers wearing identical outfits—tests motion tracking when appearance doesn't help), **SportsMOT** (45 fast-moving basketball, football, and volleyball clips with panning cameras), **MOT17** (7 busy street scenes), and **MOT20** (4 dense pedestrian crowds, second halves).
173
+ - **Why academic SOTA is higher (~66–77 HOTA)**: Leaderboard papers train a specialist detector (usually YOLOX-X) directly on each benchmark—so it learns, for example, to ignore spectators in SportsMOT stands—and often fill gaps offline after the video ends. Trackflow runs one off-the-shelf, general-purpose Apache-2.0 COCO detector live, frame by frame. On SportsMOT, Roboflow's high default threshold (`0.60/0.70`) similarly filters out blurry spectators (`50.0` HOTA), at the cost of dropping occluded pedestrians on MOT17 (`42.6`) and MOT20 (`13.6`). Pass `--threshold 0.6` in Trackflow on sports broadcasts if you want the same crowd filtering.
174
+
175
+ [`scripts/eval_benchmarks.py`](https://github.com/obendidi/trackflow/blob/main/scripts/eval_benchmarks.py) reproduces all four datasets and the Roboflow `trackers==2.7.0` controls (scored with `trackers eval`, which matches TrackEval). Scenes vary widely, so test on footage like yours with `trackflow compare` or `--export mot`.
176
+
177
+ ### Text search and re-identification
178
+
179
+ ```bash
180
+ # Highlight matching people live (uses CLIP by default; --vlm embeddinggemma for clothing and accessories)
181
+ trackflow run mall.mp4 --query "person in red jacket with a backpack"
182
+
183
+ # Search a completed run later without re-running detection
184
+ # (requires a run created with --query or --vlm clip|siglip|siglip2|embeddinggemma)
185
+ trackflow search runs/run-1 "person carrying a suitcase"
186
+
187
+ # Export top search hits as time windows + normalized boxes for SAM 3 or a VLM
188
+ trackflow search runs/run-1 "person in red jacket" --top-k 5 --pad-s 1.0 --export-prompts prompts.json
189
+
190
+ # Give people who leave and come back their earlier ID (opt-in, uses person Re-ID)
191
+ trackflow run mall.mp4 --reid osnet --reid-merge
192
+ ```
193
+
194
+ ![Natural-language track search quality vs. speed across 23,287 labeled pedestrian crops](https://raw.githubusercontent.com/obendidi/trackflow/main/docs/benchmarks-search.png)
195
+
196
+ Tested across all **23,287 labeled pedestrian crops** in the PA-100K (10,000 crops, 18 clothing/accessory queries) and UPAR (13,287 crops, 20 color/attribute queries) validation sets, measured with **mAP** (Mean Average Precision, 0–1: how accurately matching people rank at the top of search results) via [`scripts/eval_text_search.py`](https://github.com/obendidi/trackflow/blob/main/scripts/eval_text_search.py):
197
+
198
+ - **`--vlm embeddinggemma`** *(PyTorch, needs `pip install "trackflow-python[transformers]"`)*: highest accuracy (**0.507** PA-100K / **0.561** UPAR mAP, ~10 crops/s on M4 Pro MPS).
199
+ - **`--vlm siglip2`** *(pure ONNX INT8, zero PyTorch)*: best lightweight choice (**0.442** PA-100K / **0.488** UPAR mAP at ~45 crops/s on CPU—both faster and more accurate than SigLIP 1 at `0.420 / 0.459` and ~28 crops/s).
200
+ - **`--vlm clip`** *(default, pure ONNX INT8)*: fastest option (**146 crops/s** on CPU, `0.288 / 0.357` mAP).
201
+
202
+ CLIP, SigLIP, SigLIP 2 and EmbeddingGemma 2 match images to *text*; they cannot reliably distinguish two people in similar clothes, so they are never used for identity. `--reid osnet` runs a dedicated person re-identification model. Re-entry merging only considers people who left before the new track appeared and stayed gone longer than the tracker's own recovery window, and merges only when one earlier person is clearly the best match; look-alikes stay separate. It can still make mistakes on low-resolution footage, which is why it is off by default.
203
+
204
+ ### Inspector, tracker comparison, and floorplan projection
205
+
206
+ ```bash
207
+ # Compare ByteTrack and BoT-SORT on the same video and open the inspector
208
+ trackflow compare crowd.mp4 --trackers bytetrack,botsort --inspect
209
+
210
+ # Open the inspector on any existing run
211
+ trackflow inspect runs/run-1
212
+ ```
213
+
214
+ `trackflow inspect` starts a local web UI where you can scrub through frames, jump to flagged ID switches or recoveries, search track cards, compare two runs, and click 4 ground corners to project 2D tracks onto a top-down floorplan.
215
+
216
+ ### Line counting
217
+
218
+ ```bash
219
+ # Count people crossing a doorway, in each direction
220
+ trackflow run entrance.mp4 --line "door=640,300,640,720"
221
+ ```
222
+
223
+ `--line` takes a line segment in image pixels as `name=x1,y1,x2,y2` (the name is optional) and can be repeated. A track crosses when the bottom center of its box moves from one side of the segment to the other and stays there for 0.3 seconds, so a box edge that jumps back and forth when people overlap doesn't count each jump. A crossing to the right of the direction from the first point to the second counts as `in`, the other way as `out`. For a line drawn left to right, `in` means moving down the frame, and the annotated video shows an arrow on the `in` side. Every crossing counts, so someone who steps back over the line adds one in each direction. Put the line where people's feet stay in view: when someone closer to the camera hides a person's legs, that person's box ends higher, and a line just above their feet can count a crossing that didn't happen.
224
+
225
+ The totals go to the run summary, `summary.json` (`line_counts`) and the HTML report. Each crossing is also a `line_crossed` event in `events.json`, with the track ID, class and direction. In Python, pass `lines=[CountingLine("door", (640, 300), (640, 720))]` to `TrackflowPipeline`; `stream()` reports crossings in each frame's `events`.
226
+
227
+ ### Anonymization
228
+
229
+ ```bash
230
+ # Blur the top of each person box, where the head usually is
231
+ trackflow run lobby.mp4 --anonymize face-blur
232
+
233
+ # Draw stick figures on a blank canvas (box-based, no pose model; no video pixels saved)
234
+ trackflow run lobby.mp4 --anonymize skeleton
235
+ ```
236
+
237
+ Available modes are `face-blur`, `blur`, `pixelate`, and `skeleton`. Anonymization covers every detected person box (including low-confidence detections and people briefly missed by the tracker), even when you track other classes, and anonymized runs do not write person crops or thumbnails. It is best effort: if the detector misses someone in a frame, that person is not blurred in that frame.
238
+
239
+ `face-blur` runs no face detector. It blurs an ellipse over the top 30% of each person box, so it misses a face that isn't there, for example on someone lying down, bending over or holding their arms up. Use `blur` or `pixelate` to cover the whole person.
240
+
241
+ ### Benchmarking
242
+
243
+ ```bash
244
+ trackflow benchmark crowd.mp4 --models rfdetr-nano,rtdetr-v2-r18 --trackers bytetrack,botsort --split-screen
245
+ ```
246
+
247
+ Runs the selected detector/tracker pairs on a video (or a generated synthetic clip if no video is given) and writes a Markdown and JSON report. `--split-screen` also renders the first run's annotated video next to a panel with the 2017 version's published speed. The 2017 README only gives that number, not per-frame results to replay.
248
+
249
+ FPS and track counts don't tell you whether IDs are right. For accuracy, run on a labeled sequence with `--export mot` and score the result with TrackEval.
250
+
251
+ ## Models
252
+
253
+ Weights download automatically from Hugging Face on first use. `trackflow models` lists every preset (`--json` for scripts).
254
+
255
+ | Preset | Model | Size (FP32) | License | Notes |
256
+ | :--- | :--- | ---: | :--- | :--- |
257
+ | `rtdetr-v2-r18` *(default)* | RT-DETRv2 ResNet-18 (640×640) | ~81 MB | Apache-2.0 | Balanced default for crowded scenes |
258
+ | `rfdetr-nano` | RF-DETR Nano (384×384) | ~108 MB | Apache-2.0 | Fast on Apple Silicon and WebGPU |
259
+ | `rfdetr-small` | RF-DETR Small (512×512) | ~115 MB | Apache-2.0 | |
260
+ | `rfdetr-medium` | RF-DETR Medium (576×576) | ~121 MB | Apache-2.0 | |
261
+ | `rfdetr-base` | RF-DETR Base (560×560) | ~108 MB | Apache-2.0 | |
262
+ | `rfdetr-large` | RF-DETR Large (704×704) | ~136 MB | Apache-2.0 | Most accurate preset; needs the `transformers` extra |
263
+ | `dfine-n` | D-FINE Nano (640×640) | ~15 MB | Apache-2.0 | Small download |
264
+ | `dfine-s` | D-FINE Small (640×640) | ~42 MB | Apache-2.0 | Compact COCO-only ONNX |
265
+ | `dfine-m` | D-FINE Medium (640×640) | ~79 MB | Apache-2.0 | Highest Apache-2.0 ONNX MOT17 HOTA |
266
+ | `yolo26n` … `yolo26x` | YOLO26 Nano to XLarge (640×640) | 10–223 MB | **AGPL-3.0** | Commercial use needs an Ultralytics license |
267
+ | `deimv2-atto` | DEIMv2 Atto (320×320) | ~2 MB | **Non-commercial** | Tiny edge model, FP32 only |
268
+ | `deimv2-s` | DEIMv2 Small, DINOv3 backbone (640×640) | ~41 MB | **Non-commercial** + DINOv3 | FP32 only |
269
+
270
+ Most presets also have `--precision fp16` and `int8` variants. Trackflow itself is Apache-2.0, but each model's weights carry their own license, so check the table before shipping a product. With ByteTrack on the MOT17 split used for the [tracker scores](#trackers):
271
+
272
+ | Preset | HOTA | IDF1 | MOTA |
273
+ | :--- | ---: | ---: | ---: |
274
+ | `dfine-m` | 46.5 | 55.1 | 39.2 |
275
+ | `rtdetr-v2-r18` *(default)* | 45.1 | 53.9 | 39.8 |
276
+ | `rfdetr-large` | 44.3 | 51.1 | 35.9 |
277
+ | `rfdetr-medium` | 42.9 | 49.7 | 34.8 |
278
+ | `yolo26n` | 37.4 | 41.4 | 27.9 |
279
+ | `rfdetr-nano` | 36.5 | 40.5 | 28.2 |
280
+
281
+ `dfine-m` scores highest here (`46.5` HOTA with ByteTrack, `46.9` with BoT-SORT) while `rtdetr-v2-r18` remains the faster default (`10.0` vs `7.3` FPS on M4 Pro CoreML). Test on footage like yours before switching.
282
+
283
+ You aren't limited to presets. `-m` also takes any compatible ONNX repo on Hugging Face (`owner/repo`), a local `.onnx` file, or, with the extra installed, any Transformers object-detection checkpoint as `hf:owner/repo`:
284
+
285
+ ```bash
286
+ pip install "trackflow-python[transformers]"
287
+ trackflow run crowd.mp4 -m rfdetr-large
288
+ trackflow run crowd.mp4 -m hf:PekingU/rtdetr_v2_r50vd --device mps
289
+ ```
290
+
291
+ Re-ID and text-search models:
292
+
293
+ | Flag | Model | Size | License | Used for |
294
+ | :--- | :--- | ---: | :--- | :--- |
295
+ | `--reid osnet` | OSNet-AIN x1.0 person Re-ID | ~9 MB | MIT code; weights trained on MSMT17 (check dataset terms for commercial use) | BoT-SORT and BoostTrack appearance, and `--reid-merge` |
296
+ | `--vlm clip` | CLIP ViT-B/32 (INT8) | ~153 MB | MIT | Default for `--query` and `search` |
297
+ | `--vlm siglip` | SigLIP Base (INT8) | ~205 MB | Apache-2.0 | Better on fine clothing/attribute queries |
298
+ | `--vlm siglip2` | SigLIP 2 Base (INT8) | ~378 MB | Apache-2.0 | Strongest pure-ONNX search (no PyTorch) |
299
+ | `--vlm embeddinggemma` | EmbeddingGemma 2 (PyTorch, needs `[transformers]`) | ~1.5 GB | Apache-2.0 | Best on clothing and accessory queries |
300
+
301
+ ## Python API
302
+
303
+ Run a video and write the same files as the CLI:
304
+
305
+ ```python
306
+ from trackflow import TrackflowPipeline
307
+
308
+ pipeline = TrackflowPipeline(
309
+ model="rfdetr-medium",
310
+ tracker="botsort",
311
+ reid="osnet", # person Re-ID for BoT-SORT
312
+ query="person wearing a red jacket", # scored with CLIP (vlm="clip" by default when query is set)
313
+ anonymize="face-blur",
314
+ )
315
+ summary = pipeline.run("crowd.mp4") # or output_dir="runs/crowd"
316
+ print(f"{summary.unique_tracks} unique tracks at {summary.avg_fps:.1f} FPS")
317
+ ```
318
+
319
+ Or feed frames from your own loop and get tracks back, with nothing written to disk:
320
+
321
+ ```python
322
+ import cv2
323
+ from trackflow import TrackflowPipeline
324
+
325
+ pipeline = TrackflowPipeline(model="rfdetr-nano")
326
+ cap = cv2.VideoCapture("rtsp://camera.local/stream")
327
+
328
+ def frames():
329
+ while True:
330
+ ok, frame = cap.read()
331
+ if not ok:
332
+ return
333
+ yield frame # BGR uint8
334
+
335
+ for result in pipeline.stream(frames(), fps=25):
336
+ for track in result.tracks:
337
+ print(result.frame_idx, track.track_id, track.class_name, track.bbox)
338
+ ```
339
+
340
+ To use your own model, pass any object with a `detect(frame_bgr) -> list[Detection]` method as `detector=`. A custom tracker goes in `tracker_factory=`, which takes any object with `update(detections, frame_bgr=None) -> list[Track]`. The built-in trackers are exported too (`ByteTracker`, `BotSortTracker`, `OcSortTracker`, `BoostTracker`), so you can tune one, for example `tracker_factory=lambda: BoostTracker(use_cmc=False)` for a fixed camera. The package ships type hints (`py.typed`), and `Detector` and `Tracker` are exported as protocols.
341
+
342
+ ## Agent skills
343
+
344
+ Use Trackflow — and its ONNX computer-vision deployment checklist — from Claude Code, Codex, Antigravity, Cursor, or OpenCode by installing the bundled skills (or point doc-fetchers at [`llms.txt`](https://obendidi.github.io/trackflow/llms.txt)):
345
+
346
+ - [`trackflow`](skills/trackflow/SKILL.md): run local tracking, line counting, text search, floorplan projection, anonymization, and exports.
347
+ - [`onnx-vision-deploy`](skills/onnx-vision-deploy/SKILL.md): empirical checklist for ONNX vision deployment across CPU, CUDA, Apple Silicon CoreML, and browser WebGPU/WASM parity.
348
+
349
+ ```bash
350
+ npx skills add obendidi/trackflow
351
+ ```
352
+
353
+ ## Migration & integration guides
354
+
355
+ - [Migrating from Google Cloud Video Intelligence (`OBJECT_TRACKING`)](docs/migrate-google-video-intelligence.md)
356
+ - [Migrating from AWS Rekognition (`StartPersonTracking` / People Pathing)](docs/migrate-aws-rekognition.md)
357
+ - [Using Trackflow alongside SAM 3 (track & filter locally, segment selectively)](docs/sam3-handoff.md)
358
+
359
+ ## Changelog
360
+
361
+ What changed in each version is in [CHANGELOG.md](https://github.com/obendidi/trackflow/blob/main/CHANGELOG.md) and on the [releases page](https://github.com/obendidi/trackflow/releases).
362
+
363
+ ## License
364
+
365
+ Apache-2.0 — see [LICENSE](https://github.com/obendidi/trackflow/blob/main/LICENSE). Model weights are downloaded separately and keep their own licenses (see [Models](#models)).
366
+
367
+ The original 2017 `Tracking-with-darkflow` codebase (YOLOv2 + DeepSORT + TensorFlow 1.0) is kept on the [`legacy-2017`](https://github.com/obendidi/trackflow/tree/legacy-2017) branch and [`v1.0-legacy-2017`](https://github.com/obendidi/trackflow/releases/tag/v1.0-legacy-2017) tag under GPL-3.0.
@@ -0,0 +1,23 @@
1
+ trackflow/__init__.py,sha256=Fyps625E_yB9KxZd-E26LFcBT5dHHFFtAB5gUG0aj6U,1499
2
+ trackflow/benchmark.py,sha256=-8yGyViSBH5nWrdEwtLuabfUoCMLfaVJyY7gwRQE2zo,9673
3
+ trackflow/boosttrack.py,sha256=Y2ruAUR8MJaiItXP2QPEhbORLtPPBGjIdcNZpV5oqP4,19877
4
+ trackflow/cli.py,sha256=yfw15W4lG53G7krXHzCKaYFRiSI0iBj-Dj0wZSJHvmQ,23341
5
+ trackflow/detector.py,sha256=KsManmy7zs1FAej0LJOhc-oOdNZ-kwq04Zqys-81kAM,31758
6
+ trackflow/homography.py,sha256=dyllF-yc9FBkGUagUEIuelX2AsnvyVKsRFp1siRHfSg,9674
7
+ trackflow/inspector.py,sha256=DT2QcoClE_0apMRQlToAyr1XIvBQ358zICErYY56dvs,18583
8
+ trackflow/inspector_ui.html,sha256=iiQbKQwY1Ho20EiuOq-q-YB2EPGy1ehHSSCZgf3F9QU,23767
9
+ trackflow/lines.py,sha256=nhd_UaCh8fpaB62NxkWEWgrv5sI3IMyROyA33-zuajU,4972
10
+ trackflow/models.py,sha256=MXvUL95g0NpKDrwDcPsJaNQji_vd5nKWLrwieO3W5rE,15752
11
+ trackflow/ocsort.py,sha256=ZyONDWI5-VBdooWQ3OADf3vlRni4WNC3rZKUf5IxC7M,15451
12
+ trackflow/pipeline.py,sha256=JbPYlCjOyPOVtCdB237LIO_a2xJfk95PRu7UARxYmh8,35821
13
+ trackflow/privacy.py,sha256=uuZX25q9013ocrLe9VbYkzlKDkIxPnMFBDVq1zTg9Hw,6792
14
+ trackflow/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
15
+ trackflow/reid.py,sha256=6B-iMBF3PLPPCPQBgXKK3vDMj8W1VmjjMqLI4iNt_T4,35784
16
+ trackflow/sinks.py,sha256=3HbNFNdkzSGpAeDONqw_x4OQ9Cu43aslEzCqq3FNdS8,17287
17
+ trackflow/tracker.py,sha256=I4aZMuWNwxZv9WApUk8TgIcu-WkmWVJ7WcyQEjmaHds,47922
18
+ trackflow/types.py,sha256=-4Fs1thoT9UCrlznMR-EhZMDItzL-e6S0jOO2LeSYao,8129
19
+ trackflow_python_tensorrt-0.6.1.dist-info/METADATA,sha256=IAwC3XNUXLnB1efnhdALufJhmWHuujfRxmb65d-IkpE,26004
20
+ trackflow_python_tensorrt-0.6.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
21
+ trackflow_python_tensorrt-0.6.1.dist-info/entry_points.txt,sha256=y303bMJKcpOQQPZEs3Z0u-yROBg6P44EYhsps8F73hY,103
22
+ trackflow_python_tensorrt-0.6.1.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
23
+ trackflow_python_tensorrt-0.6.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ trackflow = trackflow.cli:app
3
+ trackflow-python-tensorrt = trackflow.cli:app_tensorrt