kodokan 0.0.2__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.
- kodokan-0.0.2/.gitattributes +1 -0
- kodokan-0.0.2/.github/workflows/ci.yml +48 -0
- kodokan-0.0.2/.gitignore +128 -0
- kodokan-0.0.2/LICENSE +21 -0
- kodokan-0.0.2/PKG-INFO +170 -0
- kodokan-0.0.2/README.md +116 -0
- kodokan-0.0.2/examples/batch_pipeline.py +78 -0
- kodokan-0.0.2/examples/compare_demos.py +97 -0
- kodokan-0.0.2/examples/dataset_overview.py +90 -0
- kodokan-0.0.2/examples/eval_features.py +69 -0
- kodokan-0.0.2/examples/eval_features_3d.py +97 -0
- kodokan-0.0.2/examples/export_2d_bridge.py +44 -0
- kodokan-0.0.2/examples/score_demos.py +110 -0
- kodokan-0.0.2/examples/segment_review.py +83 -0
- kodokan-0.0.2/examples/warmup_seoinage.py +57 -0
- kodokan-0.0.2/kodokan/__init__.py +51 -0
- kodokan-0.0.2/kodokan/acquire.py +93 -0
- kodokan-0.0.2/kodokan/compare.py +138 -0
- kodokan-0.0.2/kodokan/config.py +47 -0
- kodokan-0.0.2/kodokan/descriptors.py +119 -0
- kodokan-0.0.2/kodokan/pose.py +320 -0
- kodokan-0.0.2/kodokan/score.py +112 -0
- kodokan-0.0.2/kodokan/segment.py +313 -0
- kodokan-0.0.2/kodokan/store.py +160 -0
- kodokan-0.0.2/kodokan/track.py +215 -0
- kodokan-0.0.2/kodokan/viz.py +226 -0
- kodokan-0.0.2/misc/docs/dataset.md +64 -0
- kodokan-0.0.2/misc/docs/feature-bakeoff.md +63 -0
- kodokan-0.0.2/misc/docs/playlist_index.txt +100 -0
- kodokan-0.0.2/misc/docs/research-architecture.md +453 -0
- kodokan-0.0.2/pyproject.toml +203 -0
- kodokan-0.0.2/scripts/lift_3d_mediapipe.py +105 -0
- kodokan-0.0.2/tests/conftest.py +38 -0
- kodokan-0.0.2/tests/test_compare.py +36 -0
- kodokan-0.0.2/tests/test_descriptors.py +28 -0
- kodokan-0.0.2/tests/test_pose.py +28 -0
- kodokan-0.0.2/tests/test_score.py +41 -0
- kodokan-0.0.2/tests/test_segment.py +50 -0
- kodokan-0.0.2/tests/test_store.py +39 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.ipynb linguist-documentation
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# wads CI — calls the reusable workflow hosted in i2mint/wads.
|
|
2
|
+
#
|
|
3
|
+
# All configuration comes from this repo's pyproject.toml [tool.wads.ci.*].
|
|
4
|
+
# To customize the workflow itself (rare), replace this file with the
|
|
5
|
+
# full inline template `wads/data/github_ci_uv.yml` from i2mint/wads.
|
|
6
|
+
#
|
|
7
|
+
# Pinning: `@master` floats with wads. If you need version stability for
|
|
8
|
+
# a release-sensitive repo, change `@master` to a wads tag (e.g. `@v0.1.81`).
|
|
9
|
+
# CI failure does not block a published release — it blocks the publish
|
|
10
|
+
# step itself — so floating master is generally safe.
|
|
11
|
+
#
|
|
12
|
+
# Permissions: GitHub validates that the caller grants AT LEAST the
|
|
13
|
+
# permissions any job in the called workflow requests — at workflow-parse
|
|
14
|
+
# time, not at run-time, even if the job would be skipped via `if:`.
|
|
15
|
+
# The reusable workflow needs:
|
|
16
|
+
# contents: write for the publish job's version-bump push-back
|
|
17
|
+
# and for the github-pages job's gh-pages branch push
|
|
18
|
+
# pages: write for the github-pages job's REST API Pages config
|
|
19
|
+
# Both default to `write` on org-account GITHUB_TOKEN and need to be
|
|
20
|
+
# granted explicitly on personal-account callers (where the default is
|
|
21
|
+
# read-only). No `id-token: write` needed — the publish-github-pages
|
|
22
|
+
# action uses peaceiris/actions-gh-pages (branch-based) + REST API,
|
|
23
|
+
# not the OIDC `actions/deploy-pages` flow.
|
|
24
|
+
name: Continuous Integration
|
|
25
|
+
on: [push, pull_request]
|
|
26
|
+
jobs:
|
|
27
|
+
ci:
|
|
28
|
+
uses: i2mint/wads/.github/workflows/uv-ci.yml@master
|
|
29
|
+
permissions:
|
|
30
|
+
contents: write
|
|
31
|
+
pages: write
|
|
32
|
+
# Explicit pass-through (not `secrets: inherit`) because `inherit` does
|
|
33
|
+
# not reliably propagate caller-repo secrets to a reusable workflow owned
|
|
34
|
+
# by a different account (verified empirically: personal-account caller +
|
|
35
|
+
# i2mint-org workflow → `${{ secrets.PYPI_PASSWORD }}` resolved to empty).
|
|
36
|
+
#
|
|
37
|
+
# This list is the per-repo *transport*: it should contain PYPI_PASSWORD
|
|
38
|
+
# (for publishing) plus every secret your tests/CI need. It is generated
|
|
39
|
+
# from [tool.wads.ci.env] in pyproject.toml. To add one, run
|
|
40
|
+
# wads-secrets add VAR_NAME # updates pyproject + this block
|
|
41
|
+
# or just append a line below. *Which* of these become job env vars (and
|
|
42
|
+
# which are required) is controlled by [tool.wads.ci.env] — passing a
|
|
43
|
+
# secret here does not by itself put it in the environment.
|
|
44
|
+
#
|
|
45
|
+
# A secret name must also be declared in the reusable workflow's superset
|
|
46
|
+
# (wads/ci_secrets.py). `wads-secrets add` warns if it is not.
|
|
47
|
+
secrets:
|
|
48
|
+
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
|
kodokan-0.0.2/.gitignore
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
.claude/handoffs/
|
|
2
|
+
.claude/scratch/
|
|
3
|
+
|
|
4
|
+
# Byte-compiled / optimized / DLL files
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*$py.class
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
.DS_Store
|
|
11
|
+
# C extensions
|
|
12
|
+
*.so
|
|
13
|
+
|
|
14
|
+
# TLS certificates
|
|
15
|
+
## Ignore all PEM files anywhere
|
|
16
|
+
*.pem
|
|
17
|
+
## Also ignore any certs directory
|
|
18
|
+
certs/
|
|
19
|
+
|
|
20
|
+
# Distribution / packaging
|
|
21
|
+
.Python
|
|
22
|
+
build/
|
|
23
|
+
develop-eggs/
|
|
24
|
+
dist/
|
|
25
|
+
downloads/
|
|
26
|
+
eggs/
|
|
27
|
+
.eggs/
|
|
28
|
+
lib/
|
|
29
|
+
lib64/
|
|
30
|
+
parts/
|
|
31
|
+
sdist/
|
|
32
|
+
var/
|
|
33
|
+
wheels/
|
|
34
|
+
*.egg-info/
|
|
35
|
+
.installed.cfg
|
|
36
|
+
*.egg
|
|
37
|
+
MANIFEST
|
|
38
|
+
_build
|
|
39
|
+
|
|
40
|
+
# PyInstaller
|
|
41
|
+
# Usually these files are written by a python script from a template
|
|
42
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
43
|
+
*.manifest
|
|
44
|
+
*.spec
|
|
45
|
+
|
|
46
|
+
# Installer logs
|
|
47
|
+
pip-log.txt
|
|
48
|
+
pip-delete-this-directory.txt
|
|
49
|
+
|
|
50
|
+
# Unit test / coverage reports
|
|
51
|
+
htmlcov/
|
|
52
|
+
.tox/
|
|
53
|
+
.coverage
|
|
54
|
+
.coverage.*
|
|
55
|
+
.cache
|
|
56
|
+
nosetests.xml
|
|
57
|
+
coverage.xml
|
|
58
|
+
*.cover
|
|
59
|
+
.hypothesis/
|
|
60
|
+
.pytest_cache/
|
|
61
|
+
|
|
62
|
+
# Translations
|
|
63
|
+
*.mo
|
|
64
|
+
*.pot
|
|
65
|
+
|
|
66
|
+
# Django stuff:
|
|
67
|
+
*.log
|
|
68
|
+
local_settings.py
|
|
69
|
+
db.sqlite3
|
|
70
|
+
|
|
71
|
+
# Flask stuff:
|
|
72
|
+
instance/
|
|
73
|
+
.webassets-cache
|
|
74
|
+
|
|
75
|
+
# Scrapy stuff:
|
|
76
|
+
.scrapy
|
|
77
|
+
|
|
78
|
+
# Sphinx documentation
|
|
79
|
+
docs/_build/
|
|
80
|
+
docs/*
|
|
81
|
+
|
|
82
|
+
# PyBuilder
|
|
83
|
+
target/
|
|
84
|
+
|
|
85
|
+
# Jupyter Notebook
|
|
86
|
+
.ipynb_checkpoints
|
|
87
|
+
|
|
88
|
+
# pyenv
|
|
89
|
+
.python-version
|
|
90
|
+
|
|
91
|
+
# celery beat schedule file
|
|
92
|
+
celerybeat-schedule
|
|
93
|
+
|
|
94
|
+
# SageMath parsed files
|
|
95
|
+
*.sage.py
|
|
96
|
+
|
|
97
|
+
# Environments
|
|
98
|
+
.env
|
|
99
|
+
.venv
|
|
100
|
+
env/
|
|
101
|
+
venv/
|
|
102
|
+
ENV/
|
|
103
|
+
env.bak/
|
|
104
|
+
venv.bak/
|
|
105
|
+
|
|
106
|
+
# Spyder project settings
|
|
107
|
+
.spyderproject
|
|
108
|
+
.spyproject
|
|
109
|
+
|
|
110
|
+
# Rope project settings
|
|
111
|
+
.ropeproject
|
|
112
|
+
|
|
113
|
+
# mkdocs documentation
|
|
114
|
+
/site
|
|
115
|
+
|
|
116
|
+
# mypy
|
|
117
|
+
.mypy_cache/
|
|
118
|
+
|
|
119
|
+
# PyCharm
|
|
120
|
+
.idea
|
|
121
|
+
|
|
122
|
+
# ML model weights (auto-downloaded by ultralytics/rtmlib)
|
|
123
|
+
*.pt
|
|
124
|
+
*.onnx
|
|
125
|
+
|
|
126
|
+
# kodokan data artifacts (videos/keypoints/renders live outside the repo by default)
|
|
127
|
+
/data/
|
|
128
|
+
kodokan_data/
|
kodokan-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thor Whalen
|
|
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.
|
kodokan-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kodokan
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Study Kodokan Judo throws from video via body-pose analysis
|
|
5
|
+
Project-URL: Homepage, https://github.com/thorwhalen/kodokan
|
|
6
|
+
Project-URL: Repository, https://github.com/thorwhalen/kodokan
|
|
7
|
+
Project-URL: Documentation, https://thorwhalen.github.io/kodokan
|
|
8
|
+
Author: Thor Whalen
|
|
9
|
+
License: mit
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: action-segmentation,judo,mediapipe,pose-estimation,video-analysis
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Requires-Dist: numpy
|
|
14
|
+
Provides-Extra: acquire
|
|
15
|
+
Requires-Dist: yb; extra == 'acquire'
|
|
16
|
+
Provides-Extra: all
|
|
17
|
+
Requires-Dist: dol; extra == 'all'
|
|
18
|
+
Requires-Dist: dtaidistance; extra == 'all'
|
|
19
|
+
Requires-Dist: matplotlib; extra == 'all'
|
|
20
|
+
Requires-Dist: onnxruntime; extra == 'all'
|
|
21
|
+
Requires-Dist: opencv-python; extra == 'all'
|
|
22
|
+
Requires-Dist: pandas; extra == 'all'
|
|
23
|
+
Requires-Dist: pyarrow; extra == 'all'
|
|
24
|
+
Requires-Dist: rerun-sdk; extra == 'all'
|
|
25
|
+
Requires-Dist: rtmlib; extra == 'all'
|
|
26
|
+
Requires-Dist: scipy; extra == 'all'
|
|
27
|
+
Requires-Dist: supervision; extra == 'all'
|
|
28
|
+
Requires-Dist: ultralytics; extra == 'all'
|
|
29
|
+
Requires-Dist: yb; extra == 'all'
|
|
30
|
+
Provides-Extra: analysis
|
|
31
|
+
Requires-Dist: dtaidistance; extra == 'analysis'
|
|
32
|
+
Requires-Dist: pandas; extra == 'analysis'
|
|
33
|
+
Requires-Dist: pyarrow; extra == 'analysis'
|
|
34
|
+
Requires-Dist: scipy; extra == 'analysis'
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
39
|
+
Provides-Extra: docs
|
|
40
|
+
Requires-Dist: sphinx-rtd-theme>=1.0; extra == 'docs'
|
|
41
|
+
Requires-Dist: sphinx>=6.0; extra == 'docs'
|
|
42
|
+
Provides-Extra: pose
|
|
43
|
+
Requires-Dist: onnxruntime; extra == 'pose'
|
|
44
|
+
Requires-Dist: rtmlib; extra == 'pose'
|
|
45
|
+
Requires-Dist: ultralytics; extra == 'pose'
|
|
46
|
+
Provides-Extra: storage
|
|
47
|
+
Requires-Dist: dol; extra == 'storage'
|
|
48
|
+
Provides-Extra: viz
|
|
49
|
+
Requires-Dist: matplotlib; extra == 'viz'
|
|
50
|
+
Requires-Dist: opencv-python; extra == 'viz'
|
|
51
|
+
Requires-Dist: rerun-sdk; extra == 'viz'
|
|
52
|
+
Requires-Dist: supervision; extra == 'viz'
|
|
53
|
+
Description-Content-Type: text/markdown
|
|
54
|
+
|
|
55
|
+
# kodokan
|
|
56
|
+
|
|
57
|
+
Study Kodokan Judo throws from video via body-pose analysis: download technique
|
|
58
|
+
demonstrations, extract two-person (tori/uke) skeletons, split each clip into its
|
|
59
|
+
repeated demonstrations, visualize them, and compare/score demonstrations.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from kodokan.acquire import download_techniques
|
|
63
|
+
from kodokan.track import estimate_poses_tracked
|
|
64
|
+
from kodokan.segment import segment_demonstrations
|
|
65
|
+
from kodokan.viz import render_skeleton_video
|
|
66
|
+
|
|
67
|
+
res = download_techniques(playlist_items="2")[0] # Seoi-nage (#002), with metadata
|
|
68
|
+
seq = estimate_poses_tracked(res.path, source_url=res.info["webpage_url"]) # tracked tori/uke COCO-17
|
|
69
|
+
demos = segment_demonstrations(seq, min_two_person_frac=0.3) # per-demo (start_s, end_s)
|
|
70
|
+
render_skeleton_video(seq, out_path="overlay.mp4", source_video=res.path) # skeletons on the video
|
|
71
|
+
render_skeleton_video(seq, out_path="skeleton.mp4", blank_canvas=True) # skeletons on blank canvas
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## What it does
|
|
75
|
+
|
|
76
|
+
A functional pipeline over the official *Kodokan 100 Techniques* YouTube playlist:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
acquire (yb) ─► pose (rtmlib / YOLO, tracked tori/uke) ─► segment (motion-energy)
|
|
80
|
+
└─► dol stores (Parquet pose + JSON segments) ─► visualize (overlay / blank / Rerun)
|
|
81
|
+
└─► compare two demos (joint-angle DTW) ─► score + eval harness
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
YouTube acquisition lives in the [`yb`](https://github.com/thorwhalen/yb) package
|
|
85
|
+
(`download_youtube_playlist`); `kodokan` is the analysis layer on top.
|
|
86
|
+
|
|
87
|
+
## Install
|
|
88
|
+
|
|
89
|
+
`import kodokan` needs only **numpy**; everything heavy is an optional extra (imported
|
|
90
|
+
lazily on first use), so the import never fails for a missing one:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install -e '.[all]' # or pick extras: .[pose,viz,analysis,storage,acquire]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
| extra | for | brings |
|
|
97
|
+
|---|---|---|
|
|
98
|
+
| `pose` | pose estimation | rtmlib, onnxruntime, ultralytics |
|
|
99
|
+
| `viz` | rendering | opencv-python, rerun-sdk, supervision, matplotlib |
|
|
100
|
+
| `analysis` | segment / compare / score | scipy, dtaidistance, pandas, pyarrow |
|
|
101
|
+
| `storage` | dol stores | dol |
|
|
102
|
+
| `acquire` | YouTube download | yb |
|
|
103
|
+
|
|
104
|
+
You also need **ffmpeg** on PATH (acquisition/merge). The optional **3D lift**
|
|
105
|
+
(`scripts/lift_3d_mediapipe.py`) runs in a **separate venv**, because MediaPipe is
|
|
106
|
+
ABI-incompatible with numpy 2.x:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
python -m venv ~/.kodokan_mp
|
|
110
|
+
~/.kodokan_mp/bin/pip install 'mediapipe==0.10.18' 'numpy<2' 'opencv-python-headless==4.10.0.84'
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Data (videos, keypoints, renders, weights) lives **outside the repo** under
|
|
114
|
+
`~/kodokan_data` (override with `KODOKAN_DATA_DIR`).
|
|
115
|
+
|
|
116
|
+
## The pipeline
|
|
117
|
+
|
|
118
|
+
| module | purpose |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `kodokan.acquire` | download techniques (wraps `yb`), skip the PV, keep source URLs |
|
|
121
|
+
| `kodokan.pose` | `estimate_poses` facade (rtmlib / ultralytics backends), COCO-17, `PoseSequence` |
|
|
122
|
+
| `kodokan.track` | `estimate_poses_tracked` — stable tori/uke identity (BoT-SORT + spatial continuity) |
|
|
123
|
+
| `kodokan.segment` | hysteresis motion-energy segmentation + two-person gate + self-similarity |
|
|
124
|
+
| `kodokan.store` | `pose_store` (tidy Parquet) / `segments_store` (JSON), the analysis SSOT |
|
|
125
|
+
| `kodokan.viz` | overlay / blank-canvas MP4 + Rerun logging |
|
|
126
|
+
| `kodokan.compare` | joint-angle (soft-)DTW comparison of two demonstrations |
|
|
127
|
+
| `kodokan.score` | reference-based 0–100 scoring + per-joint/per-phase feedback |
|
|
128
|
+
| `kodokan.descriptors` | experimental feature descriptors (for the eval harness) |
|
|
129
|
+
|
|
130
|
+
Runnable end-to-end examples live in `examples/` (`warmup_seoinage.py`,
|
|
131
|
+
`batch_pipeline.py`, `segment_review.py`, `compare_demos.py`, `score_demos.py`,
|
|
132
|
+
`eval_features.py`).
|
|
133
|
+
|
|
134
|
+
## Dataset
|
|
135
|
+
|
|
136
|
+
`examples/batch_pipeline.py` builds a small dataset (10 techniques · 84
|
|
137
|
+
demonstrations · 18.3k frames) into the `dol` stores. Load it:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from kodokan.store import pose_store, segments_store, load_all_tidy
|
|
141
|
+
seq = pose_store()["zIq0xI0ogxk"] # (F, 2, 17, 3) COCO-17 (x, y, conf)
|
|
142
|
+
demos = segments_store()["zIq0xI0ogxk"] # demo intervals + source_url
|
|
143
|
+
df = load_all_tidy() # tidy DataFrame across all clips
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
See [`misc/docs/dataset.md`](misc/docs/dataset.md).
|
|
147
|
+
|
|
148
|
+
## Status & honest limits
|
|
149
|
+
|
|
150
|
+
Works well: acquisition, tracked two-person pose, demo segmentation, the dol stores,
|
|
151
|
+
visualization, and same-technique demo comparison (joint-angle DTW is speed-invariant)
|
|
152
|
+
with interpretable per-joint/per-phase feedback.
|
|
153
|
+
|
|
154
|
+
Does **not** work yet — and this is *measured, not assumed*: **technique recognition /
|
|
155
|
+
cross-demo scoring**. A feature bake-off ([`misc/docs/feature-bakeoff.md`](misc/docs/feature-bakeoff.md))
|
|
156
|
+
shows every 2D descriptor *and* MediaPipe 3D joint angles sit at chance (separation
|
|
157
|
+
AUC ≈ 0.49–0.56). The blockers are noisy monocular 3D under grappling occlusion,
|
|
158
|
+
tori/uke role inconsistency, and the weakness of hand-crafted angle-DTW for few
|
|
159
|
+
examples — not viewpoint alone. Recognition needs a **learned** skeleton representation
|
|
160
|
+
(few-shot JEANIE, or trained PoseC3D/CTR-GCN) and/or cleaner multi-person 3D with
|
|
161
|
+
role-consistent features. The eval harness (`examples/eval_features*.py`) is ready to
|
|
162
|
+
validate those.
|
|
163
|
+
|
|
164
|
+
## Background & rationale
|
|
165
|
+
|
|
166
|
+
- [`misc/docs/research-architecture.md`](misc/docs/research-architecture.md) — cited
|
|
167
|
+
tools/architecture research (75 refs).
|
|
168
|
+
- [`misc/docs/dataset.md`](misc/docs/dataset.md) — dataset card.
|
|
169
|
+
- [`misc/docs/feature-bakeoff.md`](misc/docs/feature-bakeoff.md) — why hand-crafted
|
|
170
|
+
features don't discriminate techniques (the empirical finding).
|
kodokan-0.0.2/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# kodokan
|
|
2
|
+
|
|
3
|
+
Study Kodokan Judo throws from video via body-pose analysis: download technique
|
|
4
|
+
demonstrations, extract two-person (tori/uke) skeletons, split each clip into its
|
|
5
|
+
repeated demonstrations, visualize them, and compare/score demonstrations.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from kodokan.acquire import download_techniques
|
|
9
|
+
from kodokan.track import estimate_poses_tracked
|
|
10
|
+
from kodokan.segment import segment_demonstrations
|
|
11
|
+
from kodokan.viz import render_skeleton_video
|
|
12
|
+
|
|
13
|
+
res = download_techniques(playlist_items="2")[0] # Seoi-nage (#002), with metadata
|
|
14
|
+
seq = estimate_poses_tracked(res.path, source_url=res.info["webpage_url"]) # tracked tori/uke COCO-17
|
|
15
|
+
demos = segment_demonstrations(seq, min_two_person_frac=0.3) # per-demo (start_s, end_s)
|
|
16
|
+
render_skeleton_video(seq, out_path="overlay.mp4", source_video=res.path) # skeletons on the video
|
|
17
|
+
render_skeleton_video(seq, out_path="skeleton.mp4", blank_canvas=True) # skeletons on blank canvas
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## What it does
|
|
21
|
+
|
|
22
|
+
A functional pipeline over the official *Kodokan 100 Techniques* YouTube playlist:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
acquire (yb) ─► pose (rtmlib / YOLO, tracked tori/uke) ─► segment (motion-energy)
|
|
26
|
+
└─► dol stores (Parquet pose + JSON segments) ─► visualize (overlay / blank / Rerun)
|
|
27
|
+
└─► compare two demos (joint-angle DTW) ─► score + eval harness
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
YouTube acquisition lives in the [`yb`](https://github.com/thorwhalen/yb) package
|
|
31
|
+
(`download_youtube_playlist`); `kodokan` is the analysis layer on top.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
`import kodokan` needs only **numpy**; everything heavy is an optional extra (imported
|
|
36
|
+
lazily on first use), so the import never fails for a missing one:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install -e '.[all]' # or pick extras: .[pose,viz,analysis,storage,acquire]
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
| extra | for | brings |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| `pose` | pose estimation | rtmlib, onnxruntime, ultralytics |
|
|
45
|
+
| `viz` | rendering | opencv-python, rerun-sdk, supervision, matplotlib |
|
|
46
|
+
| `analysis` | segment / compare / score | scipy, dtaidistance, pandas, pyarrow |
|
|
47
|
+
| `storage` | dol stores | dol |
|
|
48
|
+
| `acquire` | YouTube download | yb |
|
|
49
|
+
|
|
50
|
+
You also need **ffmpeg** on PATH (acquisition/merge). The optional **3D lift**
|
|
51
|
+
(`scripts/lift_3d_mediapipe.py`) runs in a **separate venv**, because MediaPipe is
|
|
52
|
+
ABI-incompatible with numpy 2.x:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
python -m venv ~/.kodokan_mp
|
|
56
|
+
~/.kodokan_mp/bin/pip install 'mediapipe==0.10.18' 'numpy<2' 'opencv-python-headless==4.10.0.84'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Data (videos, keypoints, renders, weights) lives **outside the repo** under
|
|
60
|
+
`~/kodokan_data` (override with `KODOKAN_DATA_DIR`).
|
|
61
|
+
|
|
62
|
+
## The pipeline
|
|
63
|
+
|
|
64
|
+
| module | purpose |
|
|
65
|
+
|---|---|
|
|
66
|
+
| `kodokan.acquire` | download techniques (wraps `yb`), skip the PV, keep source URLs |
|
|
67
|
+
| `kodokan.pose` | `estimate_poses` facade (rtmlib / ultralytics backends), COCO-17, `PoseSequence` |
|
|
68
|
+
| `kodokan.track` | `estimate_poses_tracked` — stable tori/uke identity (BoT-SORT + spatial continuity) |
|
|
69
|
+
| `kodokan.segment` | hysteresis motion-energy segmentation + two-person gate + self-similarity |
|
|
70
|
+
| `kodokan.store` | `pose_store` (tidy Parquet) / `segments_store` (JSON), the analysis SSOT |
|
|
71
|
+
| `kodokan.viz` | overlay / blank-canvas MP4 + Rerun logging |
|
|
72
|
+
| `kodokan.compare` | joint-angle (soft-)DTW comparison of two demonstrations |
|
|
73
|
+
| `kodokan.score` | reference-based 0–100 scoring + per-joint/per-phase feedback |
|
|
74
|
+
| `kodokan.descriptors` | experimental feature descriptors (for the eval harness) |
|
|
75
|
+
|
|
76
|
+
Runnable end-to-end examples live in `examples/` (`warmup_seoinage.py`,
|
|
77
|
+
`batch_pipeline.py`, `segment_review.py`, `compare_demos.py`, `score_demos.py`,
|
|
78
|
+
`eval_features.py`).
|
|
79
|
+
|
|
80
|
+
## Dataset
|
|
81
|
+
|
|
82
|
+
`examples/batch_pipeline.py` builds a small dataset (10 techniques · 84
|
|
83
|
+
demonstrations · 18.3k frames) into the `dol` stores. Load it:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from kodokan.store import pose_store, segments_store, load_all_tidy
|
|
87
|
+
seq = pose_store()["zIq0xI0ogxk"] # (F, 2, 17, 3) COCO-17 (x, y, conf)
|
|
88
|
+
demos = segments_store()["zIq0xI0ogxk"] # demo intervals + source_url
|
|
89
|
+
df = load_all_tidy() # tidy DataFrame across all clips
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
See [`misc/docs/dataset.md`](misc/docs/dataset.md).
|
|
93
|
+
|
|
94
|
+
## Status & honest limits
|
|
95
|
+
|
|
96
|
+
Works well: acquisition, tracked two-person pose, demo segmentation, the dol stores,
|
|
97
|
+
visualization, and same-technique demo comparison (joint-angle DTW is speed-invariant)
|
|
98
|
+
with interpretable per-joint/per-phase feedback.
|
|
99
|
+
|
|
100
|
+
Does **not** work yet — and this is *measured, not assumed*: **technique recognition /
|
|
101
|
+
cross-demo scoring**. A feature bake-off ([`misc/docs/feature-bakeoff.md`](misc/docs/feature-bakeoff.md))
|
|
102
|
+
shows every 2D descriptor *and* MediaPipe 3D joint angles sit at chance (separation
|
|
103
|
+
AUC ≈ 0.49–0.56). The blockers are noisy monocular 3D under grappling occlusion,
|
|
104
|
+
tori/uke role inconsistency, and the weakness of hand-crafted angle-DTW for few
|
|
105
|
+
examples — not viewpoint alone. Recognition needs a **learned** skeleton representation
|
|
106
|
+
(few-shot JEANIE, or trained PoseC3D/CTR-GCN) and/or cleaner multi-person 3D with
|
|
107
|
+
role-consistent features. The eval harness (`examples/eval_features*.py`) is ready to
|
|
108
|
+
validate those.
|
|
109
|
+
|
|
110
|
+
## Background & rationale
|
|
111
|
+
|
|
112
|
+
- [`misc/docs/research-architecture.md`](misc/docs/research-architecture.md) — cited
|
|
113
|
+
tools/architecture research (75 refs).
|
|
114
|
+
- [`misc/docs/dataset.md`](misc/docs/dataset.md) — dataset card.
|
|
115
|
+
- [`misc/docs/feature-bakeoff.md`](misc/docs/feature-bakeoff.md) — why hand-crafted
|
|
116
|
+
features don't discriminate techniques (the empirical finding).
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Batch the pipeline over several techniques into the dol stores.
|
|
2
|
+
|
|
3
|
+
Downloads a range of playlist techniques (idempotent via a yt-dlp download
|
|
4
|
+
archive), then for each clip runs tracked two-person pose and demo segmentation,
|
|
5
|
+
writing results to the Parquet pose store and JSON segments store. Prints a
|
|
6
|
+
summary table.
|
|
7
|
+
|
|
8
|
+
Usage::
|
|
9
|
+
PYTHONPATH=<repo> python examples/batch_pipeline.py --items 2:11
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
import numpy as np
|
|
16
|
+
|
|
17
|
+
from kodokan import config, store
|
|
18
|
+
from kodokan.acquire import download_techniques, local_clips
|
|
19
|
+
from kodokan.segment import segment_demonstrations
|
|
20
|
+
from kodokan.track import estimate_poses_tracked
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main():
|
|
24
|
+
ap = argparse.ArgumentParser()
|
|
25
|
+
ap.add_argument("--items", default="2:11", help="yt-dlp 1-based playlist selector (#002-#011)")
|
|
26
|
+
ap.add_argument("--frame-step", type=int, default=1)
|
|
27
|
+
ap.add_argument("--device", default="mps")
|
|
28
|
+
args = ap.parse_args()
|
|
29
|
+
|
|
30
|
+
archive = config.clips_dir() / ".download_archive.txt"
|
|
31
|
+
print(f"[acquire] playlist items {args.items} (archive: {archive.name}) ...", flush=True)
|
|
32
|
+
download_techniques(playlist_items=args.items, download_archive=str(archive))
|
|
33
|
+
clips = local_clips() # process whatever is on disk (robust to archive skips)
|
|
34
|
+
print(f"[acquire] {len(clips)} clips on disk", flush=True)
|
|
35
|
+
|
|
36
|
+
ps = store.pose_store()
|
|
37
|
+
ss = store.segments_store()
|
|
38
|
+
summary = []
|
|
39
|
+
|
|
40
|
+
for c in clips:
|
|
41
|
+
vid, title, url, path = c["id"], c["title"], c["webpage_url"], c["path"]
|
|
42
|
+
if not path or not Path(path).exists():
|
|
43
|
+
print(f"[skip] {vid} {title!r}: file missing", flush=True)
|
|
44
|
+
continue
|
|
45
|
+
print(f"\n=== {vid} {title} ===", flush=True)
|
|
46
|
+
seq = estimate_poses_tracked(
|
|
47
|
+
path, frame_step=args.frame_step, device=args.device, source_url=url, progress=True
|
|
48
|
+
)
|
|
49
|
+
ps[vid] = seq
|
|
50
|
+
segs = segment_demonstrations(
|
|
51
|
+
seq, smooth_sigma=5, low_quantile=0.25, high_quantile=0.5,
|
|
52
|
+
min_duration_s=1.5, merge_gap_s=0.6, min_two_person_frac=0.3,
|
|
53
|
+
)
|
|
54
|
+
ss[vid] = {
|
|
55
|
+
"video_id": vid,
|
|
56
|
+
"technique": title,
|
|
57
|
+
"source_url": url,
|
|
58
|
+
"fps": seq.fps,
|
|
59
|
+
"n_demos": len(segs),
|
|
60
|
+
"demos": [
|
|
61
|
+
dict(index=s.index, start_s=s.start_s, end_s=s.end_s, duration_s=round(s.duration_s, 2))
|
|
62
|
+
for s in segs
|
|
63
|
+
],
|
|
64
|
+
}
|
|
65
|
+
present = ~np.all(np.isnan(seq.keypoints[..., 0]), axis=2)
|
|
66
|
+
both = f"{(present.sum(1) == 2).mean():.0%}"
|
|
67
|
+
summary.append((vid, title, seq.n_frames, both, len(segs)))
|
|
68
|
+
print(f" stored {seq.keypoints.shape} both-present={both} demos={len(segs)}", flush=True)
|
|
69
|
+
|
|
70
|
+
print("\n=== SUMMARY ===", flush=True)
|
|
71
|
+
print(f"{'video_id':12} {'frames':>6} {'2p%':>4} {'demos':>5} technique", flush=True)
|
|
72
|
+
for vid, title, nf, p2, nd in summary:
|
|
73
|
+
print(f"{vid:12} {nf:>6} {p2:>4} {nd:>5} {title}", flush=True)
|
|
74
|
+
print(f"\npose_store: {len(ps)} clips | segments_store: {len(ss)} clips", flush=True)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
main()
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Stage 1 demo: compare demonstrations of Seoi-nage via joint-angle DTW.
|
|
2
|
+
|
|
3
|
+
Loads the full pose sequence + detected demo segments, then:
|
|
4
|
+
1. proves DTW speed-invariance (a demo vs a 1.5x time-stretched copy of itself),
|
|
5
|
+
2. builds a demo x demo normalized-DTW distance matrix (heatmap PNG),
|
|
6
|
+
3. plots per-angle deviation for a chosen pair (PNG).
|
|
7
|
+
|
|
8
|
+
Usage::
|
|
9
|
+
PYTHONPATH=<repo> python examples/compare_demos.py
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
|
|
14
|
+
import matplotlib
|
|
15
|
+
|
|
16
|
+
matplotlib.use("Agg")
|
|
17
|
+
import matplotlib.pyplot as plt
|
|
18
|
+
import numpy as np
|
|
19
|
+
|
|
20
|
+
from kodokan import config
|
|
21
|
+
from kodokan.compare import (
|
|
22
|
+
ANGLE_NAMES,
|
|
23
|
+
_clean,
|
|
24
|
+
angle_features,
|
|
25
|
+
compare,
|
|
26
|
+
distance_matrix,
|
|
27
|
+
per_angle_deviation,
|
|
28
|
+
primary_person,
|
|
29
|
+
time_stretch,
|
|
30
|
+
)
|
|
31
|
+
from kodokan.pose import PoseSequence
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def main():
|
|
35
|
+
seq = PoseSequence.load_npz(config.pose_dir() / "seoi-nage_ultralytics_full.npz")
|
|
36
|
+
segs = json.loads((config.pose_dir() / "seoi-nage_segments.json").read_text())["demos"]
|
|
37
|
+
|
|
38
|
+
# angle features per demo (primary person within the demo window)
|
|
39
|
+
feats, labels = [], []
|
|
40
|
+
for d in segs:
|
|
41
|
+
fr = (d["start_frame"], d["end_frame"])
|
|
42
|
+
person = primary_person(seq, frame_range=fr)
|
|
43
|
+
f = _clean(angle_features(seq, person=person, frame_range=fr))
|
|
44
|
+
feats.append(f)
|
|
45
|
+
labels.append(f"{d['start_s']:.0f}-{d['end_s']:.0f}s")
|
|
46
|
+
print(f"demo {d['index']:2d} {labels[-1]:>10} person{person} clean_frames={len(f)}")
|
|
47
|
+
|
|
48
|
+
# --- 1) speed-invariance: demo vs 1.5x time-stretched self, vs a different demo ---
|
|
49
|
+
# choose two reasonably long clean demos
|
|
50
|
+
long_idx = sorted(range(len(feats)), key=lambda i: -len(feats[i]))[:2]
|
|
51
|
+
i, j = long_idx[0], long_idx[1]
|
|
52
|
+
self_d = compare(feats[i], feats[i])["normalized"]
|
|
53
|
+
stretch_d = compare(feats[i], time_stretch(feats[i], 1.5))["normalized"]
|
|
54
|
+
cross_d = compare(feats[i], feats[j])["normalized"]
|
|
55
|
+
print("\n--- DTW speed-invariance check (normalized distance) ---")
|
|
56
|
+
print(f" demo {labels[i]} vs itself : {self_d:.4f}")
|
|
57
|
+
print(f" demo {labels[i]} vs 1.5x-stretched : {stretch_d:.4f} (should stay ~as low as self)")
|
|
58
|
+
print(f" demo {labels[i]} vs demo {labels[j]} : {cross_d:.4f} (a genuinely different rep)")
|
|
59
|
+
|
|
60
|
+
# --- 2) distance matrix heatmap ---
|
|
61
|
+
D = distance_matrix(feats)
|
|
62
|
+
fig, ax = plt.subplots(figsize=(7, 6))
|
|
63
|
+
im = ax.imshow(D, cmap="viridis")
|
|
64
|
+
ax.set_xticks(range(len(labels)), labels, rotation=60, ha="right", fontsize=8)
|
|
65
|
+
ax.set_yticks(range(len(labels)), labels, fontsize=8)
|
|
66
|
+
ax.set_title("Seoi-nage demos — pairwise normalized-DTW distance\n(joint-angle features; darker = more similar)")
|
|
67
|
+
fig.colorbar(im, ax=ax, shrink=0.8, label="DTW distance / step (rad)")
|
|
68
|
+
fig.tight_layout()
|
|
69
|
+
p1 = config.viz_dir() / "seoi-nage_demo_distance_matrix.png"
|
|
70
|
+
fig.savefig(p1, dpi=130)
|
|
71
|
+
print("\nsaved", p1.name)
|
|
72
|
+
|
|
73
|
+
# --- 3) per-angle deviation for the (i, j) pair ---
|
|
74
|
+
res = compare(feats[i], feats[j])
|
|
75
|
+
dev = np.degrees(per_angle_deviation(res)) # to degrees for readability
|
|
76
|
+
fig, (axA, axB) = plt.subplots(2, 1, figsize=(8, 7))
|
|
77
|
+
# representative angle (right elbow) along the DTW alignment
|
|
78
|
+
a, b, path = res["a"], res["b"], res["path"]
|
|
79
|
+
re = ANGLE_NAMES.index("r_elbow")
|
|
80
|
+
axA.plot(np.degrees([a[p][re] for p, _ in path]), label=f"demo {labels[i]}")
|
|
81
|
+
axA.plot(np.degrees([b[q][re] for _, q in path]), label=f"demo {labels[j]}")
|
|
82
|
+
axA.set_title("Right-elbow angle along the DTW alignment")
|
|
83
|
+
axA.set_xlabel("aligned step")
|
|
84
|
+
axA.set_ylabel("angle (deg)")
|
|
85
|
+
axA.legend(fontsize=8)
|
|
86
|
+
axB.bar(ANGLE_NAMES, dev, color="#c0392b")
|
|
87
|
+
axB.set_title(f"Mean per-joint-angle deviation: demo {labels[i]} vs {labels[j]}")
|
|
88
|
+
axB.set_ylabel("deg")
|
|
89
|
+
axB.tick_params(axis="x", rotation=45)
|
|
90
|
+
fig.tight_layout()
|
|
91
|
+
p2 = config.viz_dir() / "seoi-nage_demo_pair_deviation.png"
|
|
92
|
+
fig.savefig(p2, dpi=130)
|
|
93
|
+
print("saved", p2.name)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
if __name__ == "__main__":
|
|
97
|
+
main()
|