github-actions[bot] commited on
Commit
de94a96
·
1 Parent(s): d835db0

Automated Deploy: be64d2e8616f60dd6bcbd10a5e6b0f7a00242280

Browse files
baseball_batting/motion_api.py CHANGED
@@ -74,6 +74,7 @@ def register(app,service,authenticated):
74
  @app.get(PREFIX+'/capabilities',dependencies=[Depends(authenticated)])
75
  def capabilities():
76
  return {'schema_version':'1.0','adapter':ADAPTER_VERSION,'model':'SAM 3D Body MHR70',
 
77
  'sam':public_status(),'gpu_queue_ready':service.ready,'mesh_available':False,
78
  'joint_count':22,'per_frame_motion':True,'projections':True,'measurement_series':True,
79
  'immutable_revisions':True,'source_video_retained':True,'interpolation':'disabled; gaps explicit',
@@ -172,7 +173,8 @@ def register(app,service,authenticated):
172
  # Reviewed events/calibration axes/correction changes reuse native inference.
173
  geometry=('camera','athlete_box','rotation_degrees','source_mirrored')
174
  reusable=(all(inputs.get(k)==parsed.model_dump().get(k) for k in geometry)
175
- and manifest.pipeline['adapter_sha256']==sha256_file(Path(__file__).with_name('sam_pose_worker.py')))
 
176
  integrity=parent/'inference-integrity-private.json'
177
  if reusable and integrity.is_file():
178
  hashes=read_json(integrity)
 
74
  @app.get(PREFIX+'/capabilities',dependencies=[Depends(authenticated)])
75
  def capabilities():
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':22,'per_frame_motion':True,'projections':True,'measurement_series':True,
80
  'immutable_revisions':True,'source_video_retained':True,'interpolation':'disabled; gaps explicit',
 
173
  # Reviewed events/calibration axes/correction changes reuse native inference.
174
  geometry=('camera','athlete_box','rotation_degrees','source_mirrored')
175
  reusable=(all(inputs.get(k)==parsed.model_dump().get(k) for k in geometry)
176
+ and manifest.pipeline['adapter_sha256']==sha256_file(Path(__file__).with_name('sam_pose_worker.py'))
177
+ and manifest.pipeline.get('tracking_implementation_sha256')==sha256_file(Path(__file__).with_name('sam_measurement_worker.py')))
178
  integrity=parent/'inference-integrity-private.json'
179
  if reusable and integrity.is_file():
180
  hashes=read_json(integrity)
baseball_batting/motion_export.py CHANGED
@@ -212,7 +212,8 @@ def export_motion(job,video,capture,raw,options,model,lineage,*,retention_s=8640
212
  atomic_json(job/'events.json',{'schema_version':'1.0','analysis_revision':revision,'events':events})
213
  atomic_json(job/'quality.json',{'analysis_revision':revision,'segments':segments,'correction':corrected['metadata'],
214
  'identity':{'person_id':person_id,'method':'conservative_single_athlete_box_continuity',
215
- 'reidentification':'disabled_after_tracking_loss','tracking_reasons':track['reasons']},
 
216
  'anatomical_assignment':'native_model_mapping_checked; image-level left/right accuracy unvalidated',
217
  'depth_accuracy':'unvalidated','body_shape':'native_model estimates; no independent limb stretching or mesh retargeting'})
218
  clips=export_group_videos(video,capture,corrected,raw['intrinsics'],job,progress) if options.annotated_videos else {}
@@ -256,6 +257,7 @@ def export_motion(job,video,capture,raw,options,model,lineage,*,retention_s=8640
256
  'camera_model':'pinhole','distortion_correction':'not_applied; source_lens_distortion_unverified',
257
  'camera_intrinsics_source':options.camera.source if options.camera else 'SAM model-estimated focal length and centered principal point'},
258
  pipeline={'model':model,'adapter_version':ADAPTER_VERSION,'adapter_sha256':sha256_file(Path(__file__).with_name('sam_pose_worker.py')),
 
259
  'exporter_sha256':sha256_file(Path(__file__)),'correction':corrected['metadata'],
260
  'measurement_definition_version':DEFINITION_VERSION,'measurement_definitions_sha256':digest(DEFINITIONS),
261
  'inputs':options.model_dump(mode='json'),'raw_outputs':'retained_private; never merged with corrected motion'},
 
212
  atomic_json(job/'events.json',{'schema_version':'1.0','analysis_revision':revision,'events':events})
213
  atomic_json(job/'quality.json',{'analysis_revision':revision,'segments':segments,'correction':corrected['metadata'],
214
  'identity':{'person_id':person_id,'method':'conservative_single_athlete_box_continuity',
215
+ 'reidentification':'disabled_after_tracking_loss_or_ambiguous_overlap','box_overlap_gate':.05,
216
+ 'tracking_reasons':track['reasons']},
217
  'anatomical_assignment':'native_model_mapping_checked; image-level left/right accuracy unvalidated',
218
  'depth_accuracy':'unvalidated','body_shape':'native_model estimates; no independent limb stretching or mesh retargeting'})
219
  clips=export_group_videos(video,capture,corrected,raw['intrinsics'],job,progress) if options.annotated_videos else {}
 
257
  'camera_model':'pinhole','distortion_correction':'not_applied; source_lens_distortion_unverified',
258
  'camera_intrinsics_source':options.camera.source if options.camera else 'SAM model-estimated focal length and centered principal point'},
259
  pipeline={'model':model,'adapter_version':ADAPTER_VERSION,'adapter_sha256':sha256_file(Path(__file__).with_name('sam_pose_worker.py')),
260
+ 'tracking_implementation_sha256':sha256_file(Path(__file__).with_name('sam_measurement_worker.py')),
261
  'exporter_sha256':sha256_file(Path(__file__)),'correction':corrected['metadata'],
262
  'measurement_definition_version':DEFINITION_VERSION,'measurement_definitions_sha256':digest(DEFINITIONS),
263
  'inputs':options.model_dump(mode='json'),'raw_outputs':'retained_private; never merged with corrected motion'},
baseball_batting/sam_measurement_worker.py CHANGED
@@ -24,14 +24,20 @@ def athlete_boxes(video,capture,models,options,device,progress,*,strict_identity
24
  detections=detector(image)
25
  selected=select_person(detections,previous or roi)
26
  reason=None
 
 
 
 
 
 
27
  if strict_identity and identity_lost:
28
  selected=None;reason='identity_uncertain_after_tracking_loss'
29
- if selected is None:reason='person_not_tracked'
30
  elif previous is None and roi is None and relevant_people(detections,selected,image.shape[0])>1:
31
  if strict_identity:raise ValueError('multiple_people_select_athlete_box')
32
  selected=None;reason='multiple_people_select_athlete_box'
33
  if strict_identity and previous is not None and selected is None:
34
- identity_lost=True;reason='identity_uncertain_after_tracking_loss'
35
  if selected:
36
  previous=selected['box'];box=previous
37
  box=[max(0,box[0]),max(0,box[1]),min(width,box[2]),min(height,box[3])]
 
24
  detections=detector(image)
25
  selected=select_person(detections,previous or roi)
26
  reason=None
27
+ if strict_identity and previous is not None and selected is not None:
28
+ # Use the same overlap gate as select_person. If multiple subjects
29
+ # qualify, geometry alone cannot safely establish identity continuity.
30
+ candidates=[d['box'] for d in detections if d['class_id']==0]
31
+ if np.count_nonzero(iou(np.asarray(previous),candidates)>=.05)>1:
32
+ selected=None;reason='identity_ambiguous_multiple_overlapping_athletes'
33
  if strict_identity and identity_lost:
34
  selected=None;reason='identity_uncertain_after_tracking_loss'
35
+ if selected is None:reason=reason or 'person_not_tracked'
36
  elif previous is None and roi is None and relevant_people(detections,selected,image.shape[0])>1:
37
  if strict_identity:raise ValueError('multiple_people_select_athlete_box')
38
  selected=None;reason='multiple_people_select_athlete_box'
39
  if strict_identity and previous is not None and selected is None:
40
+ identity_lost=True;reason=reason if reason=='identity_ambiguous_multiple_overlapping_athletes' else 'identity_uncertain_after_tracking_loss'
41
  if selected:
42
  previous=selected['box'];box=previous
43
  box=[max(0,box[0]),max(0,box[1]),min(width,box[2]),min(height,box[3])]
docs/MOTION_PLAYER_API.md CHANGED
@@ -61,7 +61,7 @@ No usable motion, fewer than four decoded frames, invalid timestamps, ambiguous
61
  athlete selection or inference failure produces a failed job with a reason.
62
 
63
  Multiple plausible athletes require `athlete_box`. Tracking uses conservative
64
- box continuity, not biometric identity recognition. After tracking loss, automatic
65
  reidentification is disabled and uncertain frames remain unusable.
66
 
67
  ## Manifest and artifacts
 
61
  athlete selection or inference failure produces a failed job with a reason.
62
 
63
  Multiple plausible athletes require `athlete_box`. Tracking uses conservative
64
+ box continuity, not biometric identity recognition. After tracking loss or ambiguous overlap, automatic
65
  reidentification is disabled and uncertain frames remain unusable.
66
 
67
  ## Manifest and artifacts
tests/test_motion_player.py CHANGED
@@ -217,3 +217,17 @@ def test_worker_reuses_native_inference_for_reviewed_event_revision(tmp_path,vid
217
  reject=client.post('/v1/motion-analyses/'+parent.name+'/revisions',headers=AUTH,
218
  json={'options':{'athlete_box':[0,0,100,100]}})
219
  assert reject.status_code==422
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  reject=client.post('/v1/motion-analyses/'+parent.name+'/revisions',headers=AUTH,
218
  json={'options':{'athlete_box':[0,0,100,100]}})
219
  assert reject.status_code==422
220
+
221
+
222
+ def test_overlapping_athletes_do_not_silently_switch_identity(video,monkeypatch,tmp_path):
223
+ from baseball_batting.sam_measurement_worker import athlete_boxes
224
+ opts=inputs();capture=ingest(video,opts.metadata())
225
+ a={'class_id':0,'box':[20,5,100,115],'score':.9}
226
+ b={'class_id':0,'box':[35,5,115,115],'score':.95}
227
+ detections=iter([[a],[a,b]]+[[a]]*6)
228
+ monkeypatch.setattr('baseball_batting.api_worker.model_files',lambda _:({'person_detector':'fixture'},None))
229
+ monkeypatch.setattr('baseball_batting.detection.YOLOXDetector',lambda *args,**kwargs:lambda image:next(detections))
230
+ boxes,reasons=athlete_boxes(video,capture,tmp_path,opts,'fixture',lambda *a:None,strict_identity=True)
231
+ assert boxes[0]==a['box'] and all(box is None for box in boxes[1:])
232
+ assert reasons[1]=='identity_ambiguous_multiple_overlapping_athletes'
233
+ assert all(r=='identity_uncertain_after_tracking_loss' for r in reasons[2:])