@trillboards/edge-sdk 0.2.175 → 0.2.176
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.
- package/deploy/detector/README.md +6 -0
- package/deploy/detector/pyproject.toml +4 -1
- package/deploy/detector/tests/test_actor_action_wire.py +103 -0
- package/deploy/detector/tests/test_actor_actions.py +94 -0
- package/deploy/detector/tests/test_actor_checkpoint.py +99 -0
- package/deploy/detector/tests/test_actor_tracking.py +191 -0
- package/deploy/detector/tests/test_actor_tracking_wire.py +120 -0
- package/deploy/detector/tests/test_actor_views.py +108 -0
- package/deploy/detector/tests/test_compute_budget.py +28 -0
- package/deploy/detector/tests/test_detector_request.py +52 -0
- package/deploy/detector/tests/test_input_recipe.py +77 -0
- package/deploy/detector/tests/test_loader.py +20 -1
- package/deploy/detector/tests/test_pose.py +66 -0
- package/deploy/detector/tests/test_server.py +83 -0
- package/deploy/detector/tests/test_task_registry.py +74 -0
- package/deploy/detector/trillboards_detector/_version.py +2 -2
- package/deploy/detector/trillboards_detector/actor_action_contract.py +65 -0
- package/deploy/detector/trillboards_detector/actor_action_wire.py +189 -0
- package/deploy/detector/trillboards_detector/actor_actions.py +115 -0
- package/deploy/detector/trillboards_detector/actor_checkpoint.py +91 -0
- package/deploy/detector/trillboards_detector/actor_tracking.py +337 -0
- package/deploy/detector/trillboards_detector/actor_views.py +102 -0
- package/deploy/detector/trillboards_detector/cli.py +12 -2
- package/deploy/detector/trillboards_detector/labels.py +32 -0
- package/deploy/detector/trillboards_detector/loader.py +30 -4
- package/deploy/detector/trillboards_detector/pose.py +129 -0
- package/deploy/detector/trillboards_detector/registry.py +92 -7
- package/deploy/detector/trillboards_detector/server.py +131 -3
- package/deploy/detector/trillboards_detector/session.py +83 -49
- package/deploy/detector/trillboards_detector/tasks.py +27 -0
- package/deploy/detector/trillboards_detector/worker_budget.py +14 -0
- package/deploy/windows/README.md +1 -1
- package/deploy/windows/ci/test-published-install.ps1 +16 -3
- package/dist/ActorActionClient.d.ts +47 -0
- package/dist/ActorActionClient.d.ts.map +1 -0
- package/dist/ActorActionClient.js +187 -0
- package/dist/ActorActionClient.js.map +1 -0
- package/dist/ActorActionProducer.d.ts +17 -0
- package/dist/ActorActionProducer.d.ts.map +1 -0
- package/dist/ActorActionProducer.js +92 -0
- package/dist/ActorActionProducer.js.map +1 -0
- package/dist/ActorPerception.d.ts +65 -0
- package/dist/ActorPerception.d.ts.map +1 -0
- package/dist/ActorPerception.js +124 -0
- package/dist/ActorPerception.js.map +1 -0
- package/dist/ActorPose.d.ts +42 -0
- package/dist/ActorPose.d.ts.map +1 -0
- package/dist/ActorPose.js +62 -0
- package/dist/ActorPose.js.map +1 -0
- package/dist/ActorReview.d.ts +51 -0
- package/dist/ActorReview.d.ts.map +1 -0
- package/dist/ActorReview.js +84 -0
- package/dist/ActorReview.js.map +1 -0
- package/dist/ActorTracking.d.ts +33 -0
- package/dist/ActorTracking.d.ts.map +1 -0
- package/dist/ActorTracking.js +90 -0
- package/dist/ActorTracking.js.map +1 -0
- package/dist/ActorWindow.d.ts +56 -0
- package/dist/ActorWindow.d.ts.map +1 -0
- package/dist/ActorWindow.js +86 -0
- package/dist/ActorWindow.js.map +1 -0
- package/dist/ActorWindowContract.d.ts +5 -0
- package/dist/ActorWindowContract.d.ts.map +1 -0
- package/dist/ActorWindowContract.js +23 -0
- package/dist/ActorWindowContract.js.map +1 -0
- package/dist/AudienceAnalyzeClient.d.ts +4 -0
- package/dist/AudienceAnalyzeClient.d.ts.map +1 -1
- package/dist/AudienceAnalyzeClient.js.map +1 -1
- package/dist/ChannelProber.d.ts.map +1 -1
- package/dist/ChannelProber.js +8 -0
- package/dist/ChannelProber.js.map +1 -1
- package/dist/CloudSensingManager.d.ts +7 -0
- package/dist/CloudSensingManager.d.ts.map +1 -1
- package/dist/CloudSensingManager.js +31 -0
- package/dist/CloudSensingManager.js.map +1 -1
- package/dist/EdgeAgent.js +1 -1
- package/dist/LocalDetectorClient.d.ts +5 -1
- package/dist/LocalDetectorClient.d.ts.map +1 -1
- package/dist/LocalDetectorClient.js +48 -3
- package/dist/LocalDetectorClient.js.map +1 -1
- package/dist/RetainedFieldContract.d.ts +2 -1
- package/dist/RetainedFieldContract.d.ts.map +1 -1
- package/dist/RetainedFieldContract.js +17 -5
- package/dist/RetainedFieldContract.js.map +1 -1
- package/dist/RuntimeModelSelection.d.ts.map +1 -1
- package/dist/RuntimeModelSelection.js +63 -2
- package/dist/RuntimeModelSelection.js.map +1 -1
- package/dist/TemporalReviewClient.d.ts.map +1 -1
- package/dist/TemporalReviewClient.js +20 -1
- package/dist/TemporalReviewClient.js.map +1 -1
- package/dist/TemporalReviewJournal.d.ts +10 -1
- package/dist/TemporalReviewJournal.d.ts.map +1 -1
- package/dist/TemporalReviewJournal.js +42 -10
- package/dist/TemporalReviewJournal.js.map +1 -1
- package/dist/connectorUpdate.d.ts +2 -0
- package/dist/connectorUpdate.d.ts.map +1 -1
- package/dist/connectorUpdate.js +33 -7
- package/dist/connectorUpdate.js.map +1 -1
- package/dist/diagnose.d.ts +1 -1
- package/dist/diagnose.js +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/localSensing.d.ts +4 -0
- package/dist/localSensing.d.ts.map +1 -1
- package/dist/localSensing.js +43 -8
- package/dist/localSensing.js.map +1 -1
- package/package.json +5 -5
- package/retained/RetainedCaptureClient.cjs +55 -9
- package/retained/__tests__/actor-perception.test.cjs +125 -0
- package/retained/__tests__/actor-window.test.cjs +78 -0
- package/retained/__tests__/runtime.test.cjs +44 -4
- package/retained/actor-window.cjs +62 -0
- package/retained/manager.cjs +14 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Original-resolution actor details must preserve pixels and missing evidence."""
|
|
2
|
+
import importlib.util
|
|
3
|
+
import unittest
|
|
4
|
+
# Numerical integration runs in the mandatory detector[cpu] SDK lane.
|
|
5
|
+
_missing=[name for name in ["PIL","numpy"] if importlib.util.find_spec(name) is None]
|
|
6
|
+
if _missing:
|
|
7
|
+
raise unittest.SkipTest("detector[cpu] dependencies absent: "+", ".join(_missing))
|
|
8
|
+
import unittest
|
|
9
|
+
from PIL import Image
|
|
10
|
+
from trillboards_detector.actor_views import actor_detail_views, ACTOR_DETAIL_PREPROCESSING
|
|
11
|
+
from trillboards_detector.tasks import COCO17
|
|
12
|
+
|
|
13
|
+
def joints(**points):
|
|
14
|
+
result=[]
|
|
15
|
+
for name in COCO17:
|
|
16
|
+
p=points.get(name)
|
|
17
|
+
result.append({"name":name,"x":p[0] if p else None,"y":p[1] if p else None,
|
|
18
|
+
"response":1. if p else 0.})
|
|
19
|
+
return result
|
|
20
|
+
|
|
21
|
+
class ActorDetailViewsTest(unittest.TestCase):
|
|
22
|
+
def test_original_pixels_and_named_wrists_survive_body_downsampling(self):
|
|
23
|
+
image=Image.new("RGB",(1000,1000),(0,0,255))
|
|
24
|
+
image.paste((255,0,0),(380,200,460,280))
|
|
25
|
+
views=actor_detail_views(image,[300,100,600,900],
|
|
26
|
+
joints(nose=(450,180),left_wrist=(420,240),right_wrist=(550,650)))
|
|
27
|
+
self.assertEqual([v["name"] for v in views],["head","left_wrist","right_wrist"])
|
|
28
|
+
left=views[1]
|
|
29
|
+
self.assertTrue(left["localized"])
|
|
30
|
+
self.assertEqual(left["image"].size,(224,224))
|
|
31
|
+
self.assertEqual(left["image"].getpixel((112,112)),(255,0,0))
|
|
32
|
+
self.assertEqual(left["preprocessing"],ACTOR_DETAIL_PREPROCESSING)
|
|
33
|
+
self.assertEqual(left["localization"],"pose")
|
|
34
|
+
self.assertGreater(left["sourceBounds"][2]-left["sourceBounds"][0],100)
|
|
35
|
+
|
|
36
|
+
def test_missing_wrist_is_explicit_unknown_and_never_guessed(self):
|
|
37
|
+
views=actor_detail_views(Image.new("RGB",(800,600)),[200,100,450,550],joints())
|
|
38
|
+
self.assertFalse(views[1]["localized"])
|
|
39
|
+
self.assertIsNone(views[1]["image"])
|
|
40
|
+
self.assertIsNone(views[1]["sourceBounds"])
|
|
41
|
+
self.assertEqual(views[1]["reason"],"joint_unobserved")
|
|
42
|
+
self.assertEqual(views[0]["localization"],"box_prior")
|
|
43
|
+
self.assertIsNotNone(views[0]["image"])
|
|
44
|
+
|
|
45
|
+
def test_low_response_and_out_of_actor_joints_cannot_localize_hands(self):
|
|
46
|
+
points=joints(left_wrist=(300,300),right_wrist=(790,590))
|
|
47
|
+
points[9]["response"]=.01
|
|
48
|
+
views=actor_detail_views(Image.new("RGB",(800,600)),[200,100,450,550],points)
|
|
49
|
+
self.assertTrue(all(not v["localized"] for v in views[1:]))
|
|
50
|
+
|
|
51
|
+
def test_source_bounds_clip_to_original_and_report_actual_detail(self):
|
|
52
|
+
views=actor_detail_views(Image.new("RGB",(100,100)),[0,0,30,80],
|
|
53
|
+
joints(nose=(4,8),left_wrist=(2,30)))
|
|
54
|
+
for view in views:
|
|
55
|
+
if view["sourceBounds"] is not None:
|
|
56
|
+
x1,y1,x2,y2=view["sourceBounds"]
|
|
57
|
+
self.assertTrue(0<=x1<x2<=100 and 0<=y1<y2<=100)
|
|
58
|
+
self.assertEqual(view["sourceSize"],[x2-x1,y2-y1])
|
|
59
|
+
|
|
60
|
+
def test_too_small_source_does_not_become_high_quality_by_upscaling(self):
|
|
61
|
+
view=actor_detail_views(Image.new("RGB",(30,30)),[2,2,8,14],
|
|
62
|
+
joints(nose=(5,4),left_wrist=(5,8)))[1]
|
|
63
|
+
self.assertEqual(view["reason"],"too_small")
|
|
64
|
+
self.assertFalse(view["localized"])
|
|
65
|
+
self.assertIsNone(view["image"])
|
|
66
|
+
|
|
67
|
+
def test_joint_contract_rejects_duplicates_missing_and_nonfinite(self):
|
|
68
|
+
valid=joints(nose=(300,150),left_wrist=(300,300))
|
|
69
|
+
variants=[valid[:-1],[valid[0],*valid[:-1]],
|
|
70
|
+
[{**v,"response":float("nan")} if i==0 else v for i,v in enumerate(valid)]]
|
|
71
|
+
for invalid in variants:
|
|
72
|
+
with self.subTest(invalid=invalid):
|
|
73
|
+
with self.assertRaises(ValueError):
|
|
74
|
+
actor_detail_views(Image.new("RGB",(800,600)),[200,100,450,550],invalid)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class ActorModelViewSizingTest(unittest.TestCase):
|
|
78
|
+
def test_small_actor_fills_the_declared_vlm_input_instead_of_a_tiny_patch(self):
|
|
79
|
+
from trillboards_detector.actor_views import actor_view
|
|
80
|
+
image=Image.new("RGB",(640,480),(50,100,150))
|
|
81
|
+
view=actor_view(image,[100,100,120,160],upper=True,size=448)
|
|
82
|
+
self.assertEqual(view.size,(448,448))
|
|
83
|
+
self.assertEqual(view.getpixel((224,0)),(50,100,150))
|
|
84
|
+
self.assertEqual(view.getpixel((224,447)),(50,100,150))
|
|
85
|
+
|
|
86
|
+
def test_default_temporal_training_pixels_remain_identical(self):
|
|
87
|
+
from trillboards_detector.actor_views import actor_view
|
|
88
|
+
image=Image.new("RGB",(640,480),(50,100,150))
|
|
89
|
+
a=actor_view(image,[100,100,120,160],upper=True)
|
|
90
|
+
b=actor_view(image,[100,100,120,160],upper=True,size=182)
|
|
91
|
+
self.assertEqual(a.size,(182,182))
|
|
92
|
+
self.assertEqual(a.tobytes(),b.tobytes())
|
|
93
|
+
|
|
94
|
+
def test_requested_size_never_stretches_aspect_ratio(self):
|
|
95
|
+
from trillboards_detector.actor_views import fit_actor_view
|
|
96
|
+
view=fit_actor_view(Image.new("RGB",(20,40),(255,0,0)),size=448)
|
|
97
|
+
self.assertEqual(view.getpixel((111,224)),(0,0,0))
|
|
98
|
+
self.assertEqual(view.getpixel((112,224)),(255,0,0))
|
|
99
|
+
self.assertEqual(view.getpixel((335,224)),(255,0,0))
|
|
100
|
+
self.assertEqual(view.getpixel((336,224)),(0,0,0))
|
|
101
|
+
|
|
102
|
+
def test_vlm_size_must_be_a_bounded_integer(self):
|
|
103
|
+
from trillboards_detector.actor_views import fit_actor_view
|
|
104
|
+
for size in [0,15,1025,True,"448",448.5]:
|
|
105
|
+
with self.subTest(size=size),self.assertRaises(ValueError):
|
|
106
|
+
fit_actor_view(Image.new("RGB",(20,40)),size=size)
|
|
107
|
+
|
|
108
|
+
if __name__=="__main__":unittest.main()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Launch the actual CLI in a fresh process with inherited numerical pools."""
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import os
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import unittest
|
|
8
|
+
|
|
9
|
+
PACKAGE_ROOT=Path(__file__).resolve().parents[1]
|
|
10
|
+
|
|
11
|
+
THREAD_KEYS=("OPENBLAS_NUM_THREADS","MKL_NUM_THREADS","BLIS_NUM_THREADS",
|
|
12
|
+
"VECLIB_MAXIMUM_THREADS","NUMEXPR_NUM_THREADS")
|
|
13
|
+
|
|
14
|
+
class NativeWorkerBudgetTest(unittest.TestCase):
|
|
15
|
+
def test_cli_bounds_inherited_blas_pools_before_loading_numpy(self):
|
|
16
|
+
env={**os.environ,**{key:"8" for key in THREAD_KEYS}}
|
|
17
|
+
code="import trillboards_detector.cli,os,json;print(json.dumps({k:os.environ.get(k) for k in "+repr(THREAD_KEYS)+"}))"
|
|
18
|
+
result=subprocess.run([sys.executable,"-c",code],env=env,capture_output=True,text=True,timeout=20,cwd=PACKAGE_ROOT)
|
|
19
|
+
self.assertEqual(result.returncode,0,result.stderr)
|
|
20
|
+
self.assertEqual(json.loads(result.stdout),{key:"1" for key in THREAD_KEYS})
|
|
21
|
+
|
|
22
|
+
def test_real_version_command_still_exits_without_loading_a_model(self):
|
|
23
|
+
result=subprocess.run([sys.executable,"-m","trillboards_detector","--version"],
|
|
24
|
+
capture_output=True,text=True,timeout=20,cwd=PACKAGE_ROOT)
|
|
25
|
+
self.assertEqual(result.returncode,0,result.stderr)
|
|
26
|
+
self.assertIn("trillboards-detector 0.2.0+src.",result.stdout)
|
|
27
|
+
|
|
28
|
+
if __name__=="__main__":unittest.main()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Artifact-local request validation must agree with native HTTP class resolution."""
|
|
2
|
+
import importlib.util
|
|
3
|
+
import unittest
|
|
4
|
+
# Numerical integration runs in the mandatory detector[cpu] SDK lane.
|
|
5
|
+
_missing=[name for name in ["numpy"] if importlib.util.find_spec(name) is None]
|
|
6
|
+
if _missing:
|
|
7
|
+
raise unittest.SkipTest("detector[cpu] dependencies absent: "+", ".join(_missing))
|
|
8
|
+
import unittest
|
|
9
|
+
import numpy as np
|
|
10
|
+
from trillboards_detector.labels import RFDETR_MEDIUM,ClassIndex
|
|
11
|
+
from trillboards_detector.errors import ModelContractError
|
|
12
|
+
from trillboards_detector.session import OnnxDetector,_checked_detector_request
|
|
13
|
+
|
|
14
|
+
class DetectorRequestTest(unittest.TestCase):
|
|
15
|
+
def setUp(self):
|
|
16
|
+
self.index=ClassIndex((RFDETR_MEDIUM,))
|
|
17
|
+
|
|
18
|
+
def test_class_aliases_use_the_existing_class_index_authority(self):
|
|
19
|
+
confidence,wanted=_checked_detector_request(.25,{'CELL_phone',' Person '},self.index)
|
|
20
|
+
self.assertEqual(confidence,.25)
|
|
21
|
+
self.assertEqual(wanted,{'cell phone','person'})
|
|
22
|
+
|
|
23
|
+
def test_unknown_class_cannot_look_like_an_empty_frame(self):
|
|
24
|
+
with self.assertRaisesRegex(ModelContractError,'requested classes'):
|
|
25
|
+
_checked_detector_request(.25,{'guessed_phone_model'},self.index)
|
|
26
|
+
|
|
27
|
+
def test_all_classes_and_explicit_empty_filter_keep_their_distinct_meanings(self):
|
|
28
|
+
self.assertEqual(_checked_detector_request(.25,None,self.index),(.25,None))
|
|
29
|
+
self.assertEqual(_checked_detector_request(.25,set(),self.index),(.25,set()))
|
|
30
|
+
|
|
31
|
+
def test_bad_thresholds_cannot_turn_every_detection_into_a_negative(self):
|
|
32
|
+
for bad in [float('nan'),float('inf'),-1,1.01,True,'0.25',None]:
|
|
33
|
+
with self.subTest(value=bad),self.assertRaisesRegex(ModelContractError,'min_confidence'):
|
|
34
|
+
_checked_detector_request(bad,{'person'},self.index)
|
|
35
|
+
|
|
36
|
+
def test_numeric_scalar_types_remain_accepted(self):
|
|
37
|
+
for value in [0,1,.25,np.float32(.25),np.float64(.25)]:
|
|
38
|
+
with self.subTest(value=value):
|
|
39
|
+
self.assertEqual(_checked_detector_request(value,{'person'},self.index), (float(value),{'person'}))
|
|
40
|
+
|
|
41
|
+
def test_class_filter_is_a_set_of_real_names(self):
|
|
42
|
+
for bad in ['person',['person'],{None},{1}]:
|
|
43
|
+
with self.subTest(value=bad),self.assertRaisesRegex(ModelContractError,'requested classes'):
|
|
44
|
+
_checked_detector_request(.25,bad,self.index)
|
|
45
|
+
|
|
46
|
+
def test_invalid_request_is_refused_before_a_session_is_touched(self):
|
|
47
|
+
detector=object.__new__(OnnxDetector)
|
|
48
|
+
detector._class_index=self.index
|
|
49
|
+
with self.assertRaisesRegex(ModelContractError,'requested classes'):
|
|
50
|
+
detector.detect(b'not decoded for an invalid request',.25,{'missing_class'})
|
|
51
|
+
|
|
52
|
+
if __name__=='__main__':unittest.main()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Real image transforms: an output tensor layout cannot choose a model's pixels."""
|
|
2
|
+
import importlib.util
|
|
3
|
+
import unittest
|
|
4
|
+
# Numerical integration runs in the mandatory detector[cpu] SDK lane.
|
|
5
|
+
_missing=[name for name in ["numpy","PIL","cv2"] if importlib.util.find_spec(name) is None]
|
|
6
|
+
if _missing:
|
|
7
|
+
raise unittest.SkipTest("detector[cpu] dependencies absent: "+", ".join(_missing))
|
|
8
|
+
import dataclasses
|
|
9
|
+
import io
|
|
10
|
+
import unittest
|
|
11
|
+
import numpy as np
|
|
12
|
+
from PIL import Image
|
|
13
|
+
from trillboards_detector.labels import RFDETR_MEDIUM,ModelVocabulary,VariantContract
|
|
14
|
+
from trillboards_detector.session import preprocess_for_layout,IMAGENET_MEAN,IMAGENET_STD,ModelContractError
|
|
15
|
+
|
|
16
|
+
PIL_RECIPE="imagenet-normalised-stretch"
|
|
17
|
+
HALF_PIXEL_RECIPE="rgb-float-half-pixel-no-antialias-imagenet-v1"
|
|
18
|
+
BGR_RECIPE="bgr-bytes-cv2-linear-stretch-v1"
|
|
19
|
+
YOLO_RECIPE="ultralytics-letterbox-114-centred"
|
|
20
|
+
|
|
21
|
+
def source_image():
|
|
22
|
+
# Lossless values let the 4-to-2 half-pixel reference be four known means.
|
|
23
|
+
red=np.arange(16,dtype=np.uint8).reshape(4,4)*16
|
|
24
|
+
rgb=np.stack([red,np.full((4,4),31,dtype=np.uint8),np.full((4,4),207,dtype=np.uint8)],axis=-1)
|
|
25
|
+
out=io.BytesIO();Image.fromarray(rgb).save(out,format="PNG")
|
|
26
|
+
return out.getvalue(),rgb
|
|
27
|
+
|
|
28
|
+
class InputRecipeTest(unittest.TestCase):
|
|
29
|
+
def test_existing_artifacts_keep_their_scored_input_recipe(self):
|
|
30
|
+
self.assertEqual(RFDETR_MEDIUM.input_preprocessing,PIL_RECIPE)
|
|
31
|
+
raw,_=source_image()
|
|
32
|
+
a=preprocess_for_layout("rfdetr_dets_labels",raw,2,2)[0]
|
|
33
|
+
b=preprocess_for_layout("rfdetr_dets_labels",raw,2,2,input_preprocessing=PIL_RECIPE)[0]
|
|
34
|
+
np.testing.assert_array_equal(a,b)
|
|
35
|
+
|
|
36
|
+
def test_same_box_head_can_use_a_different_measured_input_recipe(self):
|
|
37
|
+
native=dataclasses.replace(RFDETR_MEDIUM,input_preprocessing=BGR_RECIPE)
|
|
38
|
+
self.assertEqual(native.input_preprocessing,BGR_RECIPE)
|
|
39
|
+
self.assertEqual(native.onnx_variant,RFDETR_MEDIUM.onnx_variant)
|
|
40
|
+
|
|
41
|
+
def test_half_pixel_downscale_retains_reference_pixels_without_pil_lowpass(self):
|
|
42
|
+
raw,_=source_image()
|
|
43
|
+
actual,geometry,w,h=preprocess_for_layout("rfdetr_dets_labels",raw,2,2,input_preprocessing=HALF_PIXEL_RECIPE)
|
|
44
|
+
expected=np.array([[[40,72],[168,200]],[[31,31],[31,31]],[[207,207],[207,207]]],dtype=np.float32)/255
|
|
45
|
+
expected=(expected-IMAGENET_MEAN)/IMAGENET_STD
|
|
46
|
+
np.testing.assert_allclose(actual[0],expected,rtol=0,atol=1e-6)
|
|
47
|
+
self.assertIsNone(geometry);self.assertEqual((w,h),(4,4))
|
|
48
|
+
old=preprocess_for_layout("rfdetr_dets_labels",raw,2,2)[0]
|
|
49
|
+
self.assertGreater(float(np.max(np.abs(old-actual))),.05)
|
|
50
|
+
|
|
51
|
+
def test_retail_ssd_consumes_bgr_byte_scale_not_rgb_imagenet(self):
|
|
52
|
+
raw,rgb=source_image()
|
|
53
|
+
blob,geometry,w,h=preprocess_for_layout("rfdetr_dets_labels",raw,4,4,input_preprocessing=BGR_RECIPE)
|
|
54
|
+
self.assertEqual(blob.dtype,np.float32)
|
|
55
|
+
np.testing.assert_array_equal(blob[0],rgb[:,:,::-1].transpose(2,0,1))
|
|
56
|
+
self.assertIsNone(geometry);self.assertEqual((w,h),(4,4))
|
|
57
|
+
|
|
58
|
+
def test_unsupported_recipe_fails_at_model_declaration(self):
|
|
59
|
+
with self.assertRaisesRegex(ValueError,"preprocessing"):
|
|
60
|
+
dataclasses.replace(RFDETR_MEDIUM,input_preprocessing="invented-recipe")
|
|
61
|
+
|
|
62
|
+
def test_a_letterbox_recipe_cannot_feed_normalized_stretch_box_decode(self):
|
|
63
|
+
with self.assertRaisesRegex(ValueError,"preprocessing"):
|
|
64
|
+
dataclasses.replace(RFDETR_MEDIUM,input_preprocessing=YOLO_RECIPE)
|
|
65
|
+
|
|
66
|
+
def test_a_stretch_recipe_cannot_silently_feed_letterbox_box_decode(self):
|
|
67
|
+
with self.assertRaisesRegex(ValueError,"preprocessing"):
|
|
68
|
+
ModelVocabulary("wrong_geometry",{0:"person"},1,1024,
|
|
69
|
+
VariantContract("anchor_4_plus_nc","pixels",1.0),
|
|
70
|
+
input_preprocessing=BGR_RECIPE)
|
|
71
|
+
|
|
72
|
+
def test_unknown_layout_does_not_fall_through_to_yolo(self):
|
|
73
|
+
raw,_=source_image()
|
|
74
|
+
with self.assertRaises(ModelContractError):
|
|
75
|
+
preprocess_for_layout("invented_layout",raw,2,2)
|
|
76
|
+
|
|
77
|
+
if __name__=="__main__":unittest.main()
|
|
@@ -44,6 +44,25 @@ if HAVE_RUNTIME:
|
|
|
44
44
|
|
|
45
45
|
@unittest.skipUnless(HAVE_RUNTIME, "onnxruntime/numpy/Pillow are not installed")
|
|
46
46
|
class TestBuildCatalogue(unittest.TestCase):
|
|
47
|
+
def test_pose_path_does_not_inherit_the_detector_only_override(self):
|
|
48
|
+
from trillboards_detector.tasks import RTMPOSE_BODY7
|
|
49
|
+
entries = build_catalogue("rfdetr_medium", None, (RFDETR_MEDIUM,),
|
|
50
|
+
{"HOME": "/h", "TRILLBOARDS_DETECTOR_MODEL": "/bench/person.onnx"},
|
|
51
|
+
task_models=(RTMPOSE_BODY7,))
|
|
52
|
+
pose = next(e for e in entries if e.name == "rtmpose_m_body7")
|
|
53
|
+
self.assertTrue(str(pose.path).endswith("/models/rtmpose_m_body7/model.onnx"))
|
|
54
|
+
self.assertNotEqual(str(pose.path), "/bench/person.onnx")
|
|
55
|
+
|
|
56
|
+
def test_pose_task_uses_its_own_ota_path_without_detection_classes(self):
|
|
57
|
+
from trillboards_detector.tasks import RTMPOSE_BODY7
|
|
58
|
+
entries = build_catalogue("rfdetr_medium", None, (RFDETR_MEDIUM,),
|
|
59
|
+
{"HOME": "/h"}, task_models=(RTMPOSE_BODY7,))
|
|
60
|
+
pose = next(e for e in entries if e.name == "rtmpose_m_body7")
|
|
61
|
+
self.assertTrue(str(pose.path).endswith("/models/rtmpose_m_body7/model.onnx"))
|
|
62
|
+
self.assertEqual(pose.vocabulary.task, "pose_coco17")
|
|
63
|
+
self.assertFalse(hasattr(pose.vocabulary, "class_names"))
|
|
64
|
+
|
|
65
|
+
|
|
47
66
|
def test_the_pinned_model_comes_first_so_it_wins_every_class_tie(self):
|
|
48
67
|
"""Catalogue order IS the disambiguation rule. `person` must keep coming
|
|
49
68
|
from the model the 98.8/98.8 was measured on, whatever a later
|
|
@@ -110,7 +129,7 @@ class TestHealthIsOneRead(unittest.TestCase):
|
|
|
110
129
|
self.assertEqual(len(calls), 1, "`/health` read the registry twice; it must describe one moment")
|
|
111
130
|
# And it is still the payload every existing reader parses.
|
|
112
131
|
self.assertEqual(payload["model"], "rfdetr_medium")
|
|
113
|
-
self.assertEqual(sorted(payload["models"]), ["ppe", "rfdetr_medium"])
|
|
132
|
+
self.assertEqual(sorted(payload["models"]), ["ppe", "rfdetr_medium", "rtmpose_m_body7"])
|
|
114
133
|
self.assertEqual(payload["resident_models"], [])
|
|
115
134
|
|
|
116
135
|
def test_before_the_first_stat_the_answer_is_loading_and_names_no_reason(self):
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Pose pixel/coordinate contracts against the published RTMPose export."""
|
|
2
|
+
import importlib.util
|
|
3
|
+
import unittest
|
|
4
|
+
# The dependency-free wire lane has no numerical packages. The mandatory CPU
|
|
5
|
+
# SDK lane installs detector[cpu] and executes these real numerical tests.
|
|
6
|
+
_missing=[name for name in ["numpy","cv2"] if importlib.util.find_spec(name) is None]
|
|
7
|
+
if _missing:
|
|
8
|
+
raise unittest.SkipTest("detector[cpu] dependencies absent: "+", ".join(_missing))
|
|
9
|
+
import unittest
|
|
10
|
+
import numpy as np
|
|
11
|
+
from trillboards_detector.pose import prepare_pose, decode_pose, PoseGeometry
|
|
12
|
+
|
|
13
|
+
class PoseContractTest(unittest.TestCase):
|
|
14
|
+
def test_opencv_preprocessing_has_one_bounded_worker(self):
|
|
15
|
+
import cv2
|
|
16
|
+
self.assertLessEqual(cv2.getNumThreads(),1)
|
|
17
|
+
|
|
18
|
+
def test_jpeg_rgb_order_is_preserved_before_imagenet_normalization(self):
|
|
19
|
+
# The exporter says to_rgb=true. The image decoder supplies RGB; an
|
|
20
|
+
# OpenCV BGR round-trip here silently feeds the wrong channels.
|
|
21
|
+
image = np.full((320,240,3), [240,80,20], dtype=np.uint8)
|
|
22
|
+
tensor, geometry = prepare_pose(image, (40.,40.,200.,280.))
|
|
23
|
+
self.assertEqual(tensor.shape,(1,3,256,192))
|
|
24
|
+
self.assertEqual(tensor.dtype,np.float32)
|
|
25
|
+
np.testing.assert_allclose(tensor[0,:,128,96],
|
|
26
|
+
(np.array([240,80,20])-np.array([123.675,116.28,103.53]))/np.array([58.395,57.12,57.375]),
|
|
27
|
+
atol=1e-6)
|
|
28
|
+
self.assertGreater(tensor[0,0,128,96],tensor[0,2,128,96])
|
|
29
|
+
|
|
30
|
+
def test_padding_and_affine_center_match_original_camera_pixels(self):
|
|
31
|
+
image=np.zeros((480,640,3),np.uint8)
|
|
32
|
+
_,g=prepare_pose(image,(100.,80.,180.,280.))
|
|
33
|
+
self.assertEqual(g.center,(140.,180.))
|
|
34
|
+
self.assertEqual(g.scale,(187.5,250.))
|
|
35
|
+
x=np.zeros((1,17,384),np.float32);y=np.zeros((1,17,512),np.float32)
|
|
36
|
+
x[:,:,192]=.8;y[:,:,256]=.2
|
|
37
|
+
points=decode_pose(x,y,g)
|
|
38
|
+
for p in points:
|
|
39
|
+
self.assertAlmostEqual(p['x'],140.)
|
|
40
|
+
self.assertAlmostEqual(p['y'],180.)
|
|
41
|
+
# MMPose SimCC uses the weaker axis, not a mean that hides it.
|
|
42
|
+
self.assertAlmostEqual(p['response'],.2)
|
|
43
|
+
self.assertEqual(points[9]['name'],'left_wrist')
|
|
44
|
+
self.assertEqual(points[10]['name'],'right_wrist')
|
|
45
|
+
|
|
46
|
+
def test_nonpositive_axis_or_off_camera_joint_is_unobservable(self):
|
|
47
|
+
g=PoseGeometry((0.,0.),(192.,256.),(640,480))
|
|
48
|
+
x=np.zeros((1,17,384),np.float32);y=np.zeros((1,17,512),np.float32)
|
|
49
|
+
x[:,:,0]=.9;y[:,:,0]=.9
|
|
50
|
+
p=decode_pose(x,y,g)
|
|
51
|
+
self.assertTrue(all(j['x'] is None and j['y'] is None for j in p))
|
|
52
|
+
y.fill(-1)
|
|
53
|
+
p=decode_pose(x,y,g)
|
|
54
|
+
self.assertTrue(all(j['x'] is None and j['y'] is None for j in p))
|
|
55
|
+
|
|
56
|
+
def test_invalid_pixels_boxes_and_tensor_axes_are_refused(self):
|
|
57
|
+
im=np.zeros((480,640,3),np.uint8)
|
|
58
|
+
for pixels,box in [(im.astype(float),(0,0,20,20)),(im[:,:,0],(0,0,20,20)),
|
|
59
|
+
(im,(0,0,0,20)),(im,(0,0,1000,20)),(im,(False,0,20,20))]:
|
|
60
|
+
with self.assertRaises(ValueError):prepare_pose(pixels,box)
|
|
61
|
+
_,g=prepare_pose(im,(0,0,40,100))
|
|
62
|
+
for x,y in [(np.zeros((17,384)),np.zeros((1,17,512))),
|
|
63
|
+
(np.zeros((1,17,383)),np.zeros((1,17,512))),
|
|
64
|
+
(np.full((1,17,384),np.nan),np.zeros((1,17,512)))]:
|
|
65
|
+
with self.assertRaises(ValueError):decode_pose(x,y,g)
|
|
66
|
+
if __name__=='__main__':unittest.main()
|
|
@@ -798,5 +798,88 @@ class TestChunkedTrailerBound(ServerCase):
|
|
|
798
798
|
s.close()
|
|
799
799
|
|
|
800
800
|
|
|
801
|
+
|
|
802
|
+
class ActorActionServerTest(ServerCase):
|
|
803
|
+
def loader(self,mutate=None,raises=None):
|
|
804
|
+
if __package__:
|
|
805
|
+
from .test_actor_action_wire import fixture
|
|
806
|
+
else:
|
|
807
|
+
from test_actor_action_wire import fixture
|
|
808
|
+
class ActionLoader(FakeLoader):
|
|
809
|
+
def classify_actor_actions(self,batch):
|
|
810
|
+
self.calls.append(batch)
|
|
811
|
+
if raises is not None:raise raises
|
|
812
|
+
result={"version":1,"modelId":batch.model["modelId"],"modelSha256":batch.model["sha256"],
|
|
813
|
+
"preprocessing":"rgb_contact_v1","fields":list(batch.fields),"inferenceMs":2.,
|
|
814
|
+
"results":[{"windowSha256":w.sha256,"actor":w.data["actor"],
|
|
815
|
+
"fields":{f:{"state":"present","reason":None} for f in batch.fields},
|
|
816
|
+
"scores":{f:1.5 for f in batch.fields}} for w in batch.windows]}
|
|
817
|
+
if mutate:mutate(result)
|
|
818
|
+
return result
|
|
819
|
+
return ActionLoader()
|
|
820
|
+
|
|
821
|
+
def test_selected_actor_action_roundtrip_preserves_the_original_actor_and_window(self):
|
|
822
|
+
if __package__:
|
|
823
|
+
from .test_actor_action_wire import fixture
|
|
824
|
+
else:
|
|
825
|
+
from test_actor_action_wire import fixture
|
|
826
|
+
body,window=fixture();loader=self.loader();url=self.serve(loader)
|
|
827
|
+
status,result=self.request(url+"/actor-actions",method="POST",body=body)
|
|
828
|
+
self.assertEqual(status,200);self.assertEqual(result["results"][0]["actor"],window["actor"])
|
|
829
|
+
self.assertEqual(result["results"][0]["windowSha256"],body["windows"][0]["sha256"])
|
|
830
|
+
self.assertEqual(loader.calls[0].images.keys(),{body["images"][0]["sha256"]})
|
|
831
|
+
|
|
832
|
+
def test_changed_original_evidence_is_refused_before_model_execution(self):
|
|
833
|
+
if __package__:
|
|
834
|
+
from .test_actor_action_wire import fixture
|
|
835
|
+
else:
|
|
836
|
+
from test_actor_action_wire import fixture
|
|
837
|
+
body,_=fixture();body["windows"][0]["sha256"]="f"*64;loader=self.loader()
|
|
838
|
+
status,_=self.request(self.serve(loader)+"/actor-actions",method="POST",body=body)
|
|
839
|
+
self.assertEqual(status,400);self.assertEqual(loader.calls,[])
|
|
840
|
+
|
|
841
|
+
def test_missing_native_action_capability_is_unavailable_not_a_negative(self):
|
|
842
|
+
if __package__:
|
|
843
|
+
from .test_actor_action_wire import fixture
|
|
844
|
+
else:
|
|
845
|
+
from test_actor_action_wire import fixture
|
|
846
|
+
status,_=self.request(self.serve(FakeLoader())+"/actor-actions",method="POST",body=fixture()[0])
|
|
847
|
+
self.assertEqual(status,503)
|
|
848
|
+
|
|
849
|
+
def test_missing_or_changed_selected_artifact_has_an_explicit_error(self):
|
|
850
|
+
if __package__:
|
|
851
|
+
from .test_actor_action_wire import fixture
|
|
852
|
+
else:
|
|
853
|
+
from test_actor_action_wire import fixture
|
|
854
|
+
from trillboards_detector.errors import ModelVerificationError
|
|
855
|
+
for error,expected in [(DetectorNotReady("missing selected action artifact"),503),
|
|
856
|
+
(ModelVerificationError("wrong selected action artifact"),409)]:
|
|
857
|
+
with self.subTest(expected=expected):
|
|
858
|
+
status,_=self.request(self.serve(self.loader(raises=error))+"/actor-actions",method="POST",body=fixture()[0])
|
|
859
|
+
self.assertEqual(status,expected)
|
|
860
|
+
|
|
861
|
+
def test_malformed_native_action_result_never_leaves_as_a_success(self):
|
|
862
|
+
if __package__:
|
|
863
|
+
from .test_actor_action_wire import fixture
|
|
864
|
+
else:
|
|
865
|
+
from test_actor_action_wire import fixture
|
|
866
|
+
mutations=[lambda r:r.update(modelSha256="f"*64),lambda r:r.update(results=[]),
|
|
867
|
+
lambda r:r["results"][0]["actor"].update(id="other_person"),
|
|
868
|
+
lambda r:r["results"][0]["fields"]["phone_use"].update(state="unknown"),
|
|
869
|
+
lambda r:r["results"][0]["scores"].update(phone_use=float("nan"))]
|
|
870
|
+
for mutate in mutations:
|
|
871
|
+
with self.subTest(mutate=mutate):
|
|
872
|
+
status,_=self.request(self.serve(self.loader(mutate=mutate))+"/actor-actions",method="POST",body=fixture()[0])
|
|
873
|
+
self.assertEqual(status,500)
|
|
874
|
+
|
|
875
|
+
def test_no_actors_remains_an_empty_success_with_model_proof(self):
|
|
876
|
+
if __package__:
|
|
877
|
+
from .test_actor_action_wire import fixture
|
|
878
|
+
else:
|
|
879
|
+
from test_actor_action_wire import fixture
|
|
880
|
+
body,_=fixture();body.update(windows=[],images=[])
|
|
881
|
+
status,result=self.request(self.serve(self.loader())+"/actor-actions",method="POST",body=body)
|
|
882
|
+
self.assertEqual(status,200);self.assertEqual(result["results"],[])
|
|
883
|
+
|
|
801
884
|
if __name__ == "__main__":
|
|
802
885
|
unittest.main()
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Non-box tasks share the detector's real admission and eviction policy."""
|
|
2
|
+
import tempfile
|
|
3
|
+
import unittest
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from trillboards_detector.errors import DetectorNotReady, ModelVerificationError
|
|
6
|
+
from trillboards_detector.labels import RFDETR_MEDIUM
|
|
7
|
+
from trillboards_detector.registry import ModelEntry, ModelRegistry, TaskModelContract
|
|
8
|
+
|
|
9
|
+
SHA="a"*64
|
|
10
|
+
class TaskAdmissionTest(unittest.TestCase):
|
|
11
|
+
def setUp(self):
|
|
12
|
+
self.tmp=tempfile.TemporaryDirectory();self.addCleanup(self.tmp.cleanup)
|
|
13
|
+
root=Path(self.tmp.name);self.det=root/"det.onnx";self.pose=root/"pose.onnx"
|
|
14
|
+
self.det.write_bytes(b"det");self.pose.write_bytes(b"pose")
|
|
15
|
+
self.task=TaskModelContract("pose_test","pose_coco17",SHA,100*1024**2,"test_rgb_affine")
|
|
16
|
+
self.loads=[]
|
|
17
|
+
|
|
18
|
+
def registry(self,budget):
|
|
19
|
+
class Session:
|
|
20
|
+
model_sha256=SHA
|
|
21
|
+
def estimate(self,jpeg,boxes):
|
|
22
|
+
return {"modelId":"pose_test","modelSha256":SHA,
|
|
23
|
+
"preprocessing":"test_rgb_affine","poses":[[] for _ in boxes]}
|
|
24
|
+
def factory(entry):
|
|
25
|
+
self.loads.append(entry.name)
|
|
26
|
+
return Session()
|
|
27
|
+
reg=ModelRegistry([ModelEntry(RFDETR_MEDIUM,self.det,pinned=True),ModelEntry(self.task,self.pose)],
|
|
28
|
+
factory,lambda session:None,budget,log=lambda line:None)
|
|
29
|
+
reg.refresh()
|
|
30
|
+
return reg
|
|
31
|
+
|
|
32
|
+
def test_pose_is_not_a_detection_class_and_is_lazy(self):
|
|
33
|
+
reg=self.registry(800*1024**2)
|
|
34
|
+
self.assertEqual(reg.class_index().model_names,("rfdetr_medium",))
|
|
35
|
+
self.assertEqual(self.loads,["rfdetr_medium"])
|
|
36
|
+
result=reg.estimate_pose(b"jpeg",[[1,2,3,4]],{"modelId":"pose_test","sha256":SHA})
|
|
37
|
+
self.assertEqual(len(result["poses"]),1)
|
|
38
|
+
self.assertEqual(self.loads,["rfdetr_medium","pose_test"])
|
|
39
|
+
self.assertEqual(reg.snapshot()["models"]["pose_test"]["task"],"pose_coco17")
|
|
40
|
+
self.assertEqual(reg.snapshot()["ram_resident_bytes"],732*1024**2)
|
|
41
|
+
|
|
42
|
+
def test_pose_cannot_bypass_the_shared_ram_ceiling(self):
|
|
43
|
+
reg=self.registry(700*1024**2)
|
|
44
|
+
with self.assertRaises(DetectorNotReady):
|
|
45
|
+
reg.estimate_pose(b"jpeg",[],{"modelId":"pose_test","sha256":SHA})
|
|
46
|
+
self.assertEqual(self.loads,["rfdetr_medium"])
|
|
47
|
+
|
|
48
|
+
def test_no_injected_ceiling_refuses_a_second_task(self):
|
|
49
|
+
reg=self.registry(None)
|
|
50
|
+
with self.assertRaises(DetectorNotReady):
|
|
51
|
+
reg.estimate_pose(b"jpeg",[],{"modelId":"pose_test","sha256":SHA})
|
|
52
|
+
|
|
53
|
+
def test_task_pin_and_task_kind_are_checked_before_loading(self):
|
|
54
|
+
reg=self.registry(800*1024**2)
|
|
55
|
+
with self.assertRaises(ModelVerificationError):
|
|
56
|
+
reg.estimate_pose(b"jpeg",[],{"modelId":"pose_test","sha256":"b"*64})
|
|
57
|
+
with self.assertRaises(ModelVerificationError):
|
|
58
|
+
reg.estimate_pose(b"jpeg",[],{"modelId":"rfdetr_medium","sha256":SHA})
|
|
59
|
+
with self.assertRaises(ModelVerificationError):
|
|
60
|
+
reg.detect(b"jpeg",.25,{"person"},expected_model={"modelId":"pose_test","sha256":SHA})
|
|
61
|
+
self.assertEqual(self.loads,["rfdetr_medium"])
|
|
62
|
+
|
|
63
|
+
def test_loaded_bytes_must_match_the_task_contract(self):
|
|
64
|
+
reg=self.registry(800*1024**2)
|
|
65
|
+
reg._session_factory=lambda entry:type("Wrong",(),{"model_sha256":"b"*64})()
|
|
66
|
+
with self.assertRaises(ModelVerificationError):
|
|
67
|
+
reg.estimate_pose(b"jpeg",[],{"modelId":"pose_test","sha256":SHA})
|
|
68
|
+
self.assertEqual(reg._states["pose_test"].in_flight,0)
|
|
69
|
+
|
|
70
|
+
def test_task_cannot_be_the_general_detection_gate(self):
|
|
71
|
+
with self.assertRaises(ValueError):
|
|
72
|
+
ModelRegistry([ModelEntry(self.task,self.pose,pinned=True)],None,None,200*1024**2)
|
|
73
|
+
|
|
74
|
+
if __name__=="__main__":unittest.main()
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Immutable non-box model semantics, including cadence and decision thresholds."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
import math,re
|
|
5
|
+
from .registry import TaskModelContract
|
|
6
|
+
|
|
7
|
+
CONTACT_PREPROCESSING="actor_upper_head_left_right_rgb_grid2x2_112_area_x3d9x2fps_mean114.75_std57.38_v1"
|
|
8
|
+
|
|
9
|
+
@dataclass(frozen=True)
|
|
10
|
+
class ActorActionWindowContract:
|
|
11
|
+
frames:int=9
|
|
12
|
+
period_ms:int=500
|
|
13
|
+
tolerance_ms:int=100
|
|
14
|
+
max_gap_ms:int=1000
|
|
15
|
+
min_observed_frames:int=3
|
|
16
|
+
def __post_init__(self):
|
|
17
|
+
values=(self.frames,self.period_ms,self.tolerance_ms,self.max_gap_ms,self.min_observed_frames)
|
|
18
|
+
if (any(type(v) is not int for v in values) or not 2<=self.frames<=64
|
|
19
|
+
or not 100<=self.period_ms<=5000 or not 0<=self.tolerance_ms<=self.period_ms//2
|
|
20
|
+
or not self.period_ms<=self.max_gap_ms<=10000
|
|
21
|
+
or not 1<=self.min_observed_frames<=self.frames
|
|
22
|
+
or (self.frames-1)*self.period_ms+self.tolerance_ms>60000):
|
|
23
|
+
raise ValueError("invalid model actor window contract")
|
|
24
|
+
def as_dict(self):
|
|
25
|
+
return {"version":1,"frames":self.frames,"periodMs":self.period_ms,"toleranceMs":self.tolerance_ms,
|
|
26
|
+
"maxGapMs":self.max_gap_ms,"minObservedFrames":self.min_observed_frames}
|
|
27
|
+
@classmethod
|
|
28
|
+
def from_dict(cls,value):
|
|
29
|
+
if (not isinstance(value,dict)
|
|
30
|
+
or set(value)!={"version","frames","periodMs","toleranceMs","maxGapMs","minObservedFrames"}
|
|
31
|
+
or type(value["version"]) is not int or value["version"]!=1):
|
|
32
|
+
raise ValueError("invalid model actor window contract")
|
|
33
|
+
return cls(value["frames"],value["periodMs"],value["toleranceMs"],value["maxGapMs"],value["minObservedFrames"])
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class ActorActionOutput:
|
|
37
|
+
field:str
|
|
38
|
+
absent_below_logit:float
|
|
39
|
+
present_above_logit:float
|
|
40
|
+
def __post_init__(self):
|
|
41
|
+
if (not isinstance(self.field,str) or not re.fullmatch(r"[a-z][a-z0-9_]{0,127}",self.field)
|
|
42
|
+
or any(type(v) not in (int,float) or not math.isfinite(v)
|
|
43
|
+
for v in (self.absent_below_logit,self.present_above_logit))
|
|
44
|
+
or self.absent_below_logit>=self.present_above_logit):
|
|
45
|
+
raise ValueError("invalid calibrated actor action output")
|
|
46
|
+
def as_dict(self):
|
|
47
|
+
return {"field":self.field,"absentBelowLogit":self.absent_below_logit,"presentAboveLogit":self.present_above_logit}
|
|
48
|
+
|
|
49
|
+
@dataclass(frozen=True)
|
|
50
|
+
class ActorActionModelContract(TaskModelContract):
|
|
51
|
+
outputs:tuple[ActorActionOutput,...]=()
|
|
52
|
+
window:ActorActionWindowContract=ActorActionWindowContract()
|
|
53
|
+
requires_pose:bool=True
|
|
54
|
+
def _validate_task(self):
|
|
55
|
+
if (self.task!="actor_actions" or self.preprocessing!=CONTACT_PREPROCESSING
|
|
56
|
+
or not isinstance(self.outputs,tuple) or not 1<=len(self.outputs)<=16
|
|
57
|
+
or any(not isinstance(o,ActorActionOutput) for o in self.outputs)
|
|
58
|
+
or len({o.field for o in self.outputs})!=len(self.outputs)
|
|
59
|
+
or not isinstance(self.window,ActorActionWindowContract)
|
|
60
|
+
or self.window.frames!=9 or self.window.period_ms!=500 or self.window.min_observed_frames!=3
|
|
61
|
+
or type(self.requires_pose) is not bool):
|
|
62
|
+
raise ValueError("invalid typed actor action model contract")
|
|
63
|
+
def as_dict(self):
|
|
64
|
+
return {"version":1,"preprocessing":self.preprocessing,"window":self.window.as_dict(),
|
|
65
|
+
"requiresPose":self.requires_pose,"outputs":[o.as_dict() for o in self.outputs]}
|