Spaces:
Running on T4
Running on T4
github-actions[bot] commited on
Commit ·
999db75
1
Parent(s): 3192171
Automated Deploy: 0c9644d4b82d28d1b44a78e1b678fc6b46953d96
Browse files- BUILD_STATUS.md +10 -0
- baseball_batting/batting_measurements.py +8 -4
- baseball_batting/measurement_quality.py +5 -0
- docs/API_FOR_COACH.md +2 -2
- docs/BATTING_2D_MEASUREMENTS.md +5 -5
- docs/NINE_MEASUREMENTS.md +4 -2
- docs/api-result.schema.json +2 -1
- notebooks/batting_2d_test.ipynb +1 -1
- notebooks/batting_measurements_test.ipynb +1 -1
- tests/test_2d_regressions.py +24 -1
- tests/test_batting_measurements.py +11 -1
- tests/test_measurement_backends.py +34 -6
- tools/build_2d_notebook.py +1 -1
BUILD_STATUS.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
| 1 |
# Build status
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
## Nine measurements and optional 3D — 2026-10-11
|
| 4 |
|
| 5 |
The GPU API now accepts `measurement_backend: "2d" | "rtmw3d" | "sam3d"`. [batting_measurements_test.ipynb](notebooks/batting_measurements_test.ipynb) provides the same choice in step 3. The original 2D-only notebook remains separate. [NINE_MEASUREMENTS.md](docs/NINE_MEASUREMENTS.md) specifies calculations, camera assumptions, rejection gates and model comparison.
|
|
|
|
| 1 |
# Build status
|
| 2 |
|
| 3 |
+
## 30 FPS timing support — 2026-10-12
|
| 4 |
+
|
| 5 |
+
Method `batting-2d-v5` supports documented nominal 30 FPS capture, including 29.97 FPS and variable cadence with every interval <= `1.01/30` seconds. This replaces the earlier blanket 60 FPS timing cutoff. The existing per-metric ±1-frame sensitivity checks still withhold poorly resolved durations and ratios; unknown clocks, missing events and larger timestamp gaps remain unsupported. Full-result timing diagnostics now include actual frame intervals and the shifted-event range's unit. The coach schema and estimate labels are unchanged.
|
| 6 |
+
|
| 7 |
+
Executed evidence:
|
| 8 |
+
|
| 9 |
+
- **159 tests passed, 4 skipped**, one existing Starlette/httpx deprecation warning. Added coverage checks 30/29.97 FPS acceptance, documented variable cadence at 30–40 FPS, gap rejection, long versus short timing resolution and a replay of the walkthrough observations. Both notebooks were regenerated and their deterministic generation/schema checks passed.
|
| 10 |
+
- Replaying the archived points from `session-5645e3e671a5-sam3d-results.zip` returns `load_tempo_s: 0.533` with a ±1-frame sensitivity range of approximately 0.467–0.600 seconds. `load_launch_ratio` remains null because its shifted-event range spans approximately 2–6. Plant-to-contact timing remains unavailable without a plant event. Both full-result and coach-payload schemas pass. This replay reused the saved 2D/SAM outputs; it did not rerun GPU inference or independently verify the caller-declared original capture clock.
|
| 11 |
+
- The supplied outdoor and walkthrough SAM archives both show completed five-frame sparse SAM inference, taking 37.842 and 34.783 seconds respectively within total analysis times of 73.65 and 57.81 seconds. These exclude setup/download costs. They provide SAM worker execution evidence for these clips, not accuracy qualification or Docker HTTP deployment validation. Lightweight GPU comparison and real measurement accuracy remain pending.
|
| 12 |
+
|
| 13 |
## Nine measurements and optional 3D — 2026-10-11
|
| 14 |
|
| 15 |
The GPU API now accepts `measurement_backend: "2d" | "rtmw3d" | "sam3d"`. [batting_measurements_test.ipynb](notebooks/batting_measurements_test.ipynb) provides the same choice in step 3. The original 2D-only notebook remains separate. [NINE_MEASUREMENTS.md](docs/NINE_MEASUREMENTS.md) specifies calculations, camera assumptions, rejection gates and model comparison.
|
baseball_batting/batting_measurements.py
CHANGED
|
@@ -9,7 +9,11 @@ import math
|
|
| 9 |
import numpy as np
|
| 10 |
from scipy.ndimage import median_filter
|
| 11 |
|
| 12 |
-
VERSION = "batting-2d-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
EVENT_ORDER = ["stance_set", "load_start", "stride", "foot_contact", "foot_plant",
|
| 14 |
"swing_start", "contact", "finish"]
|
| 15 |
METRICS = {
|
|
@@ -312,7 +316,7 @@ def capture_checks(track, options, height, selected_frames):
|
|
| 312 |
elif blur > .75: reasons.append("a_bit_blurry")
|
| 313 |
fps = track["video"]["capture_fps"]
|
| 314 |
if fps is not None:
|
| 315 |
-
if fps <
|
| 316 |
elif fps < 60-1e-6: reasons.append("low_fps")
|
| 317 |
else:
|
| 318 |
diagnostics.append("Constant capture FPS is unknown or variable; timing requires documented per-frame capture times with adequate local cadence.")
|
|
@@ -559,8 +563,8 @@ def rep_metrics(track, points, options, height, height_method, direction, events
|
|
| 559 |
deltas = np.diff(real_times[start:end+1])
|
| 560 |
known_clock = len(deltas) > 0 and np.isfinite(deltas).all() and (deltas > 0).all()
|
| 561 |
timing_reason = ("Real capture timing is unknown." if not known_clock else
|
| 562 |
-
"Timing requires
|
| 563 |
-
if deltas.max() >
|
| 564 |
if timing_reason is None and reason is None:
|
| 565 |
if plant is not None and contact is not None:
|
| 566 |
values["foot_plant_to_contact_ms"] = (real_times[contact]-real_times[plant])*1000
|
|
|
|
| 9 |
import numpy as np
|
| 10 |
from scipy.ndimage import median_filter
|
| 11 |
|
| 12 |
+
VERSION = "batting-2d-v5"
|
| 13 |
+
# Nominal 30 FPS, including 29.97 and small timestamp jitter. This is an
|
| 14 |
+
# engineering support floor, not an accuracy guarantee. The API quality layer
|
| 15 |
+
# separately rejects each timing metric under ±1-frame event shifts.
|
| 16 |
+
MAX_TIMING_INTERVAL_S = 1.01 / 30
|
| 17 |
EVENT_ORDER = ["stance_set", "load_start", "stride", "foot_contact", "foot_plant",
|
| 18 |
"swing_start", "contact", "finish"]
|
| 19 |
METRICS = {
|
|
|
|
| 316 |
elif blur > .75: reasons.append("a_bit_blurry")
|
| 317 |
fps = track["video"]["capture_fps"]
|
| 318 |
if fps is not None:
|
| 319 |
+
if fps < 1/MAX_TIMING_INTERVAL_S-1e-6: reasons.append("very_low_fps")
|
| 320 |
elif fps < 60-1e-6: reasons.append("low_fps")
|
| 321 |
else:
|
| 322 |
diagnostics.append("Constant capture FPS is unknown or variable; timing requires documented per-frame capture times with adequate local cadence.")
|
|
|
|
| 563 |
deltas = np.diff(real_times[start:end+1])
|
| 564 |
known_clock = len(deltas) > 0 and np.isfinite(deltas).all() and (deltas > 0).all()
|
| 565 |
timing_reason = ("Real capture timing is unknown." if not known_clock else
|
| 566 |
+
"Timing requires nominal 30 FPS or higher capture cadence; missing frames or lower capture rate limit resolution."
|
| 567 |
+
if deltas.max() > MAX_TIMING_INTERVAL_S+1e-6 else None)
|
| 568 |
if timing_reason is None and reason is None:
|
| 569 |
if plant is not None and contact is not None:
|
| 570 |
values["foot_plant_to_contact_ms"] = (real_times[contact]-real_times[plant])*1000
|
baseball_batting/measurement_quality.py
CHANGED
|
@@ -217,6 +217,10 @@ def apply_measurement_quality(result, options, report):
|
|
| 217 |
"load_launch_ratio": ("load_start", "swing_start", "contact")}[key]
|
| 218 |
if all(name in pose_rep["events"] for name in names):
|
| 219 |
t = track["frames"]["t_s"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
intervals = []
|
| 221 |
for name in names:
|
| 222 |
i = pose_rep["events"][name]["frame"]
|
|
@@ -232,6 +236,7 @@ def apply_measurement_quality(result, options, report):
|
|
| 232 |
interval = ([(intervals[1][0]-intervals[0][1])/denominator[1],
|
| 233 |
(intervals[1][1]-intervals[0][0])/denominator[0]] if denominator[0] > 0 else None)
|
| 234 |
item.update(event_frame_sensitivity_range=interval,
|
|
|
|
| 235 |
sensitivity_scope="each event shifted ±1 frame; detection error may be larger")
|
| 236 |
if interval is None and metric["value"] is not None:
|
| 237 |
metric.update(value=None, note="Launch duration is too short to resolve under ±1-frame event shifts.")
|
|
|
|
| 217 |
"load_launch_ratio": ("load_start", "swing_start", "contact")}[key]
|
| 218 |
if all(name in pose_rep["events"] for name in names):
|
| 219 |
t = track["frames"]["t_s"]
|
| 220 |
+
steps = np.diff(np.asarray(t[pose_rep["start_frame"]:pose_rep["end_frame"]+1], float))
|
| 221 |
+
if len(steps) and np.isfinite(steps).all() and (steps > 0).all():
|
| 222 |
+
item["capture_interval_ms"] = [round(float(steps.min()*1000), 3),
|
| 223 |
+
round(float(steps.max()*1000), 3)]
|
| 224 |
intervals = []
|
| 225 |
for name in names:
|
| 226 |
i = pose_rep["events"][name]["frame"]
|
|
|
|
| 236 |
interval = ([(intervals[1][0]-intervals[0][1])/denominator[1],
|
| 237 |
(intervals[1][1]-intervals[0][0])/denominator[0]] if denominator[0] > 0 else None)
|
| 238 |
item.update(event_frame_sensitivity_range=interval,
|
| 239 |
+
event_frame_sensitivity_unit=METRICS[key][0],
|
| 240 |
sensitivity_scope="each event shifted ±1 frame; detection error may be larger")
|
| 241 |
if interval is None and metric["value"] is not None:
|
| 242 |
metric.update(value=None, note="Launch duration is too short to resolve under ±1-frame event shifts.")
|
docs/API_FOR_COACH.md
CHANGED
|
@@ -51,7 +51,7 @@ Supported values, subject to event/view/quality evidence:
|
|
| 51 |
|
| 52 |
- `stride_pct_height`: horizontal ankle-to-ankle span at estimated foot plant.
|
| 53 |
- `com_drift_pct_height`: hip midpoint relative to the front ankle at estimated contact; negative is behind.
|
| 54 |
-
- `foot_plant_to_contact_ms`, `load_tempo_s`, `load_launch_ratio`: timing
|
| 55 |
- `head_movement_pct_height`: reference-only nose path from stance to estimated contact.
|
| 56 |
- `lead_knee_angle_contact_deg`: reference-only projected interior knee angle.
|
| 57 |
|
|
@@ -97,7 +97,7 @@ Capture-clock declarations:
|
|
| 97 |
{"kind":"explicit","source":"camera timestamp file","physical_times_s":[0.0,0.00417,0.00833]}
|
| 98 |
```
|
| 99 |
|
| 100 |
-
Explicit times must match the decoded frame count and increase strictly. Unknown timing produces null capture timestamps in the pose track, no `events_ms`, and null timing metrics. Variable cadence is retained per frame without asserting constant FPS. Version
|
| 101 |
|
| 102 |
## Full result and Python client
|
| 103 |
|
|
|
|
| 51 |
|
| 52 |
- `stride_pct_height`: horizontal ankle-to-ankle span at estimated foot plant.
|
| 53 |
- `com_drift_pct_height`: hip midpoint relative to the front ankle at estimated contact; negative is behind.
|
| 54 |
+
- `foot_plant_to_contact_ms`, `load_tempo_s`, `load_launch_ratio`: timing estimates with documented nominal 30 FPS or higher capture timestamps, including 29.97 FPS. Each quantity must also pass its ±1-frame sensitivity check; shorter durations/ratios may be withheld even at higher FPS.
|
| 55 |
- `head_movement_pct_height`: reference-only nose path from stance to estimated contact.
|
| 56 |
- `lead_knee_angle_contact_deg`: reference-only projected interior knee angle.
|
| 57 |
|
|
|
|
| 97 |
{"kind":"explicit","source":"camera timestamp file","physical_times_s":[0.0,0.00417,0.00833]}
|
| 98 |
```
|
| 99 |
|
| 100 |
+
Explicit times must match the decoded frame count and increase strictly. Unknown timing produces null capture timestamps in the pose track, no `events_ms`, and null timing metrics. Variable cadence is retained per frame without asserting constant FPS. Version 5 supports nominal 30 FPS or higher timing when every capture interval in the rep is <= `1.01/30` seconds (1% tolerance for fractional frame rates/jitter). Missing frames, poor resolution and large ±1-frame sensitivity still withhold a metric. Full-result diagnostics expose actual frame intervals and shifted-event ranges; those ranges are not accuracy confidence intervals. An advisory `low_fps` reason at 30 FPS does not mean capture failed. Capture-quality, event and boundary checks are heuristics, not validated classifiers.
|
| 101 |
|
| 102 |
## Full result and Python client
|
| 103 |
|
docs/BATTING_2D_MEASUREMENTS.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# 2D batting measurement definitions
|
| 2 |
|
| 3 |
-
Version: `batting-2d-
|
| 4 |
|
| 5 |
## Pose checkpoint and foot points
|
| 6 |
|
|
@@ -53,9 +53,9 @@ Events must be inside their rep and follow the requested order. Conflicting cand
|
|
| 53 |
|---|---|---|
|
| 54 |
| `stride_pct_height` | `100 × abs(lead_ankle_x - back_ankle_x) / image_height_scale` at estimated foot plant | Lead side, plant and scale |
|
| 55 |
| `com_drift_pct_height` | `100 × pitcher_direction × (hip_midpoint_x - lead_ankle_x) / scale` at estimated contact | Negative is behind; hip proxy, not whole-body center of mass; same-frame estimate eligible with a moving camera |
|
| 56 |
-
| `foot_plant_to_contact_ms` | Physical contact time minus physical plant time, ×1000 | Both events; documented
|
| 57 |
-
| `load_tempo_s` | Physical forward-onset time minus physical hand-load-start time | Both events; documented
|
| 58 |
-
| `load_launch_ratio` | Load duration / physical onset-to-contact duration | All events; positive denominator; documented
|
| 59 |
| `head_movement_pct_height` | Sum of consecutive analytical nose displacements from stance to estimated contact, /scale ×100 | Fixed camera, complete analytical path; reference-only |
|
| 60 |
| `lead_knee_angle_contact_deg` | Interior projected hip-knee-ankle angle at estimated contact | Reference-only; not anatomical 3D flexion; eligible with a moving camera |
|
| 61 |
| `lateral_trunk_tilt_contact_deg` | Null | Requested anatomical tilt not established by face-on 2D |
|
|
@@ -79,7 +79,7 @@ Blur is the existing uncalibrated `1/(1+Laplacian variance/100)` heuristic. Pose
|
|
| 79 |
|
| 80 |
## Optional 3D and quality layer
|
| 81 |
|
| 82 |
-
The API
|
| 83 |
|
| 84 |
## Validation remaining
|
| 85 |
|
|
|
|
| 1 |
# 2D batting measurement definitions
|
| 2 |
|
| 3 |
+
Version: `batting-2d-v5`. Scope: face-on batting, with fixed-camera requirements only for ground-foot events and head movement. This module uses GPU pose/person outputs and CPU arithmetic, with no SAM, temporal 3D fitting, OpenSim or coaching decisions.
|
| 4 |
|
| 5 |
## Pose checkpoint and foot points
|
| 6 |
|
|
|
|
| 53 |
|---|---|---|
|
| 54 |
| `stride_pct_height` | `100 × abs(lead_ankle_x - back_ankle_x) / image_height_scale` at estimated foot plant | Lead side, plant and scale |
|
| 55 |
| `com_drift_pct_height` | `100 × pitcher_direction × (hip_midpoint_x - lead_ankle_x) / scale` at estimated contact | Negative is behind; hip proxy, not whole-body center of mass; same-frame estimate eligible with a moving camera |
|
| 56 |
+
| `foot_plant_to_contact_ms` | Physical contact time minus physical plant time, ×1000 | Both events; documented nominal 30 FPS or higher capture cadence |
|
| 57 |
+
| `load_tempo_s` | Physical forward-onset time minus physical hand-load-start time | Both events; documented nominal 30 FPS or higher capture cadence |
|
| 58 |
+
| `load_launch_ratio` | Load duration / physical onset-to-contact duration | All events; positive denominator; documented nominal 30 FPS or higher capture cadence |
|
| 59 |
| `head_movement_pct_height` | Sum of consecutive analytical nose displacements from stance to estimated contact, /scale ×100 | Fixed camera, complete analytical path; reference-only |
|
| 60 |
| `lead_knee_angle_contact_deg` | Interior projected hip-knee-ankle angle at estimated contact | Reference-only; not anatomical 3D flexion; eligible with a moving camera |
|
| 61 |
| `lateral_trunk_tilt_contact_deg` | Null | Requested anatomical tilt not established by face-on 2D |
|
|
|
|
| 79 |
|
| 80 |
## Optional 3D and quality layer
|
| 81 |
|
| 82 |
+
The API applies `measurement-quality-v1` and optional RTMW3D/SAM event-window estimates after this 2D stage. See [NINE_MEASUREMENTS.md](NINE_MEASUREMENTS.md) for all nine definitions, camera assumptions, rejection gates and Colab/model choices. Version 5 supports documented nominal 30 FPS or higher physical timestamps, including variable cadence and 29.97 FPS. Every interval must be <= `1.01/30` seconds. The quality layer separately rejects poorly resolved durations/ratios under ±1-frame event shifts. Unknown clocks still withhold timing. This module itself does not infer 3D.
|
| 83 |
|
| 84 |
## Validation remaining
|
| 85 |
|
docs/NINE_MEASUREMENTS.md
CHANGED
|
@@ -34,7 +34,7 @@ Use those recording declarations only when they describe the video. Changing `me
|
|
| 34 |
| Field | Calculation | Main requirements |
|
| 35 |
|---|---|---|
|
| 36 |
| `stride_pct_height` | Horizontal ankle-to-ankle span at estimated settled foot plant, divided by image stature | Fixed camera, identified lead leg, observed plant, valid scale |
|
| 37 |
-
| `foot_plant_to_contact_ms` | Actual capture-time difference between estimated plant and contact | Both events, documented
|
| 38 |
| `com_drift_pct_height` | Hip midpoint horizontal position relative to lead ankle at estimated contact | Identified lead leg, pitcher direction, scale; this follows the coach contract and is not whole-body centre of mass |
|
| 39 |
| `load_tempo_s` | Hand-load start to swing onset in capture seconds | Both events, documented timestamps and adequate resolution |
|
| 40 |
| `load_launch_ratio` | Load duration / onset-to-contact duration | Three events, documented timestamps, denominator resolved under frame shifts |
|
|
@@ -49,7 +49,9 @@ Contact still means estimated lead-arm extension during the primary swing, not c
|
|
| 49 |
|
| 50 |
## Stability checks and evidence
|
| 51 |
|
| 52 |
-
The raw exported 2D track stays unchanged. The analytical track retains bounded three-frame interpolation/median filtering and the v3 event repair. Version `batting-2d-
|
|
|
|
|
|
|
| 53 |
|
| 54 |
`measurement-quality-v1` adds:
|
| 55 |
|
|
|
|
| 34 |
| Field | Calculation | Main requirements |
|
| 35 |
|---|---|---|
|
| 36 |
| `stride_pct_height` | Horizontal ankle-to-ankle span at estimated settled foot plant, divided by image stature | Fixed camera, identified lead leg, observed plant, valid scale |
|
| 37 |
+
| `foot_plant_to_contact_ms` | Actual capture-time difference between estimated plant and contact | Both events, documented nominal 30 FPS or higher timestamps, adequate event resolution |
|
| 38 |
| `com_drift_pct_height` | Hip midpoint horizontal position relative to lead ankle at estimated contact | Identified lead leg, pitcher direction, scale; this follows the coach contract and is not whole-body centre of mass |
|
| 39 |
| `load_tempo_s` | Hand-load start to swing onset in capture seconds | Both events, documented timestamps and adequate resolution |
|
| 40 |
| `load_launch_ratio` | Load duration / onset-to-contact duration | Three events, documented timestamps, denominator resolved under frame shifts |
|
|
|
|
| 49 |
|
| 50 |
## Stability checks and evidence
|
| 51 |
|
| 52 |
+
The raw exported 2D track stays unchanged. The analytical track retains bounded three-frame interpolation/median filtering and the v3 event repair. Version `batting-2d-v5` permits documented nominal 30 FPS or higher timestamps, including variable cadence and 29.97 FPS. Every capture interval in the rep must be <= `1.01/30` seconds; the 1% tolerance accommodates fractional frame rates and small timestamp jitter. Larger gaps withhold timing. Playback time still never supplies physical swing time.
|
| 53 |
+
|
| 54 |
+
30 FPS has about 33.3 ms between frames; 60 FPS has about 16.7 ms. The previous 60 FPS cutoff was an engineering choice, not a model requirement. A longer load can be estimated at 30 FPS, while a short launch or plant-to-contact interval may remain too poorly resolved. The API quality layer rejects each duration/ratio if its ±1-frame sensitivity range is nonpositive/undefined or wider than half its value. This is a resolution stress test, not a measured error limit. The full result records `capture_interval_ms`, `event_frame_sensitivity_range` and its unit. An advisory `low_fps` capture reason can remain at 30 FPS without making capture fail.
|
| 55 |
|
| 56 |
`measurement-quality-v1` adds:
|
| 57 |
|
docs/api-result.schema.json
CHANGED
|
@@ -633,7 +633,8 @@
|
|
| 633 |
"batting-2d-v1",
|
| 634 |
"batting-2d-v2",
|
| 635 |
"batting-2d-v3",
|
| 636 |
-
|
|
|
|
| 637 |
]
|
| 638 |
},
|
| 639 |
"body_height_px": {
|
|
|
|
| 633 |
"batting-2d-v1",
|
| 634 |
"batting-2d-v2",
|
| 635 |
"batting-2d-v3",
|
| 636 |
+
"batting-2d-v4",
|
| 637 |
+
"batting-2d-v5"
|
| 638 |
]
|
| 639 |
},
|
| 640 |
"body_height_px": {
|
notebooks/batting_2d_test.ipynb
CHANGED
|
@@ -240,7 +240,7 @@
|
|
| 240 |
"\n",
|
| 241 |
"Set `VIEW=\"face_on\"` only for a known face-on recording. Unknown view keeps measurements empty, while ranges and generic motion events can still be inspected. Set `CAMERA_STABILITY=\"moving\"` for a moving camera and `\"fixed_verified\"` only when the camera stays still. Moving/unknown cameras can still return within-frame body positions and projected knee angles when the required events are found. Ground-foot events and head movement require a fixed camera.\n",
|
| 242 |
"\n",
|
| 243 |
-
"Keep `TIMING={\"kind\":\"unknown\"}` unless capture timing is known. For an original unretimed recording use `{\"kind\":\"unretimed\",\"source\":\"original camera file; no retiming\"}`. For documented constant slow motion use `{\"kind\":\"constant_slowdown\",\"source\":\"documented camera/export settings\",\"factor\":8,\"all_captured_frames_retained\":True}` with the real factor. Playback FPS is not capture FPS. Timing
|
| 244 |
"\n",
|
| 245 |
"Leave `SINGLE_SWING=False` for this multi-swing test. A new upload cell run creates a new job; rerunning only the analysis cell resumes the same job and verified observation cache. The current worker limits are 7,200 frames, 120 playback seconds and 8.3 megapixels per frame.\n"
|
| 246 |
],
|
|
|
|
| 240 |
"\n",
|
| 241 |
"Set `VIEW=\"face_on\"` only for a known face-on recording. Unknown view keeps measurements empty, while ranges and generic motion events can still be inspected. Set `CAMERA_STABILITY=\"moving\"` for a moving camera and `\"fixed_verified\"` only when the camera stays still. Moving/unknown cameras can still return within-frame body positions and projected knee angles when the required events are found. Ground-foot events and head movement require a fixed camera.\n",
|
| 242 |
"\n",
|
| 243 |
+
"Keep `TIMING={\"kind\":\"unknown\"}` unless capture timing is known. For an original unretimed recording use `{\"kind\":\"unretimed\",\"source\":\"original camera file; no retiming\"}`. For documented constant slow motion use `{\"kind\":\"constant_slowdown\",\"source\":\"documented camera/export settings\",\"factor\":8,\"all_captured_frames_retained\":True}` with the real factor. Playback FPS is not capture FPS. Timing estimates support documented nominal 30 FPS or higher cadence, including 29.97 FPS and variable cadence with no larger gaps. Each timing measurement is separately withheld if moving its events by one frame changes it too much. 60 FPS gives finer time resolution; it is no longer required.\n",
|
| 244 |
"\n",
|
| 245 |
"Leave `SINGLE_SWING=False` for this multi-swing test. A new upload cell run creates a new job; rerunning only the analysis cell resumes the same job and verified observation cache. The current worker limits are 7,200 frames, 120 playback seconds and 8.3 megapixels per frame.\n"
|
| 246 |
],
|
notebooks/batting_measurements_test.ipynb
CHANGED
|
@@ -261,7 +261,7 @@
|
|
| 261 |
"\n",
|
| 262 |
"Set `VIEW=\"face_on\"` only for a known face-on recording. Unknown view keeps measurements empty, while ranges and generic motion events can still be inspected. Set `CAMERA_STABILITY=\"moving\"` for a moving camera and `\"fixed_verified\"` only when the camera stays still. Moving/unknown cameras can still return within-frame body positions and projected knee angles when the required events are found. Ground-foot events and head movement require a fixed camera.\n",
|
| 263 |
"\n",
|
| 264 |
-
"Keep `TIMING={\"kind\":\"unknown\"}` unless capture timing is known. For an original unretimed recording use `{\"kind\":\"unretimed\",\"source\":\"original camera file; no retiming\"}`. For documented constant slow motion use `{\"kind\":\"constant_slowdown\",\"source\":\"documented camera/export settings\",\"factor\":8,\"all_captured_frames_retained\":True}` with the real factor. Playback FPS is not capture FPS. Timing
|
| 265 |
"\n",
|
| 266 |
"Leave `SINGLE_SWING=False` for this multi-swing test. A new upload cell run creates a new job; rerunning only the analysis cell resumes the same job and verified observation cache. The current worker limits are 7,200 frames, 120 playback seconds and 8.3 megapixels per frame.\n",
|
| 267 |
"\n",
|
|
|
|
| 261 |
"\n",
|
| 262 |
"Set `VIEW=\"face_on\"` only for a known face-on recording. Unknown view keeps measurements empty, while ranges and generic motion events can still be inspected. Set `CAMERA_STABILITY=\"moving\"` for a moving camera and `\"fixed_verified\"` only when the camera stays still. Moving/unknown cameras can still return within-frame body positions and projected knee angles when the required events are found. Ground-foot events and head movement require a fixed camera.\n",
|
| 263 |
"\n",
|
| 264 |
+
"Keep `TIMING={\"kind\":\"unknown\"}` unless capture timing is known. For an original unretimed recording use `{\"kind\":\"unretimed\",\"source\":\"original camera file; no retiming\"}`. For documented constant slow motion use `{\"kind\":\"constant_slowdown\",\"source\":\"documented camera/export settings\",\"factor\":8,\"all_captured_frames_retained\":True}` with the real factor. Playback FPS is not capture FPS. Timing estimates support documented nominal 30 FPS or higher cadence, including 29.97 FPS and variable cadence with no larger gaps. Each timing measurement is separately withheld if moving its events by one frame changes it too much. 60 FPS gives finer time resolution; it is no longer required.\n",
|
| 265 |
"\n",
|
| 266 |
"Leave `SINGLE_SWING=False` for this multi-swing test. A new upload cell run creates a new job; rerunning only the analysis cell resumes the same job and verified observation cache. The current worker limits are 7,200 frames, 120 playback seconds and 8.3 megapixels per frame.\n",
|
| 267 |
"\n",
|
tests/test_2d_regressions.py
CHANGED
|
@@ -81,6 +81,29 @@ def test_walkthrough_keeps_preparation_and_follow_through(walkthrough):
|
|
| 81 |
assert np.nanmax(distance) < 160 # old toes were roughly 780 px from ankles
|
| 82 |
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
def test_known_view_on_moving_camera_keeps_only_supported_numbers(walkthrough):
|
| 85 |
opt = AnalysisInput(view="face_on", handedness="left", pitcher_direction="image_left",
|
| 86 |
camera_stability="moving")
|
|
@@ -151,7 +174,7 @@ def test_outdoor_reset_never_replaces_the_actual_swing(outdoor, declared):
|
|
| 151 |
assert events["contact"]["estimated"] is True
|
| 152 |
assert "primary" in events["contact"]["method"]
|
| 153 |
assert "finish" not in events # no finish fabricated from the end of the clip
|
| 154 |
-
assert method["version"] == "batting-2d-
|
| 155 |
assert reps[0]["events_ms"] == {}
|
| 156 |
assert all("t_s" not in event for event in events.values())
|
| 157 |
# The feet overlap in projection at the real swing, unlike the later reset.
|
|
|
|
| 81 |
assert np.nanmax(distance) < 160 # old toes were roughly 780 px from ankles
|
| 82 |
|
| 83 |
|
| 84 |
+
def test_walkthrough_30fps_keeps_resolved_load_but_withholds_launch_ratio(walkthrough):
|
| 85 |
+
from baseball_batting.measurement_quality import apply_measurement_quality
|
| 86 |
+
from baseball_batting.event_body3d import reconstruct_events
|
| 87 |
+
# A declared test clock, not independent evidence about the source camera.
|
| 88 |
+
walkthrough["video"]["capture_fps"] = 30
|
| 89 |
+
walkthrough["frames"]["t_s"] = [i/30 for i in range(walkthrough["video"]["frame_count"])]
|
| 90 |
+
opt = AnalysisInput(view="face_on", handedness="left", pitcher_direction="image_left",
|
| 91 |
+
camera_stability="fixed_verified", single_swing=True)
|
| 92 |
+
pose, reps, capture, warnings, method = analyze_batting(walkthrough, opt)
|
| 93 |
+
result = {"pose_track": deepcopy(walkthrough), "measurement_method": method,
|
| 94 |
+
"capabilities": {"body_3d": False}, "warnings": warnings,
|
| 95 |
+
"measurements": {"schema_version": "2.0", "discipline": "hitting", "view": "face_on",
|
| 96 |
+
"fps": 30, "reps": reps, "capture": capture}}
|
| 97 |
+
result["pose_track"]["reps"] = pose
|
| 98 |
+
report = reconstruct_events(Path("unused.mp4"), result, opt, Path("."), Path("."))
|
| 99 |
+
full = apply_measurement_quality(result, opt, report)
|
| 100 |
+
metrics = metric_map(full["coach_payload"]["reps"][0])
|
| 101 |
+
assert metrics["load_tempo_s"]["value"] == pytest.approx(16/30, abs=.001)
|
| 102 |
+
assert metrics["load_launch_ratio"]["value"] is None
|
| 103 |
+
assert "±1-frame" in metrics["load_launch_ratio"]["note"]
|
| 104 |
+
assert metrics["foot_plant_to_contact_ms"]["value"] is None
|
| 105 |
+
|
| 106 |
+
|
| 107 |
def test_known_view_on_moving_camera_keeps_only_supported_numbers(walkthrough):
|
| 108 |
opt = AnalysisInput(view="face_on", handedness="left", pitcher_direction="image_left",
|
| 109 |
camera_stability="moving")
|
|
|
|
| 174 |
assert events["contact"]["estimated"] is True
|
| 175 |
assert "primary" in events["contact"]["method"]
|
| 176 |
assert "finish" not in events # no finish fabricated from the end of the clip
|
| 177 |
+
assert method["version"] == "batting-2d-v5"
|
| 178 |
assert reps[0]["events_ms"] == {}
|
| 179 |
assert all("t_s" not in event for event in events.values())
|
| 180 |
# The feet overlap in projection at the real swing, unlike the later reset.
|
tests/test_batting_measurements.py
CHANGED
|
@@ -84,7 +84,7 @@ def test_automatic_two_swings_and_rep_relative_times():
|
|
| 84 |
|
| 85 |
|
| 86 |
def test_unknown_or_low_capture_clock_never_uses_playback_time():
|
| 87 |
-
for fps in (None,
|
| 88 |
track = swing_track()
|
| 89 |
track["video"]["capture_fps"] = fps
|
| 90 |
if fps is None: track["frames"]["t_s"] = [None]*180
|
|
@@ -97,6 +97,16 @@ def test_unknown_or_low_capture_clock_never_uses_playback_time():
|
|
| 97 |
assert all("t_s" not in e for e in pose[0]["events"].values())
|
| 98 |
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
def test_mirrored_image_keeps_stride_and_signed_body_position():
|
| 101 |
original = analyze_batting(swing_track(), options(single_swing=True))[1][0]
|
| 102 |
mirrored = analyze_batting(swing_track(mirror=True), options(single_swing=True))[1][0]
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
def test_unknown_or_low_capture_clock_never_uses_playback_time():
|
| 87 |
+
for fps in (None, 25):
|
| 88 |
track = swing_track()
|
| 89 |
track["video"]["capture_fps"] = fps
|
| 90 |
if fps is None: track["frames"]["t_s"] = [None]*180
|
|
|
|
| 97 |
assert all("t_s" not in e for e in pose[0]["events"].values())
|
| 98 |
|
| 99 |
|
| 100 |
+
@pytest.mark.parametrize("fps", [30, 29.97])
|
| 101 |
+
def test_nominal_30fps_known_clock_allows_resolved_load_duration(fps):
|
| 102 |
+
track = swing_track(fps=fps)
|
| 103 |
+
pose, reps, capture, _, _ = analyze_batting(track, options(single_swing=True))
|
| 104 |
+
assert capture["ok"] is True and "low_fps" in capture["reasons"]
|
| 105 |
+
events = pose[0]["events"]
|
| 106 |
+
expected = (events["swing_start"]["frame"]-events["load_start"]["frame"])/fps
|
| 107 |
+
assert metric_map(reps[0])["load_tempo_s"]["value"] == pytest.approx(expected, abs=.001)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
def test_mirrored_image_keeps_stride_and_signed_body_position():
|
| 111 |
original = analyze_batting(swing_track(), options(single_swing=True))[1][0]
|
| 112 |
mirrored = analyze_batting(swing_track(mirror=True), options(single_swing=True))[1][0]
|
tests/test_measurement_backends.py
CHANGED
|
@@ -168,17 +168,45 @@ def test_unknown_timing_and_moving_camera_remain_withheld_with_3d():
|
|
| 168 |
assert metrics["lead_knee_angle_contact_deg"]["value"] is not None
|
| 169 |
|
| 170 |
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
track = swing_track(); track["video"]["capture_fps"] = None
|
| 173 |
-
intervals = np.resize([1/
|
| 174 |
track["frames"]["t_s"] = np.r_[0, np.cumsum(intervals)].tolist()
|
| 175 |
pose, reps, _, _, _ = analyze_batting(track, options(single_swing=True))
|
| 176 |
-
a, b = (pose[0]["events"][
|
| 177 |
-
expected = (track["frames"]["t_s"][b]-track["frames"]["t_s"][a])*
|
| 178 |
-
assert metric_map(reps[0])[
|
| 179 |
track["frames"]["t_s"][90:] = [t+.1 for t in track["frames"]["t_s"][90:]]
|
| 180 |
metrics = metric_map(analyze_batting(track, options(single_swing=True))[1][0])
|
| 181 |
-
assert metrics[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
|
| 184 |
def test_frame_budget_keeps_complete_event_windows():
|
|
|
|
| 168 |
assert metrics["lead_knee_angle_contact_deg"]["value"] is not None
|
| 169 |
|
| 170 |
|
| 171 |
+
@pytest.mark.parametrize("cadence,key,event_names,scale", [
|
| 172 |
+
((100, 120), "foot_plant_to_contact_ms", ("foot_plant", "contact"), 1000),
|
| 173 |
+
((30, 40), "load_tempo_s", ("load_start", "swing_start"), 1),
|
| 174 |
+
])
|
| 175 |
+
def test_known_variable_capture_clock_uses_original_timestamps(cadence, key, event_names, scale):
|
| 176 |
track = swing_track(); track["video"]["capture_fps"] = None
|
| 177 |
+
intervals = np.resize([1/cadence[0], 1/cadence[1]], 179)
|
| 178 |
track["frames"]["t_s"] = np.r_[0, np.cumsum(intervals)].tolist()
|
| 179 |
pose, reps, _, _, _ = analyze_batting(track, options(single_swing=True))
|
| 180 |
+
a, b = (pose[0]["events"][name]["frame"] for name in event_names)
|
| 181 |
+
expected = (track["frames"]["t_s"][b]-track["frames"]["t_s"][a])*scale
|
| 182 |
+
assert metric_map(reps[0])[key]["value"] == pytest.approx(expected, abs=.001)
|
| 183 |
track["frames"]["t_s"][90:] = [t+.1 for t in track["frames"]["t_s"][90:]]
|
| 184 |
metrics = metric_map(analyze_batting(track, options(single_swing=True))[1][0])
|
| 185 |
+
assert metrics[key]["value"] is None
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def test_30fps_frame_sensitivity_keeps_long_load_and_withholds_short_timings():
|
| 189 |
+
result, opt, _ = measurement_result(swing_track(fps=30),
|
| 190 |
+
options(single_swing=True, measurement_backend="2d"))
|
| 191 |
+
# Independently supplied event frames: a 16-frame load and a 5-frame launch.
|
| 192 |
+
result["pose_track"]["reps"][0]["events"] = {
|
| 193 |
+
name: {"frame": frame, "t_s": frame/30} for name, frame in
|
| 194 |
+
(("stance_set", 5), ("load_start", 54), ("foot_plant", 70),
|
| 195 |
+
("swing_start", 70), ("contact", 75))}
|
| 196 |
+
metrics = metric_map(result["measurements"]["reps"][0])
|
| 197 |
+
for key, value in (("load_tempo_s", .533), ("foot_plant_to_contact_ms", 166.667),
|
| 198 |
+
("load_launch_ratio", 3.2)):
|
| 199 |
+
metrics[key]["value"] = value
|
| 200 |
+
report = reconstruct_events(Path("unused.mp4"), result, opt, Path("."), Path("."))
|
| 201 |
+
full = apply_measurement_quality(result, opt, report)
|
| 202 |
+
metrics = metric_map(full["coach_payload"]["reps"][0])
|
| 203 |
+
assert metrics["load_tempo_s"]["value"] == .533
|
| 204 |
+
for key in ("foot_plant_to_contact_ms", "load_launch_ratio"):
|
| 205 |
+
assert metrics[key]["value"] is None and "±1-frame" in metrics[key]["note"]
|
| 206 |
+
diagnostic = {m["key"]: m for m in full["measurement_diagnostics"][0]["metrics"]}
|
| 207 |
+
assert diagnostic["load_tempo_s"]["capture_interval_ms"] == [33.333, 33.333]
|
| 208 |
+
assert diagnostic["load_tempo_s"]["event_frame_sensitivity_range"] == pytest.approx([14/30, 18/30])
|
| 209 |
+
assert diagnostic["load_tempo_s"]["event_frame_sensitivity_unit"] == "s"
|
| 210 |
|
| 211 |
|
| 212 |
def test_frame_budget_keeps_complete_event_windows():
|
tools/build_2d_notebook.py
CHANGED
|
@@ -90,7 +90,7 @@ You can enter an existing `VIDEO_PATH` or leave it empty to upload. Set `HANDEDN
|
|
| 90 |
|
| 91 |
Set `VIEW="face_on"` only for a known face-on recording. Unknown view keeps measurements empty, while ranges and generic motion events can still be inspected. Set `CAMERA_STABILITY="moving"` for a moving camera and `"fixed_verified"` only when the camera stays still. Moving/unknown cameras can still return within-frame body positions and projected knee angles when the required events are found. Ground-foot events and head movement require a fixed camera.
|
| 92 |
|
| 93 |
-
Keep `TIMING={"kind":"unknown"}` unless capture timing is known. For an original unretimed recording use `{"kind":"unretimed","source":"original camera file; no retiming"}`. For documented constant slow motion use `{"kind":"constant_slowdown","source":"documented camera/export settings","factor":8,"all_captured_frames_retained":True}` with the real factor. Playback FPS is not capture FPS. Timing
|
| 94 |
|
| 95 |
Leave `SINGLE_SWING=False` for this multi-swing test. A new upload cell run creates a new job; rerunning only the analysis cell resumes the same job and verified observation cache. The current worker limits are 7,200 frames, 120 playback seconds and 8.3 megapixels per frame.
|
| 96 |
'''), code('''from google.colab import files
|
|
|
|
| 90 |
|
| 91 |
Set `VIEW="face_on"` only for a known face-on recording. Unknown view keeps measurements empty, while ranges and generic motion events can still be inspected. Set `CAMERA_STABILITY="moving"` for a moving camera and `"fixed_verified"` only when the camera stays still. Moving/unknown cameras can still return within-frame body positions and projected knee angles when the required events are found. Ground-foot events and head movement require a fixed camera.
|
| 92 |
|
| 93 |
+
Keep `TIMING={"kind":"unknown"}` unless capture timing is known. For an original unretimed recording use `{"kind":"unretimed","source":"original camera file; no retiming"}`. For documented constant slow motion use `{"kind":"constant_slowdown","source":"documented camera/export settings","factor":8,"all_captured_frames_retained":True}` with the real factor. Playback FPS is not capture FPS. Timing estimates support documented nominal 30 FPS or higher cadence, including 29.97 FPS and variable cadence with no larger gaps. Each timing measurement is separately withheld if moving its events by one frame changes it too much. 60 FPS gives finer time resolution; it is no longer required.
|
| 94 |
|
| 95 |
Leave `SINGLE_SWING=False` for this multi-swing test. A new upload cell run creates a new job; rerunning only the analysis cell resumes the same job and verified observation cache. The current worker limits are 7,200 frames, 120 playback seconds and 8.3 megapixels per frame.
|
| 96 |
'''), code('''from google.colab import files
|