@trillboards/edge-sdk 0.2.245 → 0.2.253
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/bench/detect_frames.py +88 -0
- package/deploy/detector/bench/openvino_parity.py +152 -0
- package/deploy/detector/pyproject.toml +10 -1
- package/deploy/detector/tests/test_actor_tracking.py +168 -0
- package/deploy/detector/tests/test_actor_tracking_wire.py +22 -0
- package/deploy/detector/tests/test_loader.py +25 -0
- package/deploy/detector/tests/test_openvino_engines.py +251 -0
- package/deploy/detector/tests/test_registry.py +53 -0
- package/deploy/detector/tests/test_server.py +43 -0
- package/deploy/detector/tests/test_version_stamp.py +17 -4
- package/deploy/detector/trillboards_detector/_version.py +2 -2
- package/deploy/detector/trillboards_detector/actor_tracking.py +139 -2
- package/deploy/detector/trillboards_detector/cli.py +5 -0
- package/deploy/detector/trillboards_detector/detections.py +5 -0
- package/deploy/detector/trillboards_detector/execution.py +386 -0
- package/deploy/detector/trillboards_detector/loader.py +40 -1
- package/deploy/detector/trillboards_detector/registry.py +33 -1
- package/deploy/detector/trillboards_detector/server.py +43 -1
- package/deploy/detector/trillboards_detector/session.py +81 -3
- package/deploy/detector/trillboards_detector/track_records.py +113 -0
- package/deploy/windows/build-windows.ps1 +1 -0
- package/deploy/windows/ci/test-detector-looks-field.ps1 +15 -3
- package/deploy/windows/ci/test-detector-reinstall.ps1 +645 -0
- package/deploy/windows/ci/test-rollout-proofs.ps1 +3 -2
- package/deploy/windows/ensure-detector.ps1 +255 -0
- package/deploy/windows/install-update.ps1 +4 -3
- package/deploy/windows/setup-detector.ps1 +122 -29
- package/deploy/windows/stop-existing.ps1 +1 -0
- package/deploy/windows/trillboards-edge.cmd +10 -22
- package/dist/ActorTracking.d.ts +38 -0
- package/dist/ActorTracking.d.ts.map +1 -1
- package/dist/ActorTracking.js +40 -0
- package/dist/ActorTracking.js.map +1 -1
- package/dist/AlertClips.d.ts +4 -2
- package/dist/AlertClips.d.ts.map +1 -1
- package/dist/AlertClips.js +24 -9
- package/dist/AlertClips.js.map +1 -1
- package/dist/CloudSensingManager.d.ts +9 -0
- package/dist/CloudSensingManager.d.ts.map +1 -1
- package/dist/CloudSensingManager.js +52 -4
- package/dist/CloudSensingManager.js.map +1 -1
- package/dist/ConnectorStatusClient.d.ts +8 -0
- package/dist/ConnectorStatusClient.d.ts.map +1 -1
- package/dist/ConnectorStatusClient.js +3 -0
- package/dist/ConnectorStatusClient.js.map +1 -1
- package/dist/DurableVlmCandidateSpool.d.ts +11 -0
- package/dist/DurableVlmCandidateSpool.d.ts.map +1 -1
- package/dist/DurableVlmCandidateSpool.js +31 -2
- package/dist/DurableVlmCandidateSpool.js.map +1 -1
- package/dist/EdgeAgent.js +1 -1
- package/dist/FrameGroupingShadow.d.ts +57 -0
- package/dist/FrameGroupingShadow.d.ts.map +1 -1
- package/dist/FrameGroupingShadow.js +123 -5
- package/dist/FrameGroupingShadow.js.map +1 -1
- package/dist/LocalDetectorClient.d.ts +44 -1
- package/dist/LocalDetectorClient.d.ts.map +1 -1
- package/dist/LocalDetectorClient.js +88 -4
- package/dist/LocalDetectorClient.js.map +1 -1
- package/dist/LocalVideoBuffer.d.ts +14 -2
- package/dist/LocalVideoBuffer.d.ts.map +1 -1
- package/dist/LocalVideoBuffer.js +23 -3
- package/dist/LocalVideoBuffer.js.map +1 -1
- package/dist/NativeReadiness.d.ts +21 -2
- package/dist/NativeReadiness.d.ts.map +1 -1
- package/dist/NativeReadiness.js +25 -6
- package/dist/NativeReadiness.js.map +1 -1
- package/dist/OrderedReviewClient.d.ts +3 -0
- package/dist/OrderedReviewClient.d.ts.map +1 -1
- package/dist/OrderedReviewClient.js +3 -0
- package/dist/OrderedReviewClient.js.map +1 -1
- package/dist/SensingProfileClient.d.ts.map +1 -1
- package/dist/SensingProfileClient.js +3 -0
- package/dist/SensingProfileClient.js.map +1 -1
- package/dist/TemporalReviewClient.d.ts +3 -0
- package/dist/TemporalReviewClient.d.ts.map +1 -1
- package/dist/TemporalReviewClient.js +3 -0
- package/dist/TemporalReviewClient.js.map +1 -1
- package/dist/VideoSegmentUploader.d.ts +14 -7
- package/dist/VideoSegmentUploader.d.ts.map +1 -1
- package/dist/VideoSegmentUploader.js +34 -38
- package/dist/VideoSegmentUploader.js.map +1 -1
- package/dist/VlmCandidateBuffer.d.ts +13 -0
- package/dist/VlmCandidateBuffer.d.ts.map +1 -1
- package/dist/VlmCandidateBuffer.js.map +1 -1
- package/dist/autoSense.d.ts +4 -0
- package/dist/autoSense.d.ts.map +1 -1
- package/dist/autoSense.js +7 -0
- package/dist/autoSense.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/connectorUpdate.d.ts +18 -9
- package/dist/connectorUpdate.d.ts.map +1 -1
- package/dist/connectorUpdate.js +66 -3
- package/dist/connectorUpdate.js.map +1 -1
- package/dist/connectorUpdateApply.d.ts +20 -1
- package/dist/connectorUpdateApply.d.ts.map +1 -1
- package/dist/connectorUpdateApply.js +55 -1
- package/dist/connectorUpdateApply.js.map +1 -1
- package/dist/connectorUpdateApplyMac.d.ts +3 -1
- package/dist/connectorUpdateApplyMac.d.ts.map +1 -1
- package/dist/connectorUpdateApplyMac.js +6 -0
- package/dist/connectorUpdateApplyMac.js.map +1 -1
- package/dist/continuousReview.d.ts +6 -2
- package/dist/continuousReview.d.ts.map +1 -1
- package/dist/continuousReview.js.map +1 -1
- package/dist/detectorBackendRelay.d.ts +24 -0
- package/dist/detectorBackendRelay.d.ts.map +1 -0
- package/dist/detectorBackendRelay.js +70 -0
- package/dist/detectorBackendRelay.js.map +1 -0
- package/dist/detectorEndpointState.d.ts +30 -0
- package/dist/detectorEndpointState.d.ts.map +1 -0
- package/dist/detectorEndpointState.js +125 -0
- package/dist/detectorEndpointState.js.map +1 -0
- package/dist/detectorLauncher.d.ts +23 -0
- package/dist/detectorLauncher.d.ts.map +1 -0
- package/dist/detectorLauncher.js +94 -0
- package/dist/detectorLauncher.js.map +1 -0
- package/dist/diagnose.d.ts +1 -1
- package/dist/diagnose.js +1 -1
- package/dist/localSensing.d.ts +72 -0
- package/dist/localSensing.d.ts.map +1 -1
- package/dist/localSensing.js +280 -31
- package/dist/localSensing.js.map +1 -1
- package/dist/pipelineSwitches.d.ts +59 -0
- package/dist/pipelineSwitches.d.ts.map +1 -0
- package/dist/pipelineSwitches.js +240 -0
- package/dist/pipelineSwitches.js.map +1 -0
- package/package.json +4 -4
- package/retained/ProfileAuthorityClient.cjs +4 -0
- package/retained/RetainedCaptureClient.cjs +41 -2
- package/retained/WebsiteAdmissionCaptureClient.cjs +57 -2
- package/retained/__tests__/look-reuse.test.cjs +167 -0
- package/retained/manager.cjs +28 -2
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"""Engine policy (plan v7 W8): which engine answers a frame, and when OpenVINO may.
|
|
2
|
+
|
|
3
|
+
Hermetic: fake sessions stand in for ORT and OpenVINO, so the policy is tested
|
|
4
|
+
without a model, a GPU or the openvino wheel. Parity on real frames is measured
|
|
5
|
+
by the bench (`bench/openvino_parity.py`), not here.
|
|
6
|
+
"""
|
|
7
|
+
import importlib.util
|
|
8
|
+
import threading
|
|
9
|
+
import time
|
|
10
|
+
import unittest
|
|
11
|
+
from unittest import mock
|
|
12
|
+
|
|
13
|
+
# guards-fast runs this directory on a bare interpreter (no numpy). The engine
|
|
14
|
+
# policy itself imports no numpy, so TestPolicy runs there; the fake sessions
|
|
15
|
+
# answer numpy arrays, so TestEngines runs in the lanes that install the
|
|
16
|
+
# detector's [cpu] extra.
|
|
17
|
+
HAVE_NUMPY = importlib.util.find_spec("numpy") is not None
|
|
18
|
+
if HAVE_NUMPY:
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
from trillboards_detector import execution
|
|
22
|
+
from trillboards_detector.execution import BackendPolicy, DetectorEngines, EngineUnavailable
|
|
23
|
+
|
|
24
|
+
OUTPUTS = ("dets", "labels")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class FakeSession:
|
|
28
|
+
def __init__(self, name, offset=0.0, fail=False, delay=0.0, precision="f32"):
|
|
29
|
+
self.name, self.offset, self.fail, self.delay, self.precision = name, offset, fail, delay, precision
|
|
30
|
+
self.calls = 0
|
|
31
|
+
self.device_name = name
|
|
32
|
+
|
|
33
|
+
def get_providers(self):
|
|
34
|
+
return [self.name]
|
|
35
|
+
|
|
36
|
+
def run(self, output_names, feeds):
|
|
37
|
+
self.calls += 1
|
|
38
|
+
if self.delay:
|
|
39
|
+
time.sleep(self.delay)
|
|
40
|
+
if self.fail:
|
|
41
|
+
raise RuntimeError("device lost")
|
|
42
|
+
(blob,) = feeds.values()
|
|
43
|
+
value = float(np.asarray(blob).ravel()[0])
|
|
44
|
+
return [np.full((1, 4, 4), value, np.float32), np.full((1, 4, 3), value + self.offset, np.float32)]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def compare(reference, candidate):
|
|
48
|
+
diff = float(np.abs(reference[1] - candidate[1]).max())
|
|
49
|
+
return {"person_diff": diff, "score_diff": diff, "mismatches": 1 if diff > 0.1 else 0}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def engines(mode, factory, probe_frames=3):
|
|
53
|
+
ort = FakeSession("CPUExecutionProvider")
|
|
54
|
+
with mock.patch.object(execution, "openvino_version", return_value="2026.4.1"):
|
|
55
|
+
set_ = DetectorEngines(ort, lambda: b"model", BackendPolicy(mode), compare,
|
|
56
|
+
log=lambda *_: None, session_factory=factory, probe_frames=probe_frames)
|
|
57
|
+
return set_, ort
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def frame(v=1.0):
|
|
61
|
+
return {"input": np.full((1, 3, 2, 2), v, np.float32)}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def wait_built(set_, names=("openvino_cpu", "openvino_gpu"), timeout=5.0):
|
|
65
|
+
deadline = time.time() + timeout
|
|
66
|
+
while time.time() < deadline:
|
|
67
|
+
snap = set_.snapshot()["engines"]
|
|
68
|
+
if all(n in snap for n in names) and not set_._building:
|
|
69
|
+
return snap
|
|
70
|
+
time.sleep(0.01)
|
|
71
|
+
raise AssertionError(f"engines not built: {set_.snapshot()}")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class TestPolicy(unittest.TestCase):
|
|
75
|
+
def test_modes_are_closed(self):
|
|
76
|
+
policy = BackendPolicy()
|
|
77
|
+
self.assertEqual(policy.mode, "ort")
|
|
78
|
+
self.assertTrue(policy.set("openvino"))
|
|
79
|
+
self.assertFalse(policy.set("openvino"))
|
|
80
|
+
with self.assertRaises(ValueError):
|
|
81
|
+
policy.set("tensorrt")
|
|
82
|
+
with self.assertRaises(ValueError):
|
|
83
|
+
BackendPolicy("gpu")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@unittest.skipUnless(HAVE_NUMPY, "numpy is not installed: the fake sessions answer numpy arrays")
|
|
87
|
+
class TestEngines(unittest.TestCase):
|
|
88
|
+
def test_ort_mode_builds_nothing_and_answers_on_ort(self):
|
|
89
|
+
factory = mock.Mock(side_effect=AssertionError("must not build"))
|
|
90
|
+
set_, ort = engines("ort", factory)
|
|
91
|
+
outputs, name = set_.run(OUTPUTS, frame())
|
|
92
|
+
self.assertEqual(name, "ort")
|
|
93
|
+
self.assertEqual(ort.calls, 1)
|
|
94
|
+
self.assertEqual(set_.snapshot()["serving"], ["ort"])
|
|
95
|
+
self.assertEqual(set_.snapshot()["engines"].keys(), {"ort"})
|
|
96
|
+
factory.assert_not_called()
|
|
97
|
+
|
|
98
|
+
def test_openvino_serves_only_after_its_probe_passed(self):
|
|
99
|
+
built = {}
|
|
100
|
+
|
|
101
|
+
def factory(model, device, precision, threads=None):
|
|
102
|
+
built[device] = FakeSession(f"ov-{device}", precision=precision)
|
|
103
|
+
return built[device]
|
|
104
|
+
|
|
105
|
+
set_, ort = engines("openvino", factory)
|
|
106
|
+
set_.run(OUTPUTS, frame()) # starts the background build; ORT answers
|
|
107
|
+
wait_built(set_)
|
|
108
|
+
for i in range(10): # probe frames: ORT answers AND each engine is compared
|
|
109
|
+
if set_.snapshot()["engines"]["openvino_cpu"]["state"] != "probing":
|
|
110
|
+
break
|
|
111
|
+
_, name = set_.run(OUTPUTS, frame(i))
|
|
112
|
+
self.assertEqual(name, "ort")
|
|
113
|
+
snap = set_.snapshot()
|
|
114
|
+
self.assertEqual(snap["engines"]["openvino_cpu"]["state"], "passed")
|
|
115
|
+
self.assertEqual(snap["engines"]["openvino_cpu"]["probe"]["frames"], 3)
|
|
116
|
+
self.assertEqual(snap["engines"]["openvino_cpu"]["probe"]["mismatches"], 0)
|
|
117
|
+
_, name = set_.run(OUTPUTS, frame())
|
|
118
|
+
self.assertEqual(name, "openvino_cpu")
|
|
119
|
+
self.assertEqual(set_.snapshot()["serving"], ["openvino_cpu"]) # GPU passed too, but only openvino_gpu uses it
|
|
120
|
+
|
|
121
|
+
def test_a_probe_that_misses_parity_never_serves(self):
|
|
122
|
+
set_, _ = engines("openvino", lambda m, d, p, threads=None: FakeSession(d, offset=0.5, precision=p))
|
|
123
|
+
set_.run(OUTPUTS, frame())
|
|
124
|
+
wait_built(set_)
|
|
125
|
+
for i in range(3):
|
|
126
|
+
set_.run(OUTPUTS, frame(i))
|
|
127
|
+
snap = set_.snapshot()["engines"]["openvino_cpu"]
|
|
128
|
+
self.assertEqual(snap["state"], "failed")
|
|
129
|
+
self.assertIn("parity", snap["reason"])
|
|
130
|
+
self.assertEqual(set_.run(OUTPUTS, frame())[1], "ort")
|
|
131
|
+
|
|
132
|
+
def test_probe_mode_reports_but_never_serves(self):
|
|
133
|
+
set_, _ = engines("openvino_probe", lambda m, d, p, threads=None: FakeSession(d, precision=p))
|
|
134
|
+
set_.run(OUTPUTS, frame())
|
|
135
|
+
wait_built(set_)
|
|
136
|
+
for i in range(4):
|
|
137
|
+
set_.run(OUTPUTS, frame(i))
|
|
138
|
+
self.assertEqual(set_.snapshot()["engines"]["openvino_cpu"]["state"], "passed")
|
|
139
|
+
self.assertEqual(set_.run(OUTPUTS, frame())[1], "ort")
|
|
140
|
+
|
|
141
|
+
def test_gpu_fp16_miss_is_rebuilt_in_fp32_and_then_serves_as_second_engine(self):
|
|
142
|
+
def factory(model, device, precision, threads=None):
|
|
143
|
+
if device == "GPU" and precision == "f16":
|
|
144
|
+
return FakeSession("gpu-f16", offset=0.01, precision="f16") # 1e-2 > the 1e-3 person bar
|
|
145
|
+
return FakeSession(f"{device}-{precision}", precision=precision, delay=0.05)
|
|
146
|
+
|
|
147
|
+
set_, _ = engines("openvino_gpu", factory)
|
|
148
|
+
set_.run(OUTPUTS, frame())
|
|
149
|
+
wait_built(set_)
|
|
150
|
+
for i in range(3):
|
|
151
|
+
set_.run(OUTPUTS, frame(i))
|
|
152
|
+
gpu = set_.snapshot()["engines"]["openvino_gpu"]
|
|
153
|
+
self.assertIn(gpu["state"], ("failed", "probing"))
|
|
154
|
+
deadline = time.time() + 5
|
|
155
|
+
while set_.snapshot()["engines"]["openvino_gpu"].get("precision") != "f32" and time.time() < deadline:
|
|
156
|
+
time.sleep(0.01)
|
|
157
|
+
for i in range(3):
|
|
158
|
+
set_.run(OUTPUTS, frame(i))
|
|
159
|
+
gpu = set_.snapshot()["engines"]["openvino_gpu"]
|
|
160
|
+
self.assertEqual((gpu["state"], gpu["precision"]), ("passed", "f32"))
|
|
161
|
+
self.assertEqual(gpu["probe"]["previous"]["precision"], "f16")
|
|
162
|
+
self.assertEqual(set_.snapshot()["serving"], ["openvino_cpu", "openvino_gpu"])
|
|
163
|
+
# Two frames at once: one on each engine.
|
|
164
|
+
names = []
|
|
165
|
+
threads = [threading.Thread(target=lambda: names.append(set_.run(OUTPUTS, frame())[1])) for _ in range(2)]
|
|
166
|
+
[t.start() for t in threads]
|
|
167
|
+
[t.join() for t in threads]
|
|
168
|
+
self.assertEqual(sorted(names), ["openvino_cpu", "openvino_gpu"])
|
|
169
|
+
|
|
170
|
+
def test_a_run_time_failure_is_answered_by_ort_and_disables_the_engine(self):
|
|
171
|
+
sessions = {}
|
|
172
|
+
|
|
173
|
+
def factory(model, device, precision, threads=None):
|
|
174
|
+
sessions[device] = FakeSession(device, precision=precision)
|
|
175
|
+
return sessions[device]
|
|
176
|
+
|
|
177
|
+
set_, ort = engines("openvino", factory)
|
|
178
|
+
set_.run(OUTPUTS, frame())
|
|
179
|
+
wait_built(set_)
|
|
180
|
+
for i in range(3):
|
|
181
|
+
set_.run(OUTPUTS, frame(i))
|
|
182
|
+
sessions["CPU"].fail = True
|
|
183
|
+
before = ort.calls
|
|
184
|
+
outputs, name = set_.run(OUTPUTS, frame(7.0))
|
|
185
|
+
self.assertEqual(float(outputs[0].ravel()[0]), 7.0) # the same input, answered
|
|
186
|
+
self.assertEqual(ort.calls, before + 1)
|
|
187
|
+
self.assertEqual(set_.snapshot()["engines"]["openvino_cpu"]["state"], "failed")
|
|
188
|
+
self.assertEqual(set_.run(OUTPUTS, frame())[1], "ort")
|
|
189
|
+
|
|
190
|
+
def test_a_host_without_openvino_reports_unavailable_and_stays_on_ort(self):
|
|
191
|
+
ort = FakeSession("CPUExecutionProvider")
|
|
192
|
+
with mock.patch.object(execution, "openvino_version", return_value=None):
|
|
193
|
+
set_ = DetectorEngines(ort, lambda: b"model", BackendPolicy("openvino_gpu"), compare,
|
|
194
|
+
log=lambda *_: None, session_factory=mock.Mock())
|
|
195
|
+
self.assertEqual(set_.run(OUTPUTS, frame())[1], "ort")
|
|
196
|
+
snap = set_.snapshot()["engines"]
|
|
197
|
+
self.assertEqual(snap["openvino_cpu"]["state"], "unavailable")
|
|
198
|
+
self.assertEqual(snap["openvino_gpu"]["state"], "unavailable")
|
|
199
|
+
|
|
200
|
+
def test_a_missing_device_is_unavailable_not_failed(self):
|
|
201
|
+
def factory(model, device, precision, threads=None):
|
|
202
|
+
if device == "GPU":
|
|
203
|
+
raise EngineUnavailable("GPU is not an OpenVINO device on this host (['CPU'])")
|
|
204
|
+
return FakeSession(device, precision=precision)
|
|
205
|
+
|
|
206
|
+
set_, _ = engines("openvino_gpu", factory)
|
|
207
|
+
set_.run(OUTPUTS, frame())
|
|
208
|
+
snap = wait_built(set_)
|
|
209
|
+
self.assertEqual(snap["openvino_gpu"]["state"], "unavailable")
|
|
210
|
+
self.assertIn("not an OpenVINO device", snap["openvino_gpu"]["reason"])
|
|
211
|
+
|
|
212
|
+
def test_a_low_floor_request_stays_on_ort_even_when_openvino_serves(self):
|
|
213
|
+
"""A box method that asks at a 0.05 floor (the uniform rule's fixtures) keeps ORT's answers."""
|
|
214
|
+
set_, _ = engines("openvino", lambda m, d, p, threads=None: FakeSession(d, precision=p))
|
|
215
|
+
set_.run(OUTPUTS, frame())
|
|
216
|
+
wait_built(set_)
|
|
217
|
+
for i in range(10):
|
|
218
|
+
if set_.snapshot()["engines"]["openvino_cpu"]["state"] != "probing":
|
|
219
|
+
break
|
|
220
|
+
set_.run(OUTPUTS, frame(i))
|
|
221
|
+
self.assertEqual(set_.run(OUTPUTS, frame(), min_confidence=0.25)[1], "openvino_cpu")
|
|
222
|
+
self.assertEqual(set_.run(OUTPUTS, frame(), min_confidence=0.05)[1], "ort")
|
|
223
|
+
|
|
224
|
+
def test_a_box_that_moves_past_the_tolerance_fails_the_probe(self):
|
|
225
|
+
def shifted(reference, candidate):
|
|
226
|
+
return {"person_diff": 0.0, "score_diff": 0.0, "mismatches": 0, "box_shift": 0.02}
|
|
227
|
+
|
|
228
|
+
ort = FakeSession("CPUExecutionProvider")
|
|
229
|
+
with mock.patch.object(execution, "openvino_version", return_value="2026.4.1"):
|
|
230
|
+
set_ = DetectorEngines(ort, lambda: b"model", BackendPolicy("openvino"), shifted, log=lambda *_: None,
|
|
231
|
+
session_factory=lambda m, d, p, threads=None: FakeSession(d, precision=p), probe_frames=2)
|
|
232
|
+
set_.run(OUTPUTS, frame())
|
|
233
|
+
wait_built(set_)
|
|
234
|
+
for i in range(4):
|
|
235
|
+
set_.run(OUTPUTS, frame(i))
|
|
236
|
+
cpu = set_.snapshot()["engines"]["openvino_cpu"]
|
|
237
|
+
self.assertEqual(cpu["state"], "failed")
|
|
238
|
+
self.assertIn("box shift", cpu["reason"])
|
|
239
|
+
|
|
240
|
+
def test_busy_time_is_accounted_per_engine(self):
|
|
241
|
+
set_, _ = engines("ort", mock.Mock())
|
|
242
|
+
for _ in range(3):
|
|
243
|
+
set_.run(OUTPUTS, frame())
|
|
244
|
+
ort = set_.snapshot()["engines"]["ort"]
|
|
245
|
+
self.assertEqual(ort["calls"], 3)
|
|
246
|
+
self.assertGreaterEqual(ort["busy_ms"], 0.0)
|
|
247
|
+
self.assertIsNotNone(ort["ms_p50"])
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
if __name__ == "__main__":
|
|
251
|
+
unittest.main()
|
|
@@ -162,6 +162,7 @@ class RegistryCase(unittest.TestCase):
|
|
|
162
162
|
vocabularies,
|
|
163
163
|
pinned: str,
|
|
164
164
|
budget_mb: "int | None" = 1536,
|
|
165
|
+
warm=None,
|
|
165
166
|
) -> ModelRegistry:
|
|
166
167
|
"""Every case INJECTS a ceiling, because the service owns none.
|
|
167
168
|
|
|
@@ -179,9 +180,61 @@ class RegistryCase(unittest.TestCase):
|
|
|
179
180
|
ram_budget_bytes=None if budget_mb is None else budget_mb * MB,
|
|
180
181
|
log=self.logs.append,
|
|
181
182
|
clock=lambda: self.now,
|
|
183
|
+
warm=warm,
|
|
182
184
|
)
|
|
183
185
|
|
|
184
186
|
|
|
187
|
+
class TestThePinnedModelWarmsAtFullSize(RegistryCase):
|
|
188
|
+
"""The probe proves a forward pass on a 64x48 frame; the pinned model then warms
|
|
189
|
+
once more at full size before READY, so the first live look is not the slow one
|
|
190
|
+
(Texas, 0.2.246 swap: first live call 3.2 s, the next 18 averaged 1.4 s)."""
|
|
191
|
+
|
|
192
|
+
def test_the_pinned_model_warms_once_before_ready_and_a_specialist_never_does(self):
|
|
193
|
+
self.write_artifact("general")
|
|
194
|
+
self.write_artifact("ppe")
|
|
195
|
+
warmed = []
|
|
196
|
+
reg = None
|
|
197
|
+
def warm(session):
|
|
198
|
+
warmed.append((session.model_name, reg.snapshot()["models"][session.model_name]["state"]))
|
|
199
|
+
reg = self.registry([GENERAL, PPE], pinned="general", warm=warm)
|
|
200
|
+
reg.refresh()
|
|
201
|
+
self.assertEqual(warmed, [("general", "loading")])
|
|
202
|
+
self.assertEqual(reg.snapshot()["models"]["general"]["state"], STATE_READY)
|
|
203
|
+
self.assertTrue(any("full-size warm-up" in line and "general" in line for line in self.logs))
|
|
204
|
+
reg.detect(b"jpeg", 0.25, reg.resolve_classes(["glove"]))
|
|
205
|
+
self.assertEqual(self.probed, ["general", "ppe"])
|
|
206
|
+
self.assertEqual(warmed, [("general", "loading")])
|
|
207
|
+
|
|
208
|
+
def test_a_failed_full_size_warmup_leaves_the_model_ready_on_its_probe(self):
|
|
209
|
+
self.write_artifact("general")
|
|
210
|
+
def warm(session):
|
|
211
|
+
raise RuntimeError("no full-size frame today")
|
|
212
|
+
reg = self.registry([GENERAL], pinned="general", warm=warm)
|
|
213
|
+
reg.refresh()
|
|
214
|
+
row = reg.snapshot()["models"]["general"]
|
|
215
|
+
self.assertEqual(row["state"], STATE_READY)
|
|
216
|
+
self.assertIn("warmup_inference_ms", row)
|
|
217
|
+
self.assertTrue(any("full-size warm-up failed; ready on its probe: no full-size frame today" in line
|
|
218
|
+
for line in self.logs))
|
|
219
|
+
self.assertEqual(reg.detect(b"jpeg", 0.25, reg.resolve_classes(["person"])).models, ["general"])
|
|
220
|
+
|
|
221
|
+
def test_the_warmup_is_not_timed_into_the_probes_inference_time(self):
|
|
222
|
+
import time
|
|
223
|
+
self.write_artifact("general")
|
|
224
|
+
reg = self.registry([GENERAL], pinned="general", warm=lambda session: time.sleep(0.25))
|
|
225
|
+
reg.refresh()
|
|
226
|
+
self.assertLess(reg.snapshot()["models"]["general"]["warmup_inference_ms"], 200)
|
|
227
|
+
|
|
228
|
+
def test_a_reload_of_a_new_pinned_artifact_warms_again(self):
|
|
229
|
+
self.write_artifact("general")
|
|
230
|
+
warmed = []
|
|
231
|
+
reg = self.registry([GENERAL], pinned="general", warm=lambda session: warmed.append(session.model_name))
|
|
232
|
+
reg.refresh()
|
|
233
|
+
self.write_artifact("general", b"onnx-v2-different-size")
|
|
234
|
+
reg.refresh()
|
|
235
|
+
self.assertEqual(warmed, ["general", "general"])
|
|
236
|
+
|
|
237
|
+
|
|
185
238
|
class TestTwoModelsAnswerOneRequest(RegistryCase):
|
|
186
239
|
"""§3: "A request spanning two models runs both and merges." """
|
|
187
240
|
|
|
@@ -1079,3 +1079,46 @@ class ActorActionServerTest(ServerCase):
|
|
|
1079
1079
|
|
|
1080
1080
|
if __name__ == "__main__":
|
|
1081
1081
|
unittest.main()
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
class TestBackendSelection(ServerCase):
|
|
1085
|
+
"""POST /backend (plan v7 W8): the connector relays CCTV_DETECTOR_BACKEND here."""
|
|
1086
|
+
|
|
1087
|
+
def loader(self):
|
|
1088
|
+
from trillboards_detector.execution import BackendPolicy
|
|
1089
|
+
|
|
1090
|
+
class PolicyLoader(FakeLoader):
|
|
1091
|
+
def __init__(self):
|
|
1092
|
+
super().__init__()
|
|
1093
|
+
self.backend_policy = BackendPolicy("ort")
|
|
1094
|
+
|
|
1095
|
+
def info(self):
|
|
1096
|
+
return {"state": "ready", "model": "rfdetr_medium",
|
|
1097
|
+
"backend": {"requested": self.backend_policy.mode, "serving": ["ort"], "engines": {}}}
|
|
1098
|
+
|
|
1099
|
+
return PolicyLoader()
|
|
1100
|
+
|
|
1101
|
+
def test_a_valid_mode_is_taken_and_reported(self):
|
|
1102
|
+
loader = self.loader()
|
|
1103
|
+
url = self.serve(loader)
|
|
1104
|
+
status, body = self.request(f"{url}/backend", method="POST", body={"version": 1, "mode": "openvino"})
|
|
1105
|
+
self.assertEqual(status, 200)
|
|
1106
|
+
self.assertEqual(body["mode"], "openvino")
|
|
1107
|
+
self.assertEqual(body["backend"]["requested"], "openvino")
|
|
1108
|
+
self.assertEqual(loader.backend_policy.mode, "openvino")
|
|
1109
|
+
|
|
1110
|
+
def test_anything_else_is_refused_and_changes_nothing(self):
|
|
1111
|
+
loader = self.loader()
|
|
1112
|
+
url = self.serve(loader)
|
|
1113
|
+
for bad in ({"version": 1, "mode": "tensorrt"}, {"version": 2, "mode": "ort"}, {"mode": "ort"},
|
|
1114
|
+
{"version": 1, "mode": "ort", "extra": True}, ["ort"]):
|
|
1115
|
+
status, _ = self.request(f"{url}/backend", method="POST", body=bad)
|
|
1116
|
+
self.assertEqual(status, 400, bad)
|
|
1117
|
+
status, _ = self.request(f"{url}/backend", method="POST", raw_body=b"not json")
|
|
1118
|
+
self.assertEqual(status, 400)
|
|
1119
|
+
self.assertEqual(loader.backend_policy.mode, "ort")
|
|
1120
|
+
|
|
1121
|
+
def test_a_build_without_selection_says_so(self):
|
|
1122
|
+
url = self.serve(FakeLoader())
|
|
1123
|
+
status, _ = self.request(f"{url}/backend", method="POST", body={"version": 1, "mode": "ort"})
|
|
1124
|
+
self.assertEqual(status, 503)
|
|
@@ -247,20 +247,33 @@ class TestInstallersCannotAcceptAStaleInstall(unittest.TestCase):
|
|
|
247
247
|
with self.subTest(installer=path.name + f" ({path.parent.name})"):
|
|
248
248
|
text = path.read_text(encoding="utf-8")
|
|
249
249
|
install_lines = self._install_invocations(text)
|
|
250
|
-
# TWO: the ordinary install
|
|
251
|
-
#
|
|
252
|
-
#
|
|
250
|
+
# TWO: on macOS and Linux the ordinary install and the
|
|
251
|
+
# uninstall-and-retry repair rung; on Windows one line per cache
|
|
252
|
+
# mode (online, offline) that every install goes through. A file
|
|
253
|
+
# that grew a third would be installing somewhere this test
|
|
254
|
+
# never looked.
|
|
253
255
|
self.assertEqual(
|
|
254
256
|
len(install_lines),
|
|
255
257
|
2,
|
|
256
258
|
f"{path} runs {len(install_lines)} `uv tool install` invocations, expected 2",
|
|
257
259
|
)
|
|
258
|
-
for line in install_lines
|
|
260
|
+
online = [line for line in install_lines if "--offline" not in line]
|
|
261
|
+
self.assertTrue(online, f"{path} never rebuilds the staged package online")
|
|
262
|
+
for line in online:
|
|
259
263
|
self.assertIn(
|
|
260
264
|
"--refresh-package trillboards-detector",
|
|
261
265
|
line,
|
|
262
266
|
f"{path} installs without busting uv's cached wheel: {line.strip()}",
|
|
263
267
|
)
|
|
268
|
+
# Windows replaces the serving detector OFFLINE, after a trial
|
|
269
|
+
# install that carried --refresh-package rebuilt the staged bytes
|
|
270
|
+
# into uv's cache. Current uv refuses --offline with any refresh,
|
|
271
|
+
# and the offline install takes the trial's rebuilt wheel
|
|
272
|
+
# (measured on uv 0.11.15, 2026-11-17: same path, version
|
|
273
|
+
# unchanged, new bytes installed with the network dead).
|
|
274
|
+
for line in install_lines:
|
|
275
|
+
if "--offline" in line:
|
|
276
|
+
self.assertNotIn("--refresh", line, f"{path}: uv refuses --offline with a refresh: {line.strip()}")
|
|
264
277
|
|
|
265
278
|
def test_every_installer_verifies_what_it_installed(self) -> None:
|
|
266
279
|
for path in self.INSTALLERS:
|
|
@@ -4,6 +4,16 @@ SQLite commits frame inputs and identities together. In-memory Kalman state is a
|
|
|
4
4
|
cache: restart recovery replays the bounded detection journal through the same
|
|
5
5
|
tracker, restoring external actor IDs from exact saved detection associations.
|
|
6
6
|
Predicted boxes are never returned as new visual observations.
|
|
7
|
+
|
|
8
|
+
A frame's per-track records (track_records.py) are read inside the same lock and
|
|
9
|
+
transaction that commits the frame, and kept beside it (actor_frame_records), so
|
|
10
|
+
`track_and_records` answers a frame with ITS records: never the records of a
|
|
11
|
+
request on the same camera that committed in between, and on a replay the ones
|
|
12
|
+
the frame had. A face vector is never kept there (a face never outlives its
|
|
13
|
+
track): the row keeps the face slot's digest, and a replay serves the face only
|
|
14
|
+
while the actor's live record still holds that same slot. A side table, not a
|
|
15
|
+
column on actor_frame: an older build inserts frames by position and must still
|
|
16
|
+
be able to write this journal after a rollback.
|
|
7
17
|
"""
|
|
8
18
|
from __future__ import annotations
|
|
9
19
|
|
|
@@ -24,6 +34,7 @@ from .actor_identity import (
|
|
|
24
34
|
ActorIdentitySegments, POLICY as IDENTITY_POLICY, checked_appearance,
|
|
25
35
|
MODEL_ID as IDENTITY_MODEL_ID,
|
|
26
36
|
)
|
|
37
|
+
from .track_records import MAX_RECORDS_PER_CAMERA, FaceSlot, TrackRecord
|
|
27
38
|
|
|
28
39
|
ALGORITHM = "bytetrack_2.6.1"
|
|
29
40
|
_ID = re.compile(r"[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}\Z")
|
|
@@ -104,10 +115,18 @@ class ActorTrackerJournal:
|
|
|
104
115
|
CREATE TABLE IF NOT EXISTS actor_motion_frame (
|
|
105
116
|
camera_id TEXT NOT NULL, frame_id TEXT NOT NULL, result_json TEXT NOT NULL,
|
|
106
117
|
PRIMARY KEY(camera_id,frame_id));
|
|
118
|
+
CREATE TABLE IF NOT EXISTS actor_frame_records (
|
|
119
|
+
camera_id TEXT NOT NULL, frame_id TEXT NOT NULL, fingerprint TEXT NOT NULL,
|
|
120
|
+
records_json TEXT NOT NULL, PRIMARY KEY(camera_id,frame_id));
|
|
107
121
|
CREATE TABLE IF NOT EXISTS actor_identity_checkpoint (
|
|
108
122
|
camera_id TEXT PRIMARY KEY, seq INTEGER NOT NULL, payload_json TEXT NOT NULL);
|
|
109
123
|
CREATE TABLE IF NOT EXISTS actor_checkpoint (
|
|
110
124
|
camera_id TEXT PRIMARY KEY, seq INTEGER NOT NULL, payload_json TEXT NOT NULL);
|
|
125
|
+
CREATE TABLE IF NOT EXISTS actor_track_record (
|
|
126
|
+
camera_id TEXT NOT NULL, actor_id TEXT NOT NULL, epoch TEXT NOT NULL, kind TEXT NOT NULL,
|
|
127
|
+
first_seen_ms INTEGER NOT NULL, last_seen_ms INTEGER NOT NULL, frames INTEGER NOT NULL,
|
|
128
|
+
box_json TEXT NOT NULL, confidence REAL NOT NULL, face_json TEXT NULL,
|
|
129
|
+
PRIMARY KEY(camera_id, actor_id));
|
|
111
130
|
""")
|
|
112
131
|
|
|
113
132
|
def close(self):
|
|
@@ -120,6 +139,98 @@ class ActorTrackerJournal:
|
|
|
120
139
|
with self._lock:
|
|
121
140
|
return self._db.execute("SELECT count(*) FROM actor_frame WHERE camera_id=?", (camera_id,)).fetchone()[0]
|
|
122
141
|
|
|
142
|
+
# ── per-track records (track_records.py) ─────────────────────────────────
|
|
143
|
+
|
|
144
|
+
def _write_track_records(self, camera, result, values, captured_at):
|
|
145
|
+
"""Inside track()'s transaction: observed actors refresh, ended actors drop."""
|
|
146
|
+
self._db.execute("DELETE FROM actor_track_record WHERE camera_id=? AND epoch<>?", (camera, result["epoch"]))
|
|
147
|
+
for ended in result["endedActors"]:
|
|
148
|
+
self._db.execute("DELETE FROM actor_track_record WHERE camera_id=? AND actor_id=?", (camera, ended["id"]))
|
|
149
|
+
for association in result["actors"]:
|
|
150
|
+
actor, box = association["actor"], values[association["detectionIndex"]]
|
|
151
|
+
self._db.execute(
|
|
152
|
+
"INSERT INTO actor_track_record VALUES (?,?,?,?,?,?,1,?,?,NULL) "
|
|
153
|
+
"ON CONFLICT(camera_id, actor_id) DO UPDATE SET last_seen_ms=excluded.last_seen_ms, "
|
|
154
|
+
"frames=actor_track_record.frames+1, box_json=excluded.box_json, confidence=excluded.confidence",
|
|
155
|
+
(camera, actor["id"], actor["epoch"], actor["kind"], captured_at, captured_at,
|
|
156
|
+
_json([box["x"], box["y"], box["width"], box["height"]]), float(box["confidence"])))
|
|
157
|
+
self._db.execute(
|
|
158
|
+
"DELETE FROM actor_track_record WHERE camera_id=? AND actor_id NOT IN (SELECT actor_id FROM "
|
|
159
|
+
"actor_track_record WHERE camera_id=? ORDER BY last_seen_ms DESC, actor_id LIMIT ?)",
|
|
160
|
+
(camera, camera, MAX_RECORDS_PER_CAMERA))
|
|
161
|
+
|
|
162
|
+
def _read_track_records(self, camera_id):
|
|
163
|
+
"""The camera's live actors' records, oldest first. The caller holds the lock."""
|
|
164
|
+
rows = self._db.execute(
|
|
165
|
+
"SELECT actor_id,kind,epoch,first_seen_ms,last_seen_ms,frames,box_json,confidence,face_json "
|
|
166
|
+
"FROM actor_track_record WHERE camera_id=? ORDER BY first_seen_ms, actor_id", (camera_id,)).fetchall()
|
|
167
|
+
return [TrackRecord(r[0], r[1], r[2], r[3], r[4], r[5], tuple(json.loads(r[6])), r[7],
|
|
168
|
+
None if r[8] is None else FaceSlot.from_wire(json.loads(r[8]))) for r in rows]
|
|
169
|
+
|
|
170
|
+
def track_records(self, camera_id):
|
|
171
|
+
"""The camera's live actors' records, oldest first (list of TrackRecord).
|
|
172
|
+
|
|
173
|
+
The LIVE state: a /detect response serves the records of its own frame from
|
|
174
|
+
track_and_records instead, which another frame cannot move.
|
|
175
|
+
"""
|
|
176
|
+
with self._lock:
|
|
177
|
+
return self._read_track_records(camera_id)
|
|
178
|
+
|
|
179
|
+
@staticmethod
|
|
180
|
+
def _stored_records(records):
|
|
181
|
+
"""A frame's records as its journal row keeps them: the wire form, each face replaced
|
|
182
|
+
by its slot's digest. The vector stays only on the live record, which ends with its
|
|
183
|
+
actor (track_records.py)."""
|
|
184
|
+
stored = []
|
|
185
|
+
for record in records:
|
|
186
|
+
wire = record.to_wire()
|
|
187
|
+
if record.face is not None:
|
|
188
|
+
wire["face"] = {"sha256": _hash(record.face.to_wire())}
|
|
189
|
+
stored.append(wire)
|
|
190
|
+
return _json(stored)
|
|
191
|
+
|
|
192
|
+
def _replayed_records(self, camera, frame_id, fingerprint):
|
|
193
|
+
"""A replayed frame's own records, as they were kept beside it. Each face comes back
|
|
194
|
+
only while the actor's live record still holds that same slot. A frame with none kept
|
|
195
|
+
(journalled before the snapshot existed, or by an older build) has none to serve: [].
|
|
196
|
+
The caller holds the lock."""
|
|
197
|
+
row = self._db.execute(
|
|
198
|
+
"SELECT fingerprint,records_json FROM actor_frame_records WHERE camera_id=? AND frame_id=?",
|
|
199
|
+
(camera, frame_id)).fetchone()
|
|
200
|
+
if row is None or row[0] != fingerprint:
|
|
201
|
+
return []
|
|
202
|
+
try:
|
|
203
|
+
stored = json.loads(row[1])
|
|
204
|
+
if not isinstance(stored, list) or any(not isinstance(r, dict) for r in stored):
|
|
205
|
+
raise ValueError("records snapshot is not a list of records")
|
|
206
|
+
live = {r.actor_id: r.face for r in self._read_track_records(camera)}
|
|
207
|
+
replayed = []
|
|
208
|
+
for record in stored:
|
|
209
|
+
saved, face = record.get("face"), None
|
|
210
|
+
if saved is not None:
|
|
211
|
+
current = live.get(record.get("actorId"))
|
|
212
|
+
if current is not None and saved.get("sha256") == _hash(current.to_wire()):
|
|
213
|
+
face = current.to_wire()
|
|
214
|
+
replayed.append({**record, "face": face})
|
|
215
|
+
return replayed
|
|
216
|
+
except (ValueError, TypeError, AttributeError) as error:
|
|
217
|
+
raise TrackingError("Corrupt actor frame journal") from error
|
|
218
|
+
|
|
219
|
+
def record_face(self, camera_id, actor_id, face):
|
|
220
|
+
"""Store one FaceSlot on a LIVE actor's record; False when the actor is not live.
|
|
221
|
+
|
|
222
|
+
The face watchlist (plan v7 T1) is the only intended writer. The slot is
|
|
223
|
+
deleted with the record when the actor ends, never kept past its track.
|
|
224
|
+
"""
|
|
225
|
+
if not isinstance(face, FaceSlot):
|
|
226
|
+
raise TrackingError("record_face takes a FaceSlot")
|
|
227
|
+
payload = _json(FaceSlot.from_wire(face.to_wire()).to_wire())
|
|
228
|
+
with self._lock:
|
|
229
|
+
cursor = self._db.execute(
|
|
230
|
+
"UPDATE actor_track_record SET face_json=? WHERE camera_id=? AND actor_id=?",
|
|
231
|
+
(payload, camera_id, actor_id))
|
|
232
|
+
return cursor.rowcount == 1
|
|
233
|
+
|
|
123
234
|
def _new_tracker(self, config=None):
|
|
124
235
|
config = self._config if config is None else config
|
|
125
236
|
return self._tracker_class(
|
|
@@ -309,6 +420,21 @@ class ActorTrackerJournal:
|
|
|
309
420
|
|
|
310
421
|
def track(self, request, detections, *, image_sha256, model_hashes, frame_size,
|
|
311
422
|
appearance=None):
|
|
423
|
+
"""The signed tracking result for one frame (track_and_records without its records)."""
|
|
424
|
+
return self.track_and_records(request, detections, image_sha256=image_sha256,
|
|
425
|
+
model_hashes=model_hashes, frame_size=frame_size,
|
|
426
|
+
appearance=appearance)[0]
|
|
427
|
+
|
|
428
|
+
def track_and_records(self, request, detections, *, image_sha256, model_hashes, frame_size,
|
|
429
|
+
appearance=None):
|
|
430
|
+
"""Track one frame: (signed tracking result, the camera's per-track records AS OF
|
|
431
|
+
THIS FRAME in wire form, oldest first).
|
|
432
|
+
|
|
433
|
+
Both are read inside one lock and one transaction, so a request on the same camera
|
|
434
|
+
that commits in between cannot hand this frame its records, and a replayed frame
|
|
435
|
+
(the same frame again, e.g. a retry after a lost response) gets the records it had
|
|
436
|
+
then, from its journal row, not the camera's live ones.
|
|
437
|
+
"""
|
|
312
438
|
request = validate_tracking_request(request)
|
|
313
439
|
if (not isinstance(image_sha256, str) or not _SHA.fullmatch(image_sha256)
|
|
314
440
|
or not isinstance(model_hashes, dict) or not 1 <= len(model_hashes) <= 16
|
|
@@ -360,8 +486,9 @@ class ActorTrackerJournal:
|
|
|
360
486
|
if own[0] != fingerprint:
|
|
361
487
|
raise TrackingError("Retained actor frame identity changed")
|
|
362
488
|
_, saved = self._checked_frame(camera, request["frameId"], own[3], own[0], own[1], own[2])
|
|
489
|
+
records = self._replayed_records(camera, request["frameId"], own[0])
|
|
363
490
|
self._db.execute("COMMIT")
|
|
364
|
-
return saved
|
|
491
|
+
return saved, records
|
|
365
492
|
head = self._db.execute(
|
|
366
493
|
"SELECT context_hash,epoch,captured_at,seq,active_json FROM actor_camera WHERE camera_id=?",
|
|
367
494
|
(camera,)).fetchone()
|
|
@@ -467,6 +594,13 @@ class ActorTrackerJournal:
|
|
|
467
594
|
(camera, request["frameId"], motion_json))
|
|
468
595
|
self._db.execute("INSERT INTO actor_frame VALUES (?,?,?,?,?,?,?)",
|
|
469
596
|
(camera, request["frameId"], seq, epoch, fingerprint, _json(inputs), _json(result)))
|
|
597
|
+
# This frame's records, read in its own transaction and kept beside it.
|
|
598
|
+
self._write_track_records(camera, result, values, captured_at)
|
|
599
|
+
records = self._read_track_records(camera)
|
|
600
|
+
self._db.execute(
|
|
601
|
+
"INSERT INTO actor_frame_records VALUES (?,?,?,?) ON CONFLICT(camera_id,frame_id) DO UPDATE SET "
|
|
602
|
+
"fingerprint=excluded.fingerprint,records_json=excluded.records_json",
|
|
603
|
+
(camera, request["frameId"], fingerprint, self._stored_records(records)))
|
|
470
604
|
self._db.execute(
|
|
471
605
|
"INSERT INTO actor_camera VALUES (?,?,?,?,?,?) ON CONFLICT(camera_id) DO UPDATE SET "
|
|
472
606
|
"context_hash=excluded.context_hash,epoch=excluded.epoch,captured_at=excluded.captured_at,"
|
|
@@ -484,13 +618,16 @@ class ActorTrackerJournal:
|
|
|
484
618
|
self._db.execute(
|
|
485
619
|
"DELETE FROM actor_motion_frame WHERE camera_id=? AND frame_id NOT IN "
|
|
486
620
|
"(SELECT frame_id FROM actor_frame WHERE camera_id=?)", (camera,camera))
|
|
621
|
+
self._db.execute(
|
|
622
|
+
"DELETE FROM actor_frame_records WHERE camera_id=? AND frame_id NOT IN "
|
|
623
|
+
"(SELECT frame_id FROM actor_frame WHERE camera_id=?)", (camera,camera))
|
|
487
624
|
self._db.execute("COMMIT")
|
|
488
625
|
self._cache[camera] = (seq, tracker, identities)
|
|
489
626
|
if identity is not None:
|
|
490
627
|
self._identity_cache[camera] = (seq, identity)
|
|
491
628
|
else:
|
|
492
629
|
self._identity_cache.pop(camera, None)
|
|
493
|
-
return json.loads(_json(result))
|
|
630
|
+
return json.loads(_json(result)), [record.to_wire() for record in records]
|
|
494
631
|
except BaseException:
|
|
495
632
|
if self._db.in_transaction:
|
|
496
633
|
self._db.execute("ROLLBACK")
|
|
@@ -22,6 +22,7 @@ from .worker_budget import configure_numeric_workers
|
|
|
22
22
|
|
|
23
23
|
# This must run before loader/server imports initialize NumPy or BLAS.
|
|
24
24
|
configure_numeric_workers()
|
|
25
|
+
from .execution import BackendPolicy
|
|
25
26
|
from .loader import DEFAULT_POLL_INTERVAL_S, DetectorLoader
|
|
26
27
|
from .modelpath import DEFAULT_MODEL_NAME, resolve_model_path, resolve_ram_budget_mb, resolve_data_dir
|
|
27
28
|
from .actor_tracking import ActorTrackerJournal
|
|
@@ -110,6 +111,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
110
111
|
s.add_argument("--poll-interval", type=float, default=DEFAULT_POLL_INTERVAL_S)
|
|
111
112
|
s.add_argument("--accelerator", choices=("auto", "cpu"), default="auto",
|
|
112
113
|
help="prefer compatible local NVIDIA CUDA, otherwise CPU; cpu is an explicit rollback")
|
|
114
|
+
s.add_argument("--backend", choices=("ort", "openvino_probe", "openvino", "openvino_gpu"), default="ort",
|
|
115
|
+
help=("the inference engine to start with (plan v7 W8); the connector relays the server's "
|
|
116
|
+
"choice with POST /backend. OpenVINO serves only after its parity probe on this host."))
|
|
113
117
|
s.add_argument("--log-file", default=None, help="also write to this file (Windows has no task stdout)")
|
|
114
118
|
s.add_argument("--verbose", action="store_true")
|
|
115
119
|
s.add_argument("--tracking-journal", default=None, help="durable actor tracker SQLite path; defaults to the connector data directory")
|
|
@@ -166,6 +170,7 @@ def main(argv: "list[str] | None" = None) -> int:
|
|
|
166
170
|
ram_budget_bytes=ram_budget_bytes,
|
|
167
171
|
log=LOG.info,
|
|
168
172
|
accelerator=args.accelerator,
|
|
173
|
+
backend_policy=BackendPolicy(args.backend),
|
|
169
174
|
)
|
|
170
175
|
actor_tracker = ActorTrackerJournal(args.tracking_journal or resolve_data_dir() / "actor-tracking" / "tracks.sqlite3")
|
|
171
176
|
loader.start()
|