Spaces:
Running on T4
Running on T4
github-actions[bot] commited on
Commit ·
445f7bc
1
Parent(s): de94a96
Automated Deploy: 165eafddb1734d1eaca9309b00c6a08d7a7b334c
Browse files
baseball_batting/motion_api.py
CHANGED
|
@@ -8,6 +8,7 @@ from fastapi import Depends, File, Form, HTTPException, Request, UploadFile
|
|
| 8 |
from fastapi.responses import JSONResponse
|
| 9 |
from pydantic import ValidationError
|
| 10 |
from .motion_contract import MotionInput, MotionManifest, MotionFrame, ProjectionFrame, RevisionRequest, ADAPTER_VERSION
|
|
|
|
| 11 |
from .api_jobs import QueueFull
|
| 12 |
from .sam_runtime import configured_record, public_status
|
| 13 |
from .storage import atomic_json, read_json, sha256_file
|
|
@@ -76,7 +77,7 @@ def register(app,service,authenticated):
|
|
| 76 |
return {'schema_version':'1.0','adapter':ADAPTER_VERSION,'model':'SAM 3D Body MHR70',
|
| 77 |
'tracking_implementation_sha256':sha256_file(Path(__file__).with_name('sam_measurement_worker.py')),
|
| 78 |
'sam':public_status(),'gpu_queue_ready':service.ready,'mesh_available':False,
|
| 79 |
-
'joint_count':
|
| 80 |
'immutable_revisions':True,'source_video_retained':True,'interpolation':'disabled; gaps explicit',
|
| 81 |
'retention_hours':settings.retention_s/3600,'max_frames':settings.max_frames,
|
| 82 |
'max_duration_s':settings.max_duration_s,'input_schema_url':PREFIX+'/input-schema',
|
|
|
|
| 8 |
from fastapi.responses import JSONResponse
|
| 9 |
from pydantic import ValidationError
|
| 10 |
from .motion_contract import MotionInput, MotionManifest, MotionFrame, ProjectionFrame, RevisionRequest, ADAPTER_VERSION
|
| 11 |
+
from .sam_motion import MHR
|
| 12 |
from .api_jobs import QueueFull
|
| 13 |
from .sam_runtime import configured_record, public_status
|
| 14 |
from .storage import atomic_json, read_json, sha256_file
|
|
|
|
| 77 |
return {'schema_version':'1.0','adapter':ADAPTER_VERSION,'model':'SAM 3D Body MHR70',
|
| 78 |
'tracking_implementation_sha256':sha256_file(Path(__file__).with_name('sam_measurement_worker.py')),
|
| 79 |
'sam':public_status(),'gpu_queue_ready':service.ready,'mesh_available':False,
|
| 80 |
+
'joint_count':len(MHR),'per_frame_motion':True,'projections':True,'measurement_series':True,
|
| 81 |
'immutable_revisions':True,'source_video_retained':True,'interpolation':'disabled; gaps explicit',
|
| 82 |
'retention_hours':settings.retention_s/3600,'max_frames':settings.max_frames,
|
| 83 |
'max_duration_s':settings.max_duration_s,'input_schema_url':PREFIX+'/input-schema',
|
baseball_batting/motion_contract.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
from typing import Any, Literal
|
| 3 |
from pydantic import Field, model_validator
|
| 4 |
from .sam_batting_contract import Strict, SamBattingInput
|
|
|
|
| 5 |
|
| 6 |
SCHEMA_VERSION = '1.0'
|
| 7 |
ADAPTER_VERSION = 'sam-mhr70-motion-v1'
|
|
@@ -15,7 +16,7 @@ class MotionInput(SamBattingInput):
|
|
| 15 |
handedness_source: str | None = Field(default=None, min_length=1, max_length=300)
|
| 16 |
lead_foot_source: str | None = Field(default=None, min_length=1, max_length=300)
|
| 17 |
scale_status: Literal['model_estimated', 'calibrated', 'unknown'] = 'model_estimated'
|
| 18 |
-
minimum_usable_joints: int = Field(default=3, ge=3, le=
|
| 19 |
|
| 20 |
@model_validator(mode='after')
|
| 21 |
def scale_evidence(self):
|
|
|
|
| 2 |
from typing import Any, Literal
|
| 3 |
from pydantic import Field, model_validator
|
| 4 |
from .sam_batting_contract import Strict, SamBattingInput
|
| 5 |
+
from .sam_motion import MHR
|
| 6 |
|
| 7 |
SCHEMA_VERSION = '1.0'
|
| 8 |
ADAPTER_VERSION = 'sam-mhr70-motion-v1'
|
|
|
|
| 16 |
handedness_source: str | None = Field(default=None, min_length=1, max_length=300)
|
| 17 |
lead_foot_source: str | None = Field(default=None, min_length=1, max_length=300)
|
| 18 |
scale_status: Literal['model_estimated', 'calibrated', 'unknown'] = 'model_estimated'
|
| 19 |
+
minimum_usable_joints: int = Field(default=3, ge=3, le=len(MHR), strict=True)
|
| 20 |
|
| 21 |
@model_validator(mode='after')
|
| 22 |
def scale_evidence(self):
|
baseball_batting/motion_export.py
CHANGED
|
@@ -279,7 +279,7 @@ def export_motion(job,video,capture,raw,options,model,lineage,*,retention_s=8640
|
|
| 279 |
'mapping':options.timing.model_dump(mode='json'),'original_video_time_origin_s':float(playback[0]),
|
| 280 |
'original_capture_time_origin_s':float(physical[0]) if known else None,
|
| 281 |
'maximum_derivative_gap_s':options.correction.max_gap_s},
|
| 282 |
-
skeleton={'version':'mhr70-batting-
|
| 283 |
'joints':[{'name':name,'source_schema':'MHR70','source_index':index,
|
| 284 |
'definition':'Native '+name.replace('_',' ')+' MHR70 landmark; no mesh-vertex or acromion substitution','derived':False} for name,index in MHR.items()],
|
| 285 |
'bones':[[INDEX_NAMES[a],INDEX_NAMES[b]] for a,b in BONES],
|
|
|
|
| 279 |
'mapping':options.timing.model_dump(mode='json'),'original_video_time_origin_s':float(playback[0]),
|
| 280 |
'original_capture_time_origin_s':float(physical[0]) if known else None,
|
| 281 |
'maximum_derivative_gap_s':options.correction.max_gap_s},
|
| 282 |
+
skeleton={'version':f'mhr70-batting-{len(JOINTS)}-v1','joint_order':list(JOINTS),
|
| 283 |
'joints':[{'name':name,'source_schema':'MHR70','source_index':index,
|
| 284 |
'definition':'Native '+name.replace('_',' ')+' MHR70 landmark; no mesh-vertex or acromion substitution','derived':False} for name,index in MHR.items()],
|
| 285 |
'bones':[[INDEX_NAMES[a],INDEX_NAMES[b]] for a,b in BONES],
|
docs/MOTION_PLAYER_API.md
CHANGED
|
@@ -66,7 +66,7 @@ reidentification is disabled and uncertain frames remain unusable.
|
|
| 66 |
|
| 67 |
## Manifest and artifacts
|
| 68 |
|
| 69 |
-
The manifest declares the ordered
|
| 70 |
mapping, bones, fixed coordinates, scale interpretation, source orientation,
|
| 71 |
timing map, model/checkpoint hashes, adapter/correction revisions and settings,
|
| 72 |
measurement-definition version, quality segments and artifact integrity details.
|
|
|
|
| 66 |
|
| 67 |
## Manifest and artifacts
|
| 68 |
|
| 69 |
+
The manifest declares the ordered 20-joint anatomical skeleton, native MHR70
|
| 70 |
mapping, bones, fixed coordinates, scale interpretation, source orientation,
|
| 71 |
timing map, model/checkpoint hashes, adapter/correction revisions and settings,
|
| 72 |
measurement-definition version, quality segments and artifact integrity details.
|
docs/motion-input.schema.json
CHANGED
|
@@ -654,7 +654,7 @@
|
|
| 654 |
},
|
| 655 |
"minimum_usable_joints": {
|
| 656 |
"default": 3,
|
| 657 |
-
"maximum":
|
| 658 |
"minimum": 3,
|
| 659 |
"title": "Minimum Usable Joints",
|
| 660 |
"type": "integer"
|
|
|
|
| 654 |
},
|
| 655 |
"minimum_usable_joints": {
|
| 656 |
"default": 3,
|
| 657 |
+
"maximum": 20,
|
| 658 |
"minimum": 3,
|
| 659 |
"title": "Minimum Usable Joints",
|
| 660 |
"type": "integer"
|
tests/test_motion_player.py
CHANGED
|
@@ -39,6 +39,9 @@ def test_artifacts_reconstruct_all_joints_and_reproduce_measurements(tmp_path,vi
|
|
| 39 |
MotionManifest.model_validate_json((tmp_path/'result.json').read_text())
|
| 40 |
frames=[MotionFrame.model_validate_json(line) for line in (tmp_path/'motion.jsonl').read_text().splitlines()]
|
| 41 |
assert len(frames)==capture['frame_count']
|
|
|
|
|
|
|
|
|
|
| 42 |
assert all(set(f.joints)==set(JOINTS) for f in frames)
|
| 43 |
assert all(f.joints['left_wrist'].confidence is None for f in frames)
|
| 44 |
assert manifest.coordinates['root_translation_included'] is False
|
|
@@ -157,6 +160,10 @@ def test_no_usable_pose_is_failure_instead_of_empty_success(tmp_path,video):
|
|
| 157 |
assert not (tmp_path/'result.json').exists()
|
| 158 |
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
def test_clock_gaps_and_identity_uncertainty_remain_explicit(tmp_path,video):
|
| 161 |
opts=inputs(annotated_videos=False,timing={'kind':'explicit','source':'Known fixture times',
|
| 162 |
'physical_times_s':[0,.01,.02,.03,1.,1.01,1.02,1.03]})
|
|
|
|
| 39 |
MotionManifest.model_validate_json((tmp_path/'result.json').read_text())
|
| 40 |
frames=[MotionFrame.model_validate_json(line) for line in (tmp_path/'motion.jsonl').read_text().splitlines()]
|
| 41 |
assert len(frames)==capture['frame_count']
|
| 42 |
+
expected={side+'_'+part for side in ('left','right') for part in
|
| 43 |
+
('ear','shoulder','elbow','wrist','hip','knee','ankle','heel','big_toe','small_toe')}
|
| 44 |
+
assert set(manifest.skeleton['joint_order'])==expected and len(expected)==20
|
| 45 |
assert all(set(f.joints)==set(JOINTS) for f in frames)
|
| 46 |
assert all(f.joints['left_wrist'].confidence is None for f in frames)
|
| 47 |
assert manifest.coordinates['root_translation_included'] is False
|
|
|
|
| 160 |
assert not (tmp_path/'result.json').exists()
|
| 161 |
|
| 162 |
|
| 163 |
+
def test_pose_quality_limit_cannot_exceed_the_declared_joint_count():
|
| 164 |
+
with pytest.raises(ValueError):MotionInput(minimum_usable_joints=21)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
def test_clock_gaps_and_identity_uncertainty_remain_explicit(tmp_path,video):
|
| 168 |
opts=inputs(annotated_videos=False,timing={'kind':'explicit','source':'Known fixture times',
|
| 169 |
'physical_times_s':[0,.01,.02,.03,1.,1.01,1.02,1.03]})
|
tests/test_motion_player_api.py
CHANGED
|
@@ -43,7 +43,7 @@ def test_motion_upload_auth_readiness_validation_queue_and_cancel(tmp_path,video
|
|
| 43 |
assert not job.exists()
|
| 44 |
assert client.get('/v1/motion-analyses/output-schema',headers=AUTH).status_code==200
|
| 45 |
assert client.get('/v1/motion-analyses/input-schema').status_code==401
|
| 46 |
-
assert client.get('/v1/motion-analyses/capabilities',headers=AUTH).json()['joint_count']==
|
| 47 |
monkeypatch.setattr(module,'configured_record',lambda:None)
|
| 48 |
assert client.post('/v1/motion-analyses',files=files,headers=AUTH).status_code==503
|
| 49 |
|
|
|
|
| 43 |
assert not job.exists()
|
| 44 |
assert client.get('/v1/motion-analyses/output-schema',headers=AUTH).status_code==200
|
| 45 |
assert client.get('/v1/motion-analyses/input-schema').status_code==401
|
| 46 |
+
assert client.get('/v1/motion-analyses/capabilities',headers=AUTH).json()['joint_count']==20
|
| 47 |
monkeypatch.setattr(module,'configured_record',lambda:None)
|
| 48 |
assert client.post('/v1/motion-analyses',files=files,headers=AUTH).status_code==503
|
| 49 |
|