@trillboards/edge-sdk 0.2.170 → 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 +9 -0
- package/dist/CloudSensingManager.d.ts.map +1 -1
- package/dist/CloudSensingManager.js +41 -4
- 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/MosaicSource.d.ts.map +1 -1
- package/dist/MosaicSource.js +3 -2
- package/dist/MosaicSource.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/config.d.ts +10 -43
- package/dist/config.d.ts.map +1 -1
- package/dist/config.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/jpegFrameSize.d.ts +1 -29
- package/dist/jpegFrameSize.d.ts.map +1 -1
- package/dist/jpegFrameSize.js +3 -91
- package/dist/jpegFrameSize.js.map +1 -1
- package/dist/localSensing.d.ts +13 -10
- package/dist/localSensing.d.ts.map +1 -1
- package/dist/localSensing.js +86 -72
- package/dist/localSensing.js.map +1 -1
- package/package.json +7 -7
- 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
|
@@ -320,3 +320,9 @@ and both now closed in the file:
|
|
|
320
320
|
and it feeds the reference the pixels that came back OUT of the JPEG rather
|
|
321
321
|
than the canvas that went in, because JPEG at quality 100 is still lossy
|
|
322
322
|
enough to move a borderline box.
|
|
323
|
+
|
|
324
|
+
### Actor action tasks
|
|
325
|
+
|
|
326
|
+
`POST /actor-actions` executes a selected `actor_actions` model over original, actor-bound causal windows. Requests carry the exact window proof source, its SHA-256, pinned model bytes and deduplicated original JPEGs. The service verifies image hashes, cadence, actor identity and output ownership before returning raw logits and present/absent/unobservable readings. It uses the same lazy model residency budget as detection and pose.
|
|
327
|
+
|
|
328
|
+
The bundled `phone_use_x3d_contact_e3_20261027` contract identifies a development artifact. It grants no website field or OTA distribution. Its calibration result is 12/104 positive events and 0/154 negative events; it must not be selected for a production phone-use claim. The full input recipe and operating thresholds are embedded in the verified ONNX artifact.
|
|
@@ -10,7 +10,7 @@ name = "trillboards-detector"
|
|
|
10
10
|
# constant, a `labels.py`-only change survives `uv tool install` AND
|
|
11
11
|
# `uv tool install --force`; move the version and a bare `uv tool install`
|
|
12
12
|
# reinstalls. See `stamp_version.py`.
|
|
13
|
-
version = "0.2.0+src.
|
|
13
|
+
version = "0.2.0+src.2f51129753df"
|
|
14
14
|
description = "On-device object-detector service for the Trillboards BYO-CCTV connector (loopback HTTP, ONNX Runtime)."
|
|
15
15
|
requires-python = ">=3.10"
|
|
16
16
|
|
|
@@ -31,6 +31,9 @@ requires-python = ">=3.10"
|
|
|
31
31
|
dependencies = [
|
|
32
32
|
"numpy==2.5.2",
|
|
33
33
|
"pillow==12.3.0",
|
|
34
|
+
"trackers==2.6.1",
|
|
35
|
+
"supervision==0.31.2",
|
|
36
|
+
"opencv-python==5.0.0.93",
|
|
34
37
|
]
|
|
35
38
|
|
|
36
39
|
# Exactly one runtime per managed tool environment. Both wheels export the
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Original actor-window transport: preserve uncertainty and refuse altered evidence."""
|
|
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 ["PIL"] if importlib.util.find_spec(name) is None]
|
|
7
|
+
if _missing:
|
|
8
|
+
raise unittest.SkipTest("detector[cpu] dependencies absent: "+", ".join(_missing))
|
|
9
|
+
import base64,copy,hashlib,io,json,unittest
|
|
10
|
+
from PIL import Image
|
|
11
|
+
from trillboards_detector.actor_action_wire import parse_actor_action_request
|
|
12
|
+
|
|
13
|
+
def digest(raw):return hashlib.sha256(raw).hexdigest()
|
|
14
|
+
def packed(value):return json.dumps(value,sort_keys=True,separators=(",",":"))
|
|
15
|
+
def fixture():
|
|
16
|
+
out=io.BytesIO();Image.new("RGB",(240,320),(230,80,20)).save(out,format="JPEG")
|
|
17
|
+
jpeg=out.getvalue();image_sha=digest(jpeg)
|
|
18
|
+
actor={"kind":"person","cameraId":"camera_1","epoch":"epoch_1","id":"track_1"}
|
|
19
|
+
contract={"version":1,"frames":9,"periodMs":500,"toleranceMs":100,"maxGapMs":1000,"minObservedFrames":3}
|
|
20
|
+
samples=[{"state":"observed","slotAtMs":1000+i*500,"frameId":"capture_"+str(i),
|
|
21
|
+
"capturedAtMs":1000+i*500,"imageSha256":image_sha,"perceptionSha256":"a"*64,
|
|
22
|
+
"trackingSha256":"b"*64,"actor":actor,"box":[20.25,30,180,300]} for i in range(9)]
|
|
23
|
+
window={"version":1,"actor":actor,"sourceId":"channel_1","contextSha256":"c"*64,
|
|
24
|
+
"policySha256":"d"*64,"currentFrameId":"capture_8","currentCapturedAtMs":5000,
|
|
25
|
+
"contract":contract,"samples":samples,"observedFrames":9,"usable":True}
|
|
26
|
+
source=packed(window)
|
|
27
|
+
body={"version":1,"model":{"modelId":"phone_action_test","sha256":"e"*64},"fields":["phone_use"],
|
|
28
|
+
"windows":[{"sha256":digest(source.encode()),"proofSource":source}],
|
|
29
|
+
"images":[{"sha256":image_sha,"jpeg":base64.b64encode(jpeg).decode()}]}
|
|
30
|
+
return body,window
|
|
31
|
+
def replace_window(body,window):
|
|
32
|
+
source=packed(window);body["windows"]=[{"sha256":digest(source.encode()),"proofSource":source}]
|
|
33
|
+
return body
|
|
34
|
+
class ActorActionWireTest(unittest.TestCase):
|
|
35
|
+
def parse(self,body):return parse_actor_action_request(packed(body).encode())
|
|
36
|
+
def test_exact_original_proof_text_is_hashed_without_float_reserialization(self):
|
|
37
|
+
body,window=fixture()
|
|
38
|
+
# A legitimate JS JSON number need not match Python's serializer spelling.
|
|
39
|
+
source=body["windows"][0]["proofSource"].replace("20.25","2.025e1")
|
|
40
|
+
body["windows"]=[{"sha256":digest(source.encode()),"proofSource":source}]
|
|
41
|
+
batch=self.parse(body)
|
|
42
|
+
self.assertEqual(batch.model,body["model"]);self.assertEqual(batch.fields,("phone_use",))
|
|
43
|
+
self.assertEqual(batch.windows[0].sha256,body["windows"][0]["sha256"])
|
|
44
|
+
self.assertEqual(batch.windows[0].proof_source,source)
|
|
45
|
+
self.assertEqual(batch.windows[0].data["samples"][0]["box"][0],20.25)
|
|
46
|
+
self.assertEqual(len(batch.images),1)
|
|
47
|
+
def test_missing_slots_are_explicit_and_never_replaced_with_another_image(self):
|
|
48
|
+
body,window=fixture()
|
|
49
|
+
for i in range(7):window["samples"][i]={"state":"unobservable","slotAtMs":1000+i*500,"reason":"not_captured"}
|
|
50
|
+
window["observedFrames"]=2;window["usable"]=False
|
|
51
|
+
batch=self.parse(replace_window(body,window))
|
|
52
|
+
self.assertFalse(batch.windows[0].data["usable"])
|
|
53
|
+
self.assertEqual(len(batch.windows[0].data["samples"]),9)
|
|
54
|
+
def test_zero_people_is_a_complete_empty_batch_not_a_fabricated_negative(self):
|
|
55
|
+
body,_=fixture();body["windows"]=[];body["images"]=[]
|
|
56
|
+
batch=self.parse(body);self.assertEqual(batch.windows,());self.assertEqual(batch.images,{})
|
|
57
|
+
def test_changed_original_pixels_or_proof_digest_is_refused(self):
|
|
58
|
+
for change in ["image","proof"]:
|
|
59
|
+
body,_=fixture()
|
|
60
|
+
if change=="image":body["images"][0]["jpeg"]=base64.b64encode(b"changed pixels").decode()
|
|
61
|
+
else:body["windows"][0]["sha256"]="f"*64
|
|
62
|
+
with self.subTest(change=change),self.assertRaises(ValueError):self.parse(body)
|
|
63
|
+
def test_invalid_actor_history_is_refused_before_model_execution(self):
|
|
64
|
+
mutations=[
|
|
65
|
+
lambda w:w["samples"][0].update(actor={**w["actor"],"cameraId":"camera_other"}),
|
|
66
|
+
lambda w:w["samples"][0].update(actor={**w["actor"],"epoch":"epoch_other"}),
|
|
67
|
+
lambda w:w["samples"][0].update(frameId="capture_8"),
|
|
68
|
+
lambda w:w["samples"][0].update(capturedAtMs=6000),
|
|
69
|
+
lambda w:w["samples"][0].update(capturedAtMs=1500),
|
|
70
|
+
lambda w:w["samples"][0].update(slotAtMs=1500),
|
|
71
|
+
lambda w:w["samples"][0].update(box=[0,0,0,20]),
|
|
72
|
+
lambda w:w["samples"][0].update(box=[True,0,20,20]),
|
|
73
|
+
lambda w:w["samples"][0].update(jpeg="unhashed alternate pixels"),
|
|
74
|
+
lambda w:w.update(observedFrames=8),
|
|
75
|
+
lambda w:w.update(usable=False),
|
|
76
|
+
lambda w:w.update(currentFrameId="missing_anchor"),
|
|
77
|
+
lambda w:w.update(currentCapturedAtMs=5500),
|
|
78
|
+
lambda w:w["contract"].update(frames=65),
|
|
79
|
+
lambda w:w["contract"].update(toleranceMs=251),
|
|
80
|
+
lambda w:w["contract"].update(extraOption=True),
|
|
81
|
+
lambda w:w["samples"][0].update(state="unobservable",reason="invented"),
|
|
82
|
+
]
|
|
83
|
+
for mutate in mutations:
|
|
84
|
+
body,window=fixture();mutate(window)
|
|
85
|
+
with self.subTest(mutation=repr(window)),self.assertRaises(ValueError):self.parse(replace_window(body,window))
|
|
86
|
+
def test_duplicate_actors_images_fields_and_unreferenced_evidence_are_refused(self):
|
|
87
|
+
mutations=[
|
|
88
|
+
lambda b:b["windows"].append(copy.deepcopy(b["windows"][0])),
|
|
89
|
+
lambda b:b["images"].append(copy.deepcopy(b["images"][0])),
|
|
90
|
+
lambda b:b["fields"].append("phone_use"),
|
|
91
|
+
lambda b:b["fields"].append("unknown field"),
|
|
92
|
+
lambda b:b["model"].update(sha256="bad"),
|
|
93
|
+
lambda b:b.update(extra=True),
|
|
94
|
+
lambda b:b["images"].append({"sha256":digest(b"other"),"jpeg":base64.b64encode(b"other").decode()}),
|
|
95
|
+
lambda b:b.update(images=[]),
|
|
96
|
+
]
|
|
97
|
+
for mutate in mutations:
|
|
98
|
+
body,_=fixture();mutate(body)
|
|
99
|
+
with self.subTest(body=body),self.assertRaises(ValueError):self.parse(body)
|
|
100
|
+
def test_json_duplicate_keys_and_nonfinite_values_are_refused(self):
|
|
101
|
+
for raw in [b'{"version":1,"version":1}',b'{"version":NaN}',b'{"version":Infinity}']:
|
|
102
|
+
with self.subTest(raw=raw),self.assertRaises(ValueError):parse_actor_action_request(raw)
|
|
103
|
+
if __name__=="__main__":unittest.main()
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Task contracts and actual RGB preprocessing for causal actor action inference."""
|
|
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","PIL","cv2"] if importlib.util.find_spec(name) is None]
|
|
7
|
+
if _missing:
|
|
8
|
+
raise unittest.SkipTest("detector[cpu] dependencies absent: "+", ".join(_missing))
|
|
9
|
+
import dataclasses,hashlib,io,unittest
|
|
10
|
+
import numpy as np
|
|
11
|
+
from PIL import Image
|
|
12
|
+
from trillboards_detector.actor_action_contract import ActorActionModelContract,ActorActionOutput,ActorActionWindowContract,CONTACT_PREPROCESSING
|
|
13
|
+
from trillboards_detector.actor_actions import prepare_action_window,action_readings
|
|
14
|
+
from trillboards_detector.actor_action_wire import parse_actor_action_request
|
|
15
|
+
from trillboards_detector.registry import TaskModelContract
|
|
16
|
+
from trillboards_detector.tasks import COCO17
|
|
17
|
+
if __package__:
|
|
18
|
+
from .test_actor_action_wire import fixture,replace_window,packed
|
|
19
|
+
else:
|
|
20
|
+
from test_actor_action_wire import fixture,replace_window,packed
|
|
21
|
+
|
|
22
|
+
def contract(**changes):
|
|
23
|
+
fields={"model_name":"phone_action_test","task":"actor_actions","sha256":"e"*64,
|
|
24
|
+
"approx_ram_bytes":512*1024**2,"preprocessing":CONTACT_PREPROCESSING,
|
|
25
|
+
"outputs":(ActorActionOutput("phone_use",-.5,.5),),"window":ActorActionWindowContract(),
|
|
26
|
+
"requires_pose":True}
|
|
27
|
+
fields.update(changes);return ActorActionModelContract(**fields)
|
|
28
|
+
def original():
|
|
29
|
+
body,window=fixture()
|
|
30
|
+
joints=[{"name":n,"x":100.,"y":80. if i<5 else 160.,"response":.8} for i,n in enumerate(COCO17)]
|
|
31
|
+
for sample in window["samples"]:sample["joints"]=joints
|
|
32
|
+
batch=parse_actor_action_request(packed(replace_window(body,window)).encode())
|
|
33
|
+
return batch
|
|
34
|
+
class ActorActionModelContractTest(unittest.TestCase):
|
|
35
|
+
def test_actions_are_a_distinct_non_box_task_with_an_immutable_input_and_output_contract(self):
|
|
36
|
+
c=contract()
|
|
37
|
+
self.assertIsInstance(c,TaskModelContract);self.assertEqual(c.task,"actor_actions")
|
|
38
|
+
self.assertEqual(c.window.as_dict(),{"version":1,"frames":9,"periodMs":500,"toleranceMs":100,"maxGapMs":1000,"minObservedFrames":3})
|
|
39
|
+
self.assertEqual(c.outputs[0].field,"phone_use")
|
|
40
|
+
with self.assertRaises(ValueError):TaskModelContract("bad","actor_actions","e"*64,1,CONTACT_PREPROCESSING)
|
|
41
|
+
def test_invalid_thresholds_fields_shapes_and_unknown_preprocessing_are_refused(self):
|
|
42
|
+
for args in [("bad field",0,1),("phone_use",1,1),("phone_use",2,1),("phone_use",False,1),("phone_use",0,float("inf"))]:
|
|
43
|
+
with self.subTest(args=args),self.assertRaises(ValueError):ActorActionOutput(*args)
|
|
44
|
+
for changes in [{"task":"pose_coco17"},{"outputs":()},{"outputs":(ActorActionOutput("phone_use",0,1),)*2},
|
|
45
|
+
{"preprocessing":"unknown_recipe"},{"requires_pose":1},{"window":ActorActionWindowContract(frames=8)},
|
|
46
|
+
{"window":ActorActionWindowContract(period_ms=1000)}]:
|
|
47
|
+
with self.subTest(changes=changes),self.assertRaises(ValueError):contract(**changes)
|
|
48
|
+
def test_model_window_contract_rejects_fabrication_and_unbounded_history(self):
|
|
49
|
+
for changes in [{"frames":1},{"frames":65},{"period_ms":0},{"tolerance_ms":251},{"max_gap_ms":100},{"min_observed_frames":10}]:
|
|
50
|
+
with self.subTest(changes=changes),self.assertRaises(ValueError):ActorActionWindowContract(**changes)
|
|
51
|
+
class ActorActionInputTest(unittest.TestCase):
|
|
52
|
+
def test_rgb_order_causal_axes_and_contact_quadrants_come_from_actual_original_jpegs(self):
|
|
53
|
+
batch=original();x,reason=prepare_action_window(batch.windows[0],batch.images,contract())
|
|
54
|
+
self.assertIsNone(reason);self.assertEqual(x.shape,(1,3,9,224,224));self.assertEqual(x.dtype,np.float32)
|
|
55
|
+
self.assertTrue(np.isfinite(x).all());self.assertGreater(x[0,0,0,56,56],x[0,2,0,56,56])
|
|
56
|
+
# Every slot in this actual static-scene fixture has its own capture identity.
|
|
57
|
+
np.testing.assert_array_equal(x[:,:,0],x[:,:,8])
|
|
58
|
+
# All head/wrist views are populated; black unavailable tiles are distinguishable.
|
|
59
|
+
self.assertTrue(all(x[0,0,0,y,xp]>0 for y,xp in [(56,56),(56,168),(168,56),(168,168)]))
|
|
60
|
+
def test_missing_slots_keep_black_masks_and_insufficient_history_does_not_run_a_model(self):
|
|
61
|
+
body,window=fixture();joints=original().windows[0].data["samples"][0]["joints"]
|
|
62
|
+
for sample in window["samples"]:sample["joints"]=joints
|
|
63
|
+
for i in range(6):window["samples"][i]={"state":"unobservable","slotAtMs":1000+i*500,"reason":"not_captured"}
|
|
64
|
+
window["observedFrames"]=3;window["usable"]=True
|
|
65
|
+
batch=parse_actor_action_request(packed(replace_window(body,window)).encode())
|
|
66
|
+
tensor,reason=prepare_action_window(batch.windows[0],batch.images,contract());self.assertIsNone(reason)
|
|
67
|
+
np.testing.assert_allclose(tensor[:,:,0],np.float32(-114.75/57.38),atol=1e-6)
|
|
68
|
+
window["samples"][6]={"state":"unobservable","slotAtMs":4000,"reason":"actor_unobserved"}
|
|
69
|
+
window["observedFrames"]=2;window["usable"]=False
|
|
70
|
+
batch=parse_actor_action_request(packed(replace_window(body,window)).encode())
|
|
71
|
+
tensor,reason=prepare_action_window(batch.windows[0],batch.images,contract())
|
|
72
|
+
self.assertIsNone(tensor);self.assertEqual(reason,"insufficient_history")
|
|
73
|
+
def test_missing_pose_is_explicit_and_an_off_camera_box_or_changed_recipe_is_refused(self):
|
|
74
|
+
body,window=fixture();batch=parse_actor_action_request(packed(body).encode())
|
|
75
|
+
tensor,reason=prepare_action_window(batch.windows[0],batch.images,contract())
|
|
76
|
+
self.assertIsNone(tensor);self.assertEqual(reason,"pose_unavailable")
|
|
77
|
+
window["samples"][0]["box"][2]=500;window["samples"][0]["joints"]=original().windows[0].data["samples"][0]["joints"]
|
|
78
|
+
for sample in window["samples"][1:]:sample["joints"]=window["samples"][0]["joints"]
|
|
79
|
+
batch=parse_actor_action_request(packed(replace_window(body,window)).encode())
|
|
80
|
+
with self.assertRaises(ValueError):prepare_action_window(batch.windows[0],batch.images,contract())
|
|
81
|
+
batch=original()
|
|
82
|
+
with self.assertRaises(ValueError):prepare_action_window(batch.windows[0],batch.images,contract(window=ActorActionWindowContract(tolerance_ms=50)))
|
|
83
|
+
def test_pixels_are_reverified_at_the_model_boundary(self):
|
|
84
|
+
batch=original();changed={key:b"changed" for key in batch.images}
|
|
85
|
+
with self.assertRaises(ValueError):prepare_action_window(batch.windows[0],changed,contract())
|
|
86
|
+
def test_an_uncertain_logit_is_neither_an_absent_action_nor_a_detector_failure(self):
|
|
87
|
+
for value,state,reason in [(-1.,"absent",None),(0.,"unobservable","model_uncertain"),(1.,"present",None)]:
|
|
88
|
+
readings,scores=action_readings(np.array([value],np.float32),contract(),("phone_use",))
|
|
89
|
+
self.assertEqual(readings,{"phone_use":{"state":state,"reason":reason}})
|
|
90
|
+
self.assertEqual(scores,{"phone_use":value})
|
|
91
|
+
for value in [np.array([np.nan]),np.array([np.inf]),np.array([[0.]]),np.array([0.,1.])]:
|
|
92
|
+
with self.subTest(value=value),self.assertRaises(ValueError):action_readings(value,contract(),("phone_use",))
|
|
93
|
+
with self.assertRaises(ValueError):action_readings(np.array([0.],np.float32),contract(),("theft",))
|
|
94
|
+
if __name__=="__main__":unittest.main()
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""A bounded replay log cannot replace the live state of a long-lived weak detection."""
|
|
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","trackers"] if importlib.util.find_spec(name) is None]
|
|
7
|
+
if _missing:
|
|
8
|
+
raise unittest.SkipTest("detector[cpu] dependencies absent: "+", ".join(_missing))
|
|
9
|
+
import tempfile,unittest
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from trillboards_detector.actor_tracking import ActorTrackerJournal
|
|
12
|
+
from trillboards_detector.detections import Detection
|
|
13
|
+
class DurableWeakActorTest(unittest.TestCase):
|
|
14
|
+
def test_restart_preserves_actor_after_its_strong_birth_has_left_the_replay_window(self):
|
|
15
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
16
|
+
path=Path(directory)/'tracker.sqlite3'
|
|
17
|
+
journal=ActorTrackerJournal(path,retained_frames=32)
|
|
18
|
+
def update(at,score):
|
|
19
|
+
return journal.track({'version':1,'cameraId':'camera','sourceId':'source','frameId':'f_'+str(at),'capturedAtMs':at},
|
|
20
|
+
[Detection('person',score,10.,20.,40.,100.)],image_sha256='a'*64,
|
|
21
|
+
model_hashes={'rfdetr_medium':'b'*64},frame_size=(640,480))
|
|
22
|
+
try:
|
|
23
|
+
update(1000,.95);actor=update(1200,.95)['actors'][0]['actor']
|
|
24
|
+
for at in range(1400,14400,200):
|
|
25
|
+
self.assertEqual(update(at,.3)['actors'][0]['actor'],actor)
|
|
26
|
+
self.assertEqual(journal.retained_frames('camera'),32)
|
|
27
|
+
journal.close();journal=ActorTrackerJournal(path,retained_frames=32)
|
|
28
|
+
restored=update(14400,.3)
|
|
29
|
+
self.assertEqual(restored['continuity'],'continued')
|
|
30
|
+
self.assertEqual(restored['actors'][0]['actor'],actor)
|
|
31
|
+
finally:journal.close()
|
|
32
|
+
|
|
33
|
+
class CheckpointIntegrityTest(unittest.TestCase):
|
|
34
|
+
def setUp(self):
|
|
35
|
+
self.directory=tempfile.TemporaryDirectory();self.path=Path(self.directory.name)/"tracker.sqlite3"
|
|
36
|
+
self.journal=ActorTrackerJournal(self.path,retained_frames=32)
|
|
37
|
+
def tearDown(self):
|
|
38
|
+
self.journal.close();self.directory.cleanup()
|
|
39
|
+
def step(self,at,confidence=.95,camera="camera",x=10.,detections=True):
|
|
40
|
+
return self.journal.track({"version":1,"cameraId":camera,"sourceId":"source","frameId":"f_"+str(at),"capturedAtMs":at},
|
|
41
|
+
[Detection("person",confidence,x,20.,40.,100.)] if detections else [],image_sha256="a"*64,
|
|
42
|
+
model_hashes={"rfdetr_medium":"b"*64},frame_size=(640,480))
|
|
43
|
+
def test_restored_filter_matches_uninterrupted_irregular_motion_after_occlusion(self):
|
|
44
|
+
import sqlite3,numpy as np
|
|
45
|
+
self.step(1000);self.step(1200)
|
|
46
|
+
self.step(1475,.3,x=12.);self.step(1925,detections=False)
|
|
47
|
+
copy_path=Path(self.directory.name)/"copy.sqlite3"
|
|
48
|
+
copy_db=sqlite3.connect(copy_path);self.journal._db.backup(copy_db);copy_db.close()
|
|
49
|
+
expected=self.step(2190,.3,x=14.)
|
|
50
|
+
restored=ActorTrackerJournal(copy_path,retained_frames=32)
|
|
51
|
+
try:
|
|
52
|
+
actual=restored.track({"version":1,"cameraId":"camera","sourceId":"source","frameId":"f_2190","capturedAtMs":2190},
|
|
53
|
+
[Detection("person",.3,14.,20.,40.,100.)],image_sha256="a"*64,
|
|
54
|
+
model_hashes={"rfdetr_medium":"b"*64},frame_size=(640,480))
|
|
55
|
+
self.assertEqual(actual,expected)
|
|
56
|
+
a=self.journal._cache["camera"][1].tracks[0].state_estimator.get_state()
|
|
57
|
+
b=restored._cache["camera"][1].tracks[0].state_estimator.get_state()
|
|
58
|
+
for key in a:np.testing.assert_allclose(a[key],b[key],rtol=0,atol=1e-12)
|
|
59
|
+
finally:restored.close()
|
|
60
|
+
def test_checkpoint_write_failure_rolls_back_frame_head_and_memory(self):
|
|
61
|
+
import sqlite3
|
|
62
|
+
self.step(1000);actor=self.step(1200)["actors"][0]["actor"]
|
|
63
|
+
before=self.journal._db.execute("SELECT payload_json FROM actor_checkpoint").fetchone()[0]
|
|
64
|
+
self.journal._db.execute("CREATE TRIGGER fail_checkpoint BEFORE UPDATE ON actor_checkpoint BEGIN SELECT RAISE(FAIL,'simulated storage failure'); END")
|
|
65
|
+
with self.assertRaises(sqlite3.IntegrityError):self.step(1400,.3,x=12.)
|
|
66
|
+
self.assertEqual(self.journal._db.execute("SELECT captured_at FROM actor_camera").fetchone()[0],1200)
|
|
67
|
+
self.assertEqual(self.journal._db.execute("SELECT count(*) FROM actor_frame WHERE frame_id='f_1400'").fetchone()[0],0)
|
|
68
|
+
self.assertEqual(self.journal._db.execute("SELECT payload_json FROM actor_checkpoint").fetchone()[0],before)
|
|
69
|
+
self.journal._db.execute("DROP TRIGGER fail_checkpoint")
|
|
70
|
+
self.assertEqual(self.step(1400,.3,x=12.)["actors"][0]["actor"],actor)
|
|
71
|
+
def test_valid_checkpoint_from_another_camera_cannot_restore_actor_identity(self):
|
|
72
|
+
from trillboards_detector.actor_tracking import TrackingError
|
|
73
|
+
self.step(1000);self.step(1200)
|
|
74
|
+
self.step(1000,camera="other");self.step(1200,camera="other")
|
|
75
|
+
self.journal._db.execute("UPDATE actor_checkpoint SET payload_json=(SELECT payload_json FROM actor_checkpoint WHERE camera_id='other') WHERE camera_id='camera'")
|
|
76
|
+
self.journal.close();self.journal=ActorTrackerJournal(self.path,retained_frames=32)
|
|
77
|
+
with self.assertRaisesRegex(TrackingError,"Corrupt"):self.step(1400,.3)
|
|
78
|
+
def test_restart_preserves_a_tentative_track_before_confirmation(self):
|
|
79
|
+
self.assertEqual(self.step(1000)["actors"],[])
|
|
80
|
+
self.journal.close();self.journal=ActorTrackerJournal(self.path,retained_frames=32)
|
|
81
|
+
self.assertEqual(len(self.step(1200)["actors"]),1)
|
|
82
|
+
|
|
83
|
+
def test_legacy_replay_without_a_birth_reports_reset_instead_of_silent_continuity(self):
|
|
84
|
+
self.step(1000);old=self.step(1200)["actors"][0]["actor"]
|
|
85
|
+
for at in range(1400,14400,200):self.step(at,.3)
|
|
86
|
+
self.journal._db.execute("DELETE FROM actor_checkpoint")
|
|
87
|
+
self.journal.close();self.journal=ActorTrackerJournal(self.path,retained_frames=32)
|
|
88
|
+
recovered=self.step(14400,.3)
|
|
89
|
+
self.assertEqual(recovered["continuity"],"recovery_reset")
|
|
90
|
+
self.assertNotEqual(recovered["epoch"],old["epoch"])
|
|
91
|
+
self.assertIn(old,recovered["endedActors"])
|
|
92
|
+
self.assertEqual(recovered["actors"],[])
|
|
93
|
+
def test_legacy_complete_replay_keeps_its_proven_actor_identity(self):
|
|
94
|
+
self.step(1000);actor=self.step(1200)["actors"][0]["actor"]
|
|
95
|
+
self.journal._db.execute("DELETE FROM actor_checkpoint")
|
|
96
|
+
self.journal.close();self.journal=ActorTrackerJournal(self.path,retained_frames=32)
|
|
97
|
+
recovered=self.step(1400,.3)
|
|
98
|
+
self.assertEqual(recovered["continuity"],"continued")
|
|
99
|
+
self.assertEqual(recovered["actors"][0]["actor"],actor)
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""Exercise the real pinned tracker and durable store, without model stubs."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import importlib.util
|
|
5
|
+
import unittest
|
|
6
|
+
# The dependency-free wire lane has no numerical packages. The mandatory CPU
|
|
7
|
+
# SDK lane installs detector[cpu] and executes these real numerical tests.
|
|
8
|
+
_missing=[name for name in ["numpy","trackers"] if importlib.util.find_spec(name) is None]
|
|
9
|
+
if _missing:
|
|
10
|
+
raise unittest.SkipTest("detector[cpu] dependencies absent: "+", ".join(_missing))
|
|
11
|
+
import copy
|
|
12
|
+
import tempfile
|
|
13
|
+
import unittest
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
from trillboards_detector.actor_tracking import ActorTrackerJournal, TrackingError
|
|
17
|
+
from trillboards_detector.detections import Detection
|
|
18
|
+
|
|
19
|
+
SHA = "a" * 64
|
|
20
|
+
MODEL = {"rfdetr_medium": "b" * 64}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def request(at, camera="cam_a", source="source_a", frame=None):
|
|
24
|
+
return {"version": 1, "cameraId": camera, "sourceId": source,
|
|
25
|
+
"frameId": frame or f"frame_{at}", "capturedAtMs": at}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def person(x=10, confidence=.95):
|
|
29
|
+
return Detection("person", confidence, x, 20, 40, 100)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ActorTrackingTest(unittest.TestCase):
|
|
33
|
+
def setUp(self):
|
|
34
|
+
self.directory = tempfile.TemporaryDirectory()
|
|
35
|
+
self.path = Path(self.directory.name) / "tracks.sqlite3"
|
|
36
|
+
self.journal = ActorTrackerJournal(self.path)
|
|
37
|
+
|
|
38
|
+
def tearDown(self):
|
|
39
|
+
self.journal.close()
|
|
40
|
+
self.directory.cleanup()
|
|
41
|
+
|
|
42
|
+
def track(self, at, detections=None, **kwargs):
|
|
43
|
+
return self.journal.track(request(at, **kwargs), detections if detections is not None else [person()],
|
|
44
|
+
image_sha256=SHA, model_hashes=MODEL, frame_size=(640, 480))
|
|
45
|
+
|
|
46
|
+
def confirmed(self, at=1000, **kwargs):
|
|
47
|
+
self.track(at, **kwargs)
|
|
48
|
+
return self.track(at+200, **kwargs)["actors"][0]["actor"]
|
|
49
|
+
|
|
50
|
+
def test_confirms_observed_person_without_inventing_a_first_observation(self):
|
|
51
|
+
first = self.track(1000)
|
|
52
|
+
self.assertEqual(first["actors"], [])
|
|
53
|
+
self.assertEqual(first["unconfirmed"], [0])
|
|
54
|
+
second = self.track(1200)
|
|
55
|
+
self.assertEqual(second["actors"][0]["detectionIndex"], 0)
|
|
56
|
+
actor = second["actors"][0]["actor"]
|
|
57
|
+
self.assertEqual(actor["kind"], "person")
|
|
58
|
+
self.assertEqual(actor["cameraId"], "cam_a")
|
|
59
|
+
self.assertEqual(actor["epoch"], second["epoch"])
|
|
60
|
+
|
|
61
|
+
def test_detection_order_is_not_track_identity(self):
|
|
62
|
+
self.track(1000, [person(10), person(200)])
|
|
63
|
+
second = self.track(1200, [person(12), person(198)])
|
|
64
|
+
third = self.track(1400, [person(196), person(14)])
|
|
65
|
+
ids = {a["detectionIndex"]: a["actor"]["id"] for a in second["actors"]}
|
|
66
|
+
reversed_ids = {a["detectionIndex"]: a["actor"]["id"] for a in third["actors"]}
|
|
67
|
+
self.assertEqual(ids[0], reversed_ids[1])
|
|
68
|
+
self.assertEqual(ids[1], reversed_ids[0])
|
|
69
|
+
self.assertNotEqual(ids[0], ids[1])
|
|
70
|
+
|
|
71
|
+
def test_short_occlusion_preserves_identity_but_is_not_a_detection(self):
|
|
72
|
+
who = self.confirmed()
|
|
73
|
+
hidden = self.track(1400, [])
|
|
74
|
+
self.assertEqual(hidden["actors"], [])
|
|
75
|
+
self.assertEqual(hidden["endedActors"], [])
|
|
76
|
+
self.assertEqual(self.track(1600)["actors"][0]["actor"], who)
|
|
77
|
+
|
|
78
|
+
def test_low_confidence_match_can_continue_but_cannot_birth_a_track(self):
|
|
79
|
+
self.assertEqual(self.track(1000, [person(confidence=.3)])["actors"], [])
|
|
80
|
+
self.track(1200)
|
|
81
|
+
who = self.track(1400)["actors"][0]["actor"]
|
|
82
|
+
self.assertEqual(self.track(1600, [person(confidence=.3)])["actors"][0]["actor"], who)
|
|
83
|
+
|
|
84
|
+
def test_other_cameras_and_source_changes_cannot_share_actors(self):
|
|
85
|
+
a = self.confirmed()
|
|
86
|
+
b = self.confirmed(camera="cam_b")
|
|
87
|
+
self.assertNotEqual(a["id"], b["id"])
|
|
88
|
+
self.assertNotEqual(a["epoch"], b["epoch"])
|
|
89
|
+
c = self.confirmed(at=2000, source="source_b")
|
|
90
|
+
self.assertNotEqual(a["epoch"], c["epoch"])
|
|
91
|
+
self.assertNotEqual(a["id"], c["id"])
|
|
92
|
+
|
|
93
|
+
def test_restart_and_bounded_history_preserve_actor(self):
|
|
94
|
+
who = self.confirmed()
|
|
95
|
+
for at in range(1400, 62000, 200):
|
|
96
|
+
self.track(at)
|
|
97
|
+
self.journal.close()
|
|
98
|
+
self.journal = ActorTrackerJournal(self.path)
|
|
99
|
+
self.assertEqual(self.track(62000)["actors"][0]["actor"], who)
|
|
100
|
+
self.assertLessEqual(self.journal.retained_frames("cam_a"), 256)
|
|
101
|
+
|
|
102
|
+
def test_same_frame_retry_is_exact_after_restart(self):
|
|
103
|
+
self.track(1000)
|
|
104
|
+
original = self.track(1200)
|
|
105
|
+
self.journal.close()
|
|
106
|
+
self.journal = ActorTrackerJournal(self.path)
|
|
107
|
+
self.assertEqual(self.track(1200), original)
|
|
108
|
+
with self.assertRaisesRegex(TrackingError, "identity"):
|
|
109
|
+
self.track(1200, [person(20)])
|
|
110
|
+
|
|
111
|
+
def test_late_or_same_time_different_frames_cannot_reorder_state(self):
|
|
112
|
+
self.confirmed()
|
|
113
|
+
for at in (1100, 1200):
|
|
114
|
+
with self.assertRaisesRegex(TrackingError, "order"):
|
|
115
|
+
self.track(at, frame="different")
|
|
116
|
+
self.assertEqual(len(self.track(1400)["actors"]), 1)
|
|
117
|
+
|
|
118
|
+
def test_long_capture_gap_and_model_change_end_prior_identity(self):
|
|
119
|
+
who = self.confirmed()
|
|
120
|
+
reset = self.track(10000)
|
|
121
|
+
self.assertEqual(reset["continuity"], "gap_reset")
|
|
122
|
+
self.assertIn(who, reset["endedActors"])
|
|
123
|
+
self.assertNotEqual(reset["epoch"], who["epoch"])
|
|
124
|
+
changed = self.journal.track(request(10200), [person()], image_sha256=SHA,
|
|
125
|
+
model_hashes={"rfdetr_medium": "c"*64}, frame_size=(640, 480))
|
|
126
|
+
self.assertEqual(changed["continuity"], "context_reset")
|
|
127
|
+
self.assertEqual(changed["actors"], [])
|
|
128
|
+
|
|
129
|
+
def test_no_cross_camera_reset_or_id_recycling(self):
|
|
130
|
+
a = self.confirmed()
|
|
131
|
+
self.confirmed(camera="cam_b")
|
|
132
|
+
self.track(1400, camera="cam_b", source="new_source")
|
|
133
|
+
self.assertEqual(self.track(1400)["actors"][0]["actor"], a)
|
|
134
|
+
|
|
135
|
+
def test_rejects_ambiguous_identity_and_invalid_boxes_without_mutation(self):
|
|
136
|
+
bad = [None, {}, {**request(1000), "capturedAtMs": True},
|
|
137
|
+
{**request(1000), "cameraId": 123}, {**request(1000), "extra": 1}]
|
|
138
|
+
for value in bad:
|
|
139
|
+
with self.assertRaises(TrackingError):
|
|
140
|
+
self.journal.track(value, [person()], image_sha256=SHA, model_hashes=MODEL, frame_size=(640,480))
|
|
141
|
+
with self.assertRaises(TrackingError):
|
|
142
|
+
self.track(1000, [person(float("nan"))])
|
|
143
|
+
self.assertEqual(self.track(1000)["continuity"], "start")
|
|
144
|
+
|
|
145
|
+
def test_camera_capacity_is_a_visible_error_and_does_not_evict_live_state(self):
|
|
146
|
+
other = ActorTrackerJournal(Path(self.directory.name) / "small.sqlite3", max_cameras=1)
|
|
147
|
+
try:
|
|
148
|
+
other.track(request(1000), [person()], image_sha256=SHA, model_hashes=MODEL, frame_size=(640,480))
|
|
149
|
+
with self.assertRaisesRegex(TrackingError, "capacity"):
|
|
150
|
+
other.track(request(1000, camera="cam_b"), [person()], image_sha256=SHA, model_hashes=MODEL, frame_size=(640,480))
|
|
151
|
+
self.assertEqual(len(other.track(request(1200), [person()], image_sha256=SHA,
|
|
152
|
+
model_hashes=MODEL, frame_size=(640,480))["actors"]), 1)
|
|
153
|
+
finally:
|
|
154
|
+
other.close()
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_corrupt_saved_result_is_not_an_idempotent_success(self):
|
|
158
|
+
import sqlite3, json
|
|
159
|
+
self.confirmed()
|
|
160
|
+
with sqlite3.connect(self.path) as db:
|
|
161
|
+
saved = json.loads(db.execute("SELECT result_json FROM actor_frame WHERE frame_id='frame_1200'").fetchone()[0])
|
|
162
|
+
saved["actors"][0]["actor"]["id"] = "different_person"
|
|
163
|
+
db.execute("UPDATE actor_frame SET result_json=? WHERE frame_id='frame_1200'", (json.dumps(saved),))
|
|
164
|
+
with self.assertRaisesRegex(TrackingError, "Corrupt"):
|
|
165
|
+
self.track(1200)
|
|
166
|
+
|
|
167
|
+
def test_corrupt_replay_input_cannot_restore_an_actor(self):
|
|
168
|
+
import sqlite3, json
|
|
169
|
+
self.confirmed()
|
|
170
|
+
self.journal.close()
|
|
171
|
+
with sqlite3.connect(self.path) as db:
|
|
172
|
+
saved = json.loads(db.execute("SELECT input_json FROM actor_frame WHERE frame_id='frame_1200'").fetchone()[0])
|
|
173
|
+
saved["detections"][0]["x"] += 20
|
|
174
|
+
db.execute("UPDATE actor_frame SET input_json=? WHERE frame_id='frame_1200'", (json.dumps(saved),))
|
|
175
|
+
self.journal = ActorTrackerJournal(self.path)
|
|
176
|
+
with self.assertRaisesRegex(TrackingError, "Corrupt"):
|
|
177
|
+
self.track(1400)
|
|
178
|
+
|
|
179
|
+
def test_corrupt_camera_head_cannot_end_an_unrelated_actor(self):
|
|
180
|
+
import sqlite3, json
|
|
181
|
+
self.confirmed()
|
|
182
|
+
with sqlite3.connect(self.path) as db:
|
|
183
|
+
active = json.loads(db.execute("SELECT active_json FROM actor_camera").fetchone()[0])
|
|
184
|
+
active[0]["cameraId"] = "another_camera"
|
|
185
|
+
db.execute("UPDATE actor_camera SET active_json=?", (json.dumps(active),))
|
|
186
|
+
with self.assertRaisesRegex(TrackingError, "Corrupt"):
|
|
187
|
+
self.track(1400)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
if __name__ == "__main__":
|
|
191
|
+
unittest.main()
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Real HTTP + ByteTrack + SQLite. Fixtures exercise transport, not model accuracy."""
|
|
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","trackers"] if importlib.util.find_spec(name) is None]
|
|
6
|
+
if _missing:
|
|
7
|
+
raise unittest.SkipTest("detector[cpu] dependencies absent: "+", ".join(_missing))
|
|
8
|
+
import base64
|
|
9
|
+
import io
|
|
10
|
+
import json
|
|
11
|
+
import tempfile
|
|
12
|
+
import threading
|
|
13
|
+
import unittest
|
|
14
|
+
import urllib.request
|
|
15
|
+
import urllib.error
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from PIL import Image
|
|
19
|
+
from trillboards_detector.actor_tracking import ActorTrackerJournal
|
|
20
|
+
from trillboards_detector.detections import Detection, DetectionBatch
|
|
21
|
+
from trillboards_detector.server import DetectorServer
|
|
22
|
+
|
|
23
|
+
SHA = "b"*64
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class StaticDetectionSource:
|
|
27
|
+
"""Exact detections are the input under test; inference is qualified separately."""
|
|
28
|
+
state = "ready"
|
|
29
|
+
def info(self):
|
|
30
|
+
return {"state": "ready"}
|
|
31
|
+
def resolve_classes(self, classes):
|
|
32
|
+
return set(classes)
|
|
33
|
+
def detect(self, jpeg, min_confidence, wanted, *, expected_model=None):
|
|
34
|
+
if expected_model != {"modelId":"rfdetr_medium","sha256":SHA}:
|
|
35
|
+
raise ValueError("unexpected selected artifact")
|
|
36
|
+
return DetectionBatch([Detection("person", .95, 10, 20, 30, 80)],
|
|
37
|
+
models=["rfdetr_medium"], model_hashes={"rfdetr_medium": SHA})
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ActorTrackingWireTest(unittest.TestCase):
|
|
41
|
+
def setUp(self):
|
|
42
|
+
self.tmp = tempfile.TemporaryDirectory()
|
|
43
|
+
self.store = ActorTrackerJournal(Path(self.tmp.name)/"actors.sqlite3")
|
|
44
|
+
self.server = DetectorServer(("127.0.0.1", 0), StaticDetectionSource(),
|
|
45
|
+
log_line=lambda _: None, actor_tracker=self.store)
|
|
46
|
+
self.worker = threading.Thread(target=lambda:self.server.serve_forever(poll_interval=.01), daemon=True)
|
|
47
|
+
self.worker.start()
|
|
48
|
+
self.base = "http://127.0.0.1:"+str(self.server.server_port)
|
|
49
|
+
out = io.BytesIO()
|
|
50
|
+
Image.new("RGB",(160,120),"white").save(out,format="JPEG")
|
|
51
|
+
self.jpeg = out.getvalue()
|
|
52
|
+
|
|
53
|
+
def tearDown(self):
|
|
54
|
+
self.server.shutdown()
|
|
55
|
+
self.server.server_close()
|
|
56
|
+
self.worker.join()
|
|
57
|
+
self.store.close()
|
|
58
|
+
self.tmp.cleanup()
|
|
59
|
+
|
|
60
|
+
def post(self, at, **changes):
|
|
61
|
+
body = {"image_b64":base64.b64encode(self.jpeg).decode(), "classes":["person"],
|
|
62
|
+
"expected_model":{"modelId":"rfdetr_medium","sha256":SHA},
|
|
63
|
+
"tracking":{"version":1,"cameraId":"cam_a","sourceId":"source_a",
|
|
64
|
+
"frameId":"frame_"+str(at),"capturedAtMs":at}, **changes}
|
|
65
|
+
request=urllib.request.Request(self.base+"/detect", data=json.dumps(body).encode(),
|
|
66
|
+
headers={"Content-Type":"application/json"})
|
|
67
|
+
try:
|
|
68
|
+
with urllib.request.urlopen(request,timeout=5) as r:
|
|
69
|
+
return r.status,json.load(r)
|
|
70
|
+
except urllib.error.HTTPError as e:
|
|
71
|
+
return e.code,json.load(e)
|
|
72
|
+
|
|
73
|
+
def test_actual_wire_confirms_actor_and_retries_with_identical_proof(self):
|
|
74
|
+
status,first=self.post(1000)
|
|
75
|
+
self.assertEqual(status,200)
|
|
76
|
+
self.assertEqual(first["tracking"]["unconfirmed"],[0])
|
|
77
|
+
status,second=self.post(1200)
|
|
78
|
+
self.assertEqual(status,200)
|
|
79
|
+
self.assertEqual(second["tracking"]["actors"][0]["actor"]["cameraId"],"cam_a")
|
|
80
|
+
self.assertEqual(self.post(1200)[1]["tracking"],second["tracking"])
|
|
81
|
+
with urllib.request.urlopen(self.base+"/health") as r:
|
|
82
|
+
self.assertEqual(json.load(r)["actor_tracking"]["state"],"ready")
|
|
83
|
+
|
|
84
|
+
def test_invalid_or_unavailable_tracking_never_becomes_an_empty_scene(self):
|
|
85
|
+
for change in [{"tracking":{}},{"min_confidence":.5},{"expected_model":None},
|
|
86
|
+
{"classes":["cell phone"]}]:
|
|
87
|
+
status,body=self.post(1000,**change)
|
|
88
|
+
self.assertGreaterEqual(status,400)
|
|
89
|
+
self.assertNotIn("detections",body)
|
|
90
|
+
self.server.actor_tracker=None
|
|
91
|
+
status,body=self.post(1000)
|
|
92
|
+
self.assertEqual(status,503)
|
|
93
|
+
self.assertNotIn("detections",body)
|
|
94
|
+
|
|
95
|
+
def test_pose_task_requires_an_original_actor_frame_and_pinned_task(self):
|
|
96
|
+
pin={"modelId":"rtmpose_m_body7","sha256":"5c0a4bf67953e6d2ac43ce15e77dc9d5d354ae18430a47d2c5963a7bc5683e3c"}
|
|
97
|
+
status,body=self.post(1000,tracking=None,pose_model=pin)
|
|
98
|
+
self.assertEqual(status,400)
|
|
99
|
+
self.assertNotIn("detections",body)
|
|
100
|
+
status,body=self.post(1000,pose_model={**pin,"sha256":"a"*64})
|
|
101
|
+
self.assertEqual(status,409)
|
|
102
|
+
self.assertNotIn("detections",body)
|
|
103
|
+
|
|
104
|
+
def test_unavailable_pose_is_not_silently_omitted(self):
|
|
105
|
+
pin={"modelId":"rtmpose_m_body7","sha256":"5c0a4bf67953e6d2ac43ce15e77dc9d5d354ae18430a47d2c5963a7bc5683e3c"}
|
|
106
|
+
status,body=self.post(1000,pose_model=pin)
|
|
107
|
+
self.assertEqual(status,503)
|
|
108
|
+
self.assertNotIn("detections",body)
|
|
109
|
+
|
|
110
|
+
def test_late_new_frame_is_a_failure_without_advancing_the_actor(self):
|
|
111
|
+
self.post(1000)
|
|
112
|
+
self.post(1200)
|
|
113
|
+
status,body=self.post(1100)
|
|
114
|
+
self.assertEqual(status,500)
|
|
115
|
+
self.assertNotIn("detections",body)
|
|
116
|
+
self.assertEqual(self.post(1400)[0],200)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if __name__ == "__main__":
|
|
120
|
+
unittest.main()
|