semantic-kinematics 0.1.0__tar.gz
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.
- semantic_kinematics-0.1.0/.gitignore +32 -0
- semantic_kinematics-0.1.0/CITATION.cff +30 -0
- semantic_kinematics-0.1.0/LICENSE +21 -0
- semantic_kinematics-0.1.0/PKG-INFO +164 -0
- semantic_kinematics-0.1.0/README.md +123 -0
- semantic_kinematics-0.1.0/legacy/README.md +84 -0
- semantic_kinematics-0.1.0/pyproject.toml +82 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/__init__.py +75 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/cli.py +206 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/config/__init__.py +33 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/config/loading.py +92 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/config/models.py +222 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/core/__init__.py +34 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/core/calibration.py +132 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/core/detections.py +165 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/core/geometry.py +71 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/core/tracks.py +120 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/core/video.py +117 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/detect/__init__.py +25 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/detect/base.py +119 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/detect/blob.py +101 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/detect/maskrcnn.py +144 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/detect/tiling.py +165 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/kinematics/__init__.py +39 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/kinematics/adapter.py +161 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/kinematics/engine.py +137 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/kinematics/kernels.py +130 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/kinematics/metrics.py +327 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/models/__init__.py +34 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/models/builders.py +105 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/models/download.py +211 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/models/registry.json +55 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/pipeline/__init__.py +16 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/pipeline/artifacts.py +85 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/pipeline/io.py +278 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/pipeline/runner.py +375 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/py.typed +0 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/runtime.py +60 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/track/__init__.py +39 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/track/base.py +139 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/track/correlation.py +319 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/track/merging.py +247 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/track/smoothing.py +117 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/track/stitching.py +195 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/training/__init__.py +10 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/training/dataset.py +147 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/training/finetune.py +34 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/viz/__init__.py +34 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/viz/colormaps.py +114 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/viz/field_maps.py +277 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/viz/fields.py +183 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/viz/render.py +311 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/viz/sam_overlay.py +120 -0
- semantic_kinematics-0.1.0/src/semantic_kinematics/viz/trajectories.py +181 -0
- semantic_kinematics-0.1.0/tests/__init__.py +0 -0
- semantic_kinematics-0.1.0/tests/conftest.py +87 -0
- semantic_kinematics-0.1.0/tests/synthetic.py +84 -0
- semantic_kinematics-0.1.0/tests/test_adapter_lgr.py +175 -0
- semantic_kinematics-0.1.0/tests/test_artifact_cache.py +62 -0
- semantic_kinematics-0.1.0/tests/test_calibration.py +100 -0
- semantic_kinematics-0.1.0/tests/test_cli.py +37 -0
- semantic_kinematics-0.1.0/tests/test_config.py +94 -0
- semantic_kinematics-0.1.0/tests/test_correlation.py +90 -0
- semantic_kinematics-0.1.0/tests/test_detect.py +171 -0
- semantic_kinematics-0.1.0/tests/test_detections.py +65 -0
- semantic_kinematics-0.1.0/tests/test_detector_registry.py +134 -0
- semantic_kinematics-0.1.0/tests/test_geometry.py +46 -0
- semantic_kinematics-0.1.0/tests/test_merge.py +141 -0
- semantic_kinematics-0.1.0/tests/test_metrics_parity.py +212 -0
- semantic_kinematics-0.1.0/tests/test_metrics_physics.py +201 -0
- semantic_kinematics-0.1.0/tests/test_package.py +14 -0
- semantic_kinematics-0.1.0/tests/test_pipeline_synthetic.py +108 -0
- semantic_kinematics-0.1.0/tests/test_real_model.py +44 -0
- semantic_kinematics-0.1.0/tests/test_registry_download.py +83 -0
- semantic_kinematics-0.1.0/tests/test_repo_hygiene.py +68 -0
- semantic_kinematics-0.1.0/tests/test_review_fixes.py +125 -0
- semantic_kinematics-0.1.0/tests/test_smoothing.py +77 -0
- semantic_kinematics-0.1.0/tests/test_stitching.py +129 -0
- semantic_kinematics-0.1.0/tests/test_store_io.py +167 -0
- semantic_kinematics-0.1.0/tests/test_tiling.py +243 -0
- semantic_kinematics-0.1.0/tests/test_track_validation.py +223 -0
- semantic_kinematics-0.1.0/tests/test_tracks.py +37 -0
- semantic_kinematics-0.1.0/tests/test_training_dataset.py +61 -0
- semantic_kinematics-0.1.0/tests/test_video.py +64 -0
- semantic_kinematics-0.1.0/tests/test_viz.py +219 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
.pytest_cache/
|
|
5
|
+
.coverage
|
|
6
|
+
htmlcov/
|
|
7
|
+
dist/
|
|
8
|
+
build/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
.venv/
|
|
11
|
+
venv/
|
|
12
|
+
.idea/
|
|
13
|
+
.vscode/
|
|
14
|
+
.ipynb_checkpoints/
|
|
15
|
+
.DS_Store
|
|
16
|
+
Thumbs.db
|
|
17
|
+
desktop.ini
|
|
18
|
+
|
|
19
|
+
# Media and artifacts: nothing heavy enters git. Model weights live in the
|
|
20
|
+
# platformdirs cache (fetched from GitHub Releases); pipeline outputs live in
|
|
21
|
+
# artifacts/ or runs/. The only committed media are the blessed fixtures under
|
|
22
|
+
# data/videos/ and the annotation JPEGs under data/annotations/.
|
|
23
|
+
*.pth
|
|
24
|
+
*.nc
|
|
25
|
+
*.avi
|
|
26
|
+
*.mp4
|
|
27
|
+
*.log
|
|
28
|
+
artifacts/
|
|
29
|
+
runs/
|
|
30
|
+
renders/
|
|
31
|
+
!data/videos/*.avi
|
|
32
|
+
!data/videos/*.mp4
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use this software, please cite the paper below."
|
|
3
|
+
title: "SemanticKinematics"
|
|
4
|
+
type: software
|
|
5
|
+
authors:
|
|
6
|
+
- family-names: Harms
|
|
7
|
+
given-names: Tanner D.
|
|
8
|
+
repository-code: "https://github.com/TannerHarms/SemanticKinematics"
|
|
9
|
+
license: MIT
|
|
10
|
+
preferred-citation:
|
|
11
|
+
type: article
|
|
12
|
+
title: "Semantic kinematic analysis from groups of tracked objects"
|
|
13
|
+
authors:
|
|
14
|
+
- family-names: Harms
|
|
15
|
+
given-names: Tanner D.
|
|
16
|
+
- family-names: Brunton
|
|
17
|
+
given-names: Steven L.
|
|
18
|
+
- family-names: McKeon
|
|
19
|
+
given-names: Beverley J.
|
|
20
|
+
journal: "Physica D: Nonlinear Phenomena"
|
|
21
|
+
year: 2026
|
|
22
|
+
volume: 496
|
|
23
|
+
start: 135335
|
|
24
|
+
doi: "10.1016/j.physd.2026.135335"
|
|
25
|
+
identifiers:
|
|
26
|
+
- type: doi
|
|
27
|
+
value: "10.48550/arXiv.2408.16190"
|
|
28
|
+
description: "arXiv preprint"
|
|
29
|
+
- type: other
|
|
30
|
+
value: "arXiv:2408.16190"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Tanner Harms
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: semantic-kinematics
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Video to flow physics: object detection, tracking, and Lagrangian gradient regression for measuring dynamic flow features in groups of tracked objects.
|
|
5
|
+
Project-URL: Repository, https://github.com/TannerHarms/SemanticKinematics
|
|
6
|
+
Project-URL: Paper, https://doi.org/10.1016/j.physd.2026.135335
|
|
7
|
+
Project-URL: LGR, https://github.com/TannerHarms/Lagrangian-Gradient-Regression
|
|
8
|
+
Project-URL: Issues, https://github.com/TannerHarms/SemanticKinematics/issues
|
|
9
|
+
Author: Tanner Harms
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Requires-Dist: lagrangian-gradient-regression>=0.1.0
|
|
19
|
+
Requires-Dist: matplotlib>=3.8
|
|
20
|
+
Requires-Dist: netcdf4>=1.6
|
|
21
|
+
Requires-Dist: numpy>=1.26
|
|
22
|
+
Requires-Dist: opencv-python-headless>=4.8
|
|
23
|
+
Requires-Dist: pandas>=2.0
|
|
24
|
+
Requires-Dist: pillow>=10
|
|
25
|
+
Requires-Dist: platformdirs>=3.0
|
|
26
|
+
Requires-Dist: pyarrow>=14
|
|
27
|
+
Requires-Dist: pydantic>=2.5
|
|
28
|
+
Requires-Dist: pyyaml>=6.0
|
|
29
|
+
Requires-Dist: scikit-image>=0.22
|
|
30
|
+
Requires-Dist: scipy>=1.11
|
|
31
|
+
Requires-Dist: torch>=2.6
|
|
32
|
+
Requires-Dist: torchvision>=0.21
|
|
33
|
+
Requires-Dist: tqdm>=4.65
|
|
34
|
+
Requires-Dist: typer>=0.9
|
|
35
|
+
Requires-Dist: xarray>=2023.12
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
39
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# SemanticKinematics
|
|
43
|
+
|
|
44
|
+
Video to flow physics: detect objects in video with a fine-tuned Mask R-CNN,
|
|
45
|
+
track them across frames, calibrate pixel coordinates to the world, and measure
|
|
46
|
+
Lagrangian flow features (vorticity, FTLE, LAVD, and more) from the tracked
|
|
47
|
+
group using [Lagrangian Gradient Regression (LGR)](https://github.com/TannerHarms/Lagrangian-Gradient-Regression).
|
|
48
|
+
|
|
49
|
+
This is the software behind Harms, Brunton & McKeon,
|
|
50
|
+
*Semantic kinematic analysis from groups of tracked objects*
|
|
51
|
+
(Physica D **496**, 135335, 2026;
|
|
52
|
+
[doi:10.1016/j.physd.2026.135335](https://doi.org/10.1016/j.physd.2026.135335);
|
|
53
|
+
preprint [arXiv:2408.16190](https://arxiv.org/abs/2408.16190)).
|
|
54
|
+
|
|
55
|
+
```text
|
|
56
|
+
video ──> detect (tiled Mask R-CNN) ──> track (cross-correlation) ──> calibrate
|
|
57
|
+
──> kinematics (LGR: velocity gradients + Lagrangian metrics) ──> render
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The pipeline is config-driven (one YAML file per experiment), every stage is
|
|
61
|
+
individually runnable and cached under content-hash keys, and
|
|
62
|
+
detection/tracking schemes are pluggable registries — a custom detector is
|
|
63
|
+
~10 lines of code (see `semantic_kinematics.detect.Detector`).
|
|
64
|
+
|
|
65
|
+
## Status
|
|
66
|
+
|
|
67
|
+
Modernized from the original research code (kept verbatim under `legacy/`
|
|
68
|
+
until the parity review completes). This is an alpha release: interfaces may
|
|
69
|
+
still change.
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
Python >= 3.12. Install torch first so you control the CUDA/CPU choice:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# CUDA (pick the index matching your driver) ...
|
|
77
|
+
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu126
|
|
78
|
+
# ... or CPU-only
|
|
79
|
+
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
|
|
80
|
+
|
|
81
|
+
pip install semantic-kinematics
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
This also installs [Lagrangian Gradient Regression](https://github.com/TannerHarms/Lagrangian-Gradient-Regression)
|
|
85
|
+
(`lagrangian-gradient-regression` on PyPI, imported as `lgr`).
|
|
86
|
+
|
|
87
|
+
The SAM-based render overlays are optional. They need Meta's Segment Anything,
|
|
88
|
+
which Meta does not publish on PyPI, and a 2.45 GB checkpoint:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install "segment-anything @ git+https://github.com/facebookresearch/segment-anything.git@dca509fe793f601edb92606367a655c15ac00fdf"
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
To work on the package itself, clone the repository and run `pip install -e ".[dev]"`.
|
|
95
|
+
|
|
96
|
+
## Quickstart
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
semkin models fetch maskrcnn_lab_debris
|
|
100
|
+
semkin run configs/examples/alldebris_short.yaml
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
or `python examples/quickstart.py`. Useful commands: `semkin validate <cfg>`
|
|
104
|
+
(schema + registry + model checks, no compute), `semkin info <cfg>` (stage
|
|
105
|
+
keys and cache status), `semkin registry` (everything pluggable),
|
|
106
|
+
`semkin run -f track <cfg>` (force one stage and downstream).
|
|
107
|
+
|
|
108
|
+
## Model zoo
|
|
109
|
+
|
|
110
|
+
Weights are GitHub Release assets (tag `models-v1`), fetched on demand into
|
|
111
|
+
a local cache and SHA256-verified. `semkin models list` shows cache status.
|
|
112
|
+
|
|
113
|
+
| Name | Architecture | Domain | Epochs |
|
|
114
|
+
|---|---|---|---|
|
|
115
|
+
| `maskrcnn_pond_debris` | Mask R-CNN ResNet50-FPN **v2** | field pond debris (TurtlePonds, 35 mm) | 150 |
|
|
116
|
+
| `maskrcnn_lab_debris` | Mask R-CNN ResNet50-FPN **v2** | lab debris (SplitFlow) | 100 |
|
|
117
|
+
| `maskrcnn_sheep_flow` | Mask R-CNN ResNet50-FPN **v2** | sheep herds (aerial) | 100 |
|
|
118
|
+
| `sam_vit_h` | SAM ViT-H | stock upstream checkpoint (Meta CDN) | — |
|
|
119
|
+
|
|
120
|
+
Each registry entry pins the training-time inference settings
|
|
121
|
+
(`builder_kwargs`) recovered from the original models — reproducing them is
|
|
122
|
+
part of reproducing the paper. See [docs/models.md](https://github.com/TannerHarms/SemanticKinematics/blob/main/docs/models.md) and
|
|
123
|
+
[docs/specs/model_registry.md](https://github.com/TannerHarms/SemanticKinematics/blob/main/docs/specs/model_registry.md).
|
|
124
|
+
|
|
125
|
+
## Data and outputs
|
|
126
|
+
|
|
127
|
+
- Committed: two small fixture clips (`data/videos/`) and 44 hand-annotated
|
|
128
|
+
training frames (`data/annotations/turtle_ponds/`). Nothing bigger enters
|
|
129
|
+
git (enforced by a test).
|
|
130
|
+
- Outputs: `artifacts/<run>/<stage>/<key>/` with a manifest per stage; see
|
|
131
|
+
[docs/specs/pipeline_stages.md](https://github.com/TannerHarms/SemanticKinematics/blob/main/docs/specs/pipeline_stages.md).
|
|
132
|
+
- Model cache: `platformdirs.user_cache_dir("semantic_kinematics")` —
|
|
133
|
+
`%LOCALAPPDATA%\semantic_kinematics\semantic_kinematics\Cache` on Windows,
|
|
134
|
+
`~/.cache/semantic_kinematics` on Linux; override `SEMKIN_CACHE_DIR`.
|
|
135
|
+
`SEMKIN_OFFLINE=1` forbids downloads.
|
|
136
|
+
|
|
137
|
+
## Testing
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pytest # fast suite: unit tests + synthetic end-to-end pipeline
|
|
141
|
+
pytest --runslow # adds real model inference (needs cached models)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
See [docs/specs/testing.md](https://github.com/TannerHarms/SemanticKinematics/blob/main/docs/specs/testing.md).
|
|
145
|
+
|
|
146
|
+
## Development
|
|
147
|
+
|
|
148
|
+
```powershell
|
|
149
|
+
# Windows: creates the venv OUTSIDE OneDrive, installs CUDA torch,
|
|
150
|
+
# this package editable, and the local lgr checkout editable.
|
|
151
|
+
scripts\dev_setup.ps1 # or -Torch cpu
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Point your IDE at `%LOCALAPPDATA%\venvs\semkin\Scripts\python.exe`.
|
|
155
|
+
Lint with `ruff check src tests examples`. House conventions mirror the lgr
|
|
156
|
+
repo; see [docs/specs/index.md](https://github.com/TannerHarms/SemanticKinematics/blob/main/docs/specs/index.md).
|
|
157
|
+
|
|
158
|
+
## Citation
|
|
159
|
+
|
|
160
|
+
See [CITATION.cff](https://github.com/TannerHarms/SemanticKinematics/blob/main/CITATION.cff).
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT — see [LICENSE](https://github.com/TannerHarms/SemanticKinematics/blob/main/LICENSE).
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# SemanticKinematics
|
|
2
|
+
|
|
3
|
+
Video to flow physics: detect objects in video with a fine-tuned Mask R-CNN,
|
|
4
|
+
track them across frames, calibrate pixel coordinates to the world, and measure
|
|
5
|
+
Lagrangian flow features (vorticity, FTLE, LAVD, and more) from the tracked
|
|
6
|
+
group using [Lagrangian Gradient Regression (LGR)](https://github.com/TannerHarms/Lagrangian-Gradient-Regression).
|
|
7
|
+
|
|
8
|
+
This is the software behind Harms, Brunton & McKeon,
|
|
9
|
+
*Semantic kinematic analysis from groups of tracked objects*
|
|
10
|
+
(Physica D **496**, 135335, 2026;
|
|
11
|
+
[doi:10.1016/j.physd.2026.135335](https://doi.org/10.1016/j.physd.2026.135335);
|
|
12
|
+
preprint [arXiv:2408.16190](https://arxiv.org/abs/2408.16190)).
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
video ──> detect (tiled Mask R-CNN) ──> track (cross-correlation) ──> calibrate
|
|
16
|
+
──> kinematics (LGR: velocity gradients + Lagrangian metrics) ──> render
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The pipeline is config-driven (one YAML file per experiment), every stage is
|
|
20
|
+
individually runnable and cached under content-hash keys, and
|
|
21
|
+
detection/tracking schemes are pluggable registries — a custom detector is
|
|
22
|
+
~10 lines of code (see `semantic_kinematics.detect.Detector`).
|
|
23
|
+
|
|
24
|
+
## Status
|
|
25
|
+
|
|
26
|
+
Modernized from the original research code (kept verbatim under `legacy/`
|
|
27
|
+
until the parity review completes). This is an alpha release: interfaces may
|
|
28
|
+
still change.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
Python >= 3.12. Install torch first so you control the CUDA/CPU choice:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# CUDA (pick the index matching your driver) ...
|
|
36
|
+
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu126
|
|
37
|
+
# ... or CPU-only
|
|
38
|
+
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
|
|
39
|
+
|
|
40
|
+
pip install semantic-kinematics
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
This also installs [Lagrangian Gradient Regression](https://github.com/TannerHarms/Lagrangian-Gradient-Regression)
|
|
44
|
+
(`lagrangian-gradient-regression` on PyPI, imported as `lgr`).
|
|
45
|
+
|
|
46
|
+
The SAM-based render overlays are optional. They need Meta's Segment Anything,
|
|
47
|
+
which Meta does not publish on PyPI, and a 2.45 GB checkpoint:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install "segment-anything @ git+https://github.com/facebookresearch/segment-anything.git@dca509fe793f601edb92606367a655c15ac00fdf"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
To work on the package itself, clone the repository and run `pip install -e ".[dev]"`.
|
|
54
|
+
|
|
55
|
+
## Quickstart
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
semkin models fetch maskrcnn_lab_debris
|
|
59
|
+
semkin run configs/examples/alldebris_short.yaml
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
or `python examples/quickstart.py`. Useful commands: `semkin validate <cfg>`
|
|
63
|
+
(schema + registry + model checks, no compute), `semkin info <cfg>` (stage
|
|
64
|
+
keys and cache status), `semkin registry` (everything pluggable),
|
|
65
|
+
`semkin run -f track <cfg>` (force one stage and downstream).
|
|
66
|
+
|
|
67
|
+
## Model zoo
|
|
68
|
+
|
|
69
|
+
Weights are GitHub Release assets (tag `models-v1`), fetched on demand into
|
|
70
|
+
a local cache and SHA256-verified. `semkin models list` shows cache status.
|
|
71
|
+
|
|
72
|
+
| Name | Architecture | Domain | Epochs |
|
|
73
|
+
|---|---|---|---|
|
|
74
|
+
| `maskrcnn_pond_debris` | Mask R-CNN ResNet50-FPN **v2** | field pond debris (TurtlePonds, 35 mm) | 150 |
|
|
75
|
+
| `maskrcnn_lab_debris` | Mask R-CNN ResNet50-FPN **v2** | lab debris (SplitFlow) | 100 |
|
|
76
|
+
| `maskrcnn_sheep_flow` | Mask R-CNN ResNet50-FPN **v2** | sheep herds (aerial) | 100 |
|
|
77
|
+
| `sam_vit_h` | SAM ViT-H | stock upstream checkpoint (Meta CDN) | — |
|
|
78
|
+
|
|
79
|
+
Each registry entry pins the training-time inference settings
|
|
80
|
+
(`builder_kwargs`) recovered from the original models — reproducing them is
|
|
81
|
+
part of reproducing the paper. See [docs/models.md](https://github.com/TannerHarms/SemanticKinematics/blob/main/docs/models.md) and
|
|
82
|
+
[docs/specs/model_registry.md](https://github.com/TannerHarms/SemanticKinematics/blob/main/docs/specs/model_registry.md).
|
|
83
|
+
|
|
84
|
+
## Data and outputs
|
|
85
|
+
|
|
86
|
+
- Committed: two small fixture clips (`data/videos/`) and 44 hand-annotated
|
|
87
|
+
training frames (`data/annotations/turtle_ponds/`). Nothing bigger enters
|
|
88
|
+
git (enforced by a test).
|
|
89
|
+
- Outputs: `artifacts/<run>/<stage>/<key>/` with a manifest per stage; see
|
|
90
|
+
[docs/specs/pipeline_stages.md](https://github.com/TannerHarms/SemanticKinematics/blob/main/docs/specs/pipeline_stages.md).
|
|
91
|
+
- Model cache: `platformdirs.user_cache_dir("semantic_kinematics")` —
|
|
92
|
+
`%LOCALAPPDATA%\semantic_kinematics\semantic_kinematics\Cache` on Windows,
|
|
93
|
+
`~/.cache/semantic_kinematics` on Linux; override `SEMKIN_CACHE_DIR`.
|
|
94
|
+
`SEMKIN_OFFLINE=1` forbids downloads.
|
|
95
|
+
|
|
96
|
+
## Testing
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pytest # fast suite: unit tests + synthetic end-to-end pipeline
|
|
100
|
+
pytest --runslow # adds real model inference (needs cached models)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
See [docs/specs/testing.md](https://github.com/TannerHarms/SemanticKinematics/blob/main/docs/specs/testing.md).
|
|
104
|
+
|
|
105
|
+
## Development
|
|
106
|
+
|
|
107
|
+
```powershell
|
|
108
|
+
# Windows: creates the venv OUTSIDE OneDrive, installs CUDA torch,
|
|
109
|
+
# this package editable, and the local lgr checkout editable.
|
|
110
|
+
scripts\dev_setup.ps1 # or -Torch cpu
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Point your IDE at `%LOCALAPPDATA%\venvs\semkin\Scripts\python.exe`.
|
|
114
|
+
Lint with `ruff check src tests examples`. House conventions mirror the lgr
|
|
115
|
+
repo; see [docs/specs/index.md](https://github.com/TannerHarms/SemanticKinematics/blob/main/docs/specs/index.md).
|
|
116
|
+
|
|
117
|
+
## Citation
|
|
118
|
+
|
|
119
|
+
See [CITATION.cff](https://github.com/TannerHarms/SemanticKinematics/blob/main/CITATION.cff).
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT — see [LICENSE](https://github.com/TannerHarms/SemanticKinematics/blob/main/LICENSE).
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Semantic Kinematics
|
|
2
|
+
|
|
3
|
+
This repository contains code for semantic kinematics analysis. The project includes various modules for detection, tracking, visualization, and file management.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [Contributing](#contributing)
|
|
10
|
+
- [License](#license)
|
|
11
|
+
|
|
12
|
+
## Setup
|
|
13
|
+
|
|
14
|
+
### Prerequisites
|
|
15
|
+
|
|
16
|
+
- Python 3.x
|
|
17
|
+
|
|
18
|
+
### Installation
|
|
19
|
+
|
|
20
|
+
1. Clone the repository:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
git clone https://github.com/yourusername/SemanticKinematics.git
|
|
24
|
+
cd SemanticKinematics
|
|
25
|
+
```
|
|
26
|
+
2. Create a virtual environment:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
python -m venv venv
|
|
30
|
+
```
|
|
31
|
+
3. Activate the virtual environment:
|
|
32
|
+
|
|
33
|
+
- On Windows:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
venv\Scripts\activate
|
|
37
|
+
```
|
|
38
|
+
- On macOS/Linux:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
source venv/bin/activate
|
|
42
|
+
```
|
|
43
|
+
4. Install the required packages:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
pip install -r requirements.txt
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Requirements
|
|
50
|
+
|
|
51
|
+
The required Python packages are listed in the requirements.txt file:
|
|
52
|
+
|
|
53
|
+
dill==0.3.7
|
|
54
|
+
matplotlib==3.7.2
|
|
55
|
+
netCDF4==1.6.5
|
|
56
|
+
netCDF4==1.7.1.post2
|
|
57
|
+
numpy==1.24.3
|
|
58
|
+
opencv_contrib_python==4.8.0.76
|
|
59
|
+
opencv_python==4.8.0.76
|
|
60
|
+
pandas==2.2.3
|
|
61
|
+
PyYAML==6.0.1
|
|
62
|
+
PyYAML==6.0.2
|
|
63
|
+
scikit_learn==1.3.1
|
|
64
|
+
scipy==1.14.1
|
|
65
|
+
segment_anything==1.0
|
|
66
|
+
skimage==0.0
|
|
67
|
+
torch==2.0.1+cu118
|
|
68
|
+
torchvision==0.15.2+cu118
|
|
69
|
+
xarray==2023.12.0
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
1. Supply a video file for analysis
|
|
74
|
+
2. Fill in generateParameters.py with the video path specified and with all desired parameters appropriately input. Running this will generate a JSON file that contains all of the parameters for the given implementation.
|
|
75
|
+
3. Run semanticKinematics.py to process the data. A directory structure will be generate containing the results of the analysis.
|
|
76
|
+
4. (Optional) Evaluate the processed results using testResults.py.
|
|
77
|
+
|
|
78
|
+
## Contributing
|
|
79
|
+
|
|
80
|
+
Contributions are welcome! Please open an issue or submit a pull request for any changes.
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "semantic-kinematics"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Video to flow physics: object detection, tracking, and Lagrangian gradient regression for measuring dynamic flow features in groups of tracked objects."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
authors = [{ name = "Tanner Harms" }]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Science/Research",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
dependencies = [
|
|
22
|
+
"numpy>=1.26",
|
|
23
|
+
"scipy>=1.11",
|
|
24
|
+
"pandas>=2.0",
|
|
25
|
+
"matplotlib>=3.8",
|
|
26
|
+
"opencv-python-headless>=4.8",
|
|
27
|
+
"scikit-image>=0.22",
|
|
28
|
+
"xarray>=2023.12",
|
|
29
|
+
"netcdf4>=1.6",
|
|
30
|
+
"pyarrow>=14",
|
|
31
|
+
"pillow>=10",
|
|
32
|
+
"pyyaml>=6.0",
|
|
33
|
+
"pydantic>=2.5",
|
|
34
|
+
"torch>=2.6",
|
|
35
|
+
"torchvision>=0.21",
|
|
36
|
+
"platformdirs>=3.0",
|
|
37
|
+
"tqdm>=4.65",
|
|
38
|
+
"typer>=0.9",
|
|
39
|
+
# Lagrangian Gradient Regression, imported as `lgr`. The PyPI project that
|
|
40
|
+
# is itself named `lgr` is an unrelated library.
|
|
41
|
+
"lagrangian-gradient-regression>=0.1.0",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.optional-dependencies]
|
|
45
|
+
# There is no `sam` extra: Meta's Segment Anything is not published on PyPI by
|
|
46
|
+
# Meta, and PyPI does not accept a package whose metadata points at a git URL.
|
|
47
|
+
# The SAM overlays need it installed separately; see the README.
|
|
48
|
+
dev = ["pytest>=7", "pytest-cov", "ruff"]
|
|
49
|
+
|
|
50
|
+
[project.scripts]
|
|
51
|
+
semkin = "semantic_kinematics.cli:main"
|
|
52
|
+
|
|
53
|
+
[project.urls]
|
|
54
|
+
Repository = "https://github.com/TannerHarms/SemanticKinematics"
|
|
55
|
+
Paper = "https://doi.org/10.1016/j.physd.2026.135335"
|
|
56
|
+
LGR = "https://github.com/TannerHarms/Lagrangian-Gradient-Regression"
|
|
57
|
+
Issues = "https://github.com/TannerHarms/SemanticKinematics/issues"
|
|
58
|
+
|
|
59
|
+
[tool.hatch.build.targets.wheel]
|
|
60
|
+
packages = ["src/semantic_kinematics"]
|
|
61
|
+
|
|
62
|
+
# The source distribution carries the package and its tests. The fixture videos,
|
|
63
|
+
# annotations, docs and legacy code stay in the repository.
|
|
64
|
+
[tool.hatch.build.targets.sdist]
|
|
65
|
+
include = ["src/semantic_kinematics", "tests", "README.md", "LICENSE", "CITATION.cff", "pyproject.toml"]
|
|
66
|
+
|
|
67
|
+
[tool.pytest.ini_options]
|
|
68
|
+
testpaths = ["tests"]
|
|
69
|
+
addopts = "-v --tb=short"
|
|
70
|
+
|
|
71
|
+
[tool.ruff]
|
|
72
|
+
line-length = 88
|
|
73
|
+
target-version = "py310"
|
|
74
|
+
extend-exclude = ["legacy"]
|
|
75
|
+
|
|
76
|
+
[tool.ruff.lint]
|
|
77
|
+
select = ["E", "F", "W", "I", "UP", "B", "SIM"]
|
|
78
|
+
ignore = ["E501"]
|
|
79
|
+
|
|
80
|
+
[tool.ruff.lint.per-file-ignores]
|
|
81
|
+
# typer's API is function calls in argument defaults.
|
|
82
|
+
"src/semantic_kinematics/cli.py" = ["B008"]
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""SemanticKinematics: flow physics from tracked objects in video.
|
|
2
|
+
|
|
3
|
+
Detection (tiled Mask R-CNN), tracking (cross-correlation), camera
|
|
4
|
+
calibration, and Lagrangian gradient regression (via the external ``lgr``
|
|
5
|
+
package), driven by a single validated config file.
|
|
6
|
+
|
|
7
|
+
``PRIMARY_API`` lists the supported entry points; everything else is
|
|
8
|
+
implementation detail and may move between releases.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from semantic_kinematics.config import PipelineConfig, load_config
|
|
14
|
+
from semantic_kinematics.core import (
|
|
15
|
+
CalibrationModel,
|
|
16
|
+
DetectionSet,
|
|
17
|
+
FrameDetections,
|
|
18
|
+
Track,
|
|
19
|
+
TrackSet,
|
|
20
|
+
VideoSource,
|
|
21
|
+
)
|
|
22
|
+
from semantic_kinematics.detect import Detector, register_detector
|
|
23
|
+
from semantic_kinematics.kinematics import (
|
|
24
|
+
KinematicsResult,
|
|
25
|
+
register_window_metric,
|
|
26
|
+
run_kinematics,
|
|
27
|
+
)
|
|
28
|
+
from semantic_kinematics.pipeline import run_pipeline
|
|
29
|
+
from semantic_kinematics.track import (
|
|
30
|
+
Tracker,
|
|
31
|
+
TrackTransform,
|
|
32
|
+
register_tracker,
|
|
33
|
+
register_transform,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
__version__ = "0.1.0"
|
|
37
|
+
|
|
38
|
+
PRIMARY_API: tuple[str, ...] = (
|
|
39
|
+
"load_config",
|
|
40
|
+
"run_pipeline",
|
|
41
|
+
"run_kinematics",
|
|
42
|
+
"Detector",
|
|
43
|
+
"Tracker",
|
|
44
|
+
"TrackTransform",
|
|
45
|
+
"register_detector",
|
|
46
|
+
"register_tracker",
|
|
47
|
+
"register_transform",
|
|
48
|
+
"register_window_metric",
|
|
49
|
+
"CalibrationModel",
|
|
50
|
+
"TrackSet",
|
|
51
|
+
"VideoSource",
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
__all__ = [
|
|
55
|
+
"CalibrationModel",
|
|
56
|
+
"DetectionSet",
|
|
57
|
+
"Detector",
|
|
58
|
+
"FrameDetections",
|
|
59
|
+
"KinematicsResult",
|
|
60
|
+
"PRIMARY_API",
|
|
61
|
+
"PipelineConfig",
|
|
62
|
+
"Track",
|
|
63
|
+
"TrackSet",
|
|
64
|
+
"TrackTransform",
|
|
65
|
+
"Tracker",
|
|
66
|
+
"VideoSource",
|
|
67
|
+
"__version__",
|
|
68
|
+
"load_config",
|
|
69
|
+
"register_detector",
|
|
70
|
+
"register_tracker",
|
|
71
|
+
"register_transform",
|
|
72
|
+
"register_window_metric",
|
|
73
|
+
"run_kinematics",
|
|
74
|
+
"run_pipeline",
|
|
75
|
+
]
|