@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,88 @@
|
|
|
1
|
+
"""Person boxes for a list of recorded looks, through the detector service's own pixels and selection.
|
|
2
|
+
|
|
3
|
+
The input half of `scripts/look-reuse-replay.cjs` (plan v7 W8): for every <capture ms>.jpg the replay's
|
|
4
|
+
schedule names, RF-DETR Medium's person detections at the service floor (0.25), selected exactly as
|
|
5
|
+
`session.postprocess` selects, written one JSON line per look: {"ms": ..., "persons": [[conf, x, y, w, h], ...]}
|
|
6
|
+
in the look's own pixels. Both replay paths read the same file, so the engine only has to be faithful to
|
|
7
|
+
itself; `--engine openvino` (CPU, FP32, async) is the fast one, parity-checked by `openvino_parity.py`.
|
|
8
|
+
|
|
9
|
+
usage: python bench/detect_frames.py --model rfdetr-medium.onnx --frames DIR --only looks.json --out det.jsonl
|
|
10
|
+
[--engine openvino|ort] [--threads N] [--jobs N]
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import concurrent.futures as cf
|
|
16
|
+
import json
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def main(argv=None) -> int:
|
|
22
|
+
ap = argparse.ArgumentParser()
|
|
23
|
+
ap.add_argument("--model", required=True)
|
|
24
|
+
ap.add_argument("--frames", required=True)
|
|
25
|
+
ap.add_argument("--only", required=True, help="JSON list of capture ms to detect")
|
|
26
|
+
ap.add_argument("--out", required=True)
|
|
27
|
+
ap.add_argument("--engine", choices=("openvino", "ort"), default="openvino")
|
|
28
|
+
ap.add_argument("--threads", type=int, default=None)
|
|
29
|
+
ap.add_argument("--jobs", type=int, default=4, help="preprocessing threads")
|
|
30
|
+
a = ap.parse_args(argv)
|
|
31
|
+
|
|
32
|
+
import numpy as np
|
|
33
|
+
from trillboards_detector.labels import RFDETR_MEDIUM
|
|
34
|
+
from trillboards_detector.session import postprocess, preprocess
|
|
35
|
+
|
|
36
|
+
wanted = [int(ms) for ms in json.loads(Path(a.only).read_text())]
|
|
37
|
+
out_path = Path(a.out)
|
|
38
|
+
done = set()
|
|
39
|
+
if out_path.exists():
|
|
40
|
+
done = {json.loads(line)["ms"] for line in out_path.read_text().splitlines() if line.strip()}
|
|
41
|
+
todo = [ms for ms in wanted if ms not in done]
|
|
42
|
+
model = Path(a.model).read_bytes()
|
|
43
|
+
|
|
44
|
+
def prep(ms):
|
|
45
|
+
blob, w, h = preprocess((Path(a.frames) / f"{ms}.jpg").read_bytes(), 576, 576)
|
|
46
|
+
return ms, np.ascontiguousarray(blob), w, h
|
|
47
|
+
|
|
48
|
+
def boxes(dets, logits, w, h):
|
|
49
|
+
batch = postprocess(dets, logits, w, h, 0.25, {"person"}, vocabulary=RFDETR_MEDIUM)
|
|
50
|
+
return [[round(d.confidence, 5), round(d.x, 2), round(d.y, 2), round(d.width, 2), round(d.height, 2)]
|
|
51
|
+
for d in batch.detections]
|
|
52
|
+
|
|
53
|
+
with out_path.open("a") as out, cf.ThreadPoolExecutor(a.jobs) as pool:
|
|
54
|
+
if a.engine == "openvino":
|
|
55
|
+
import openvino as ov
|
|
56
|
+
core = ov.Core()
|
|
57
|
+
compiled = core.compile_model(core.read_model(model=model), "CPU",
|
|
58
|
+
{"PERFORMANCE_HINT": "THROUGHPUT", "INFERENCE_PRECISION_HINT": "f32",
|
|
59
|
+
**({"INFERENCE_NUM_THREADS": a.threads} if a.threads else {})})
|
|
60
|
+
ports = {p.get_any_name(): p for p in compiled.outputs}
|
|
61
|
+
queue = ov.AsyncInferQueue(compiled, compiled.get_property("OPTIMAL_NUMBER_OF_INFER_REQUESTS"))
|
|
62
|
+
|
|
63
|
+
def done_cb(request, meta):
|
|
64
|
+
ms, w, h = meta
|
|
65
|
+
dets = request.get_tensor(ports["dets"]).data.copy()
|
|
66
|
+
logits = request.get_tensor(ports["labels"]).data.copy()
|
|
67
|
+
out.write(json.dumps({"ms": ms, "persons": boxes(dets, logits, w, h)}) + "\n")
|
|
68
|
+
|
|
69
|
+
queue.set_callback(done_cb)
|
|
70
|
+
for ms, blob, w, h in pool.map(prep, todo):
|
|
71
|
+
queue.start_async({0: blob}, (ms, w, h))
|
|
72
|
+
queue.wait_all()
|
|
73
|
+
else:
|
|
74
|
+
import onnxruntime as ort
|
|
75
|
+
so = ort.SessionOptions()
|
|
76
|
+
if a.threads:
|
|
77
|
+
so.intra_op_num_threads = a.threads
|
|
78
|
+
session = ort.InferenceSession(model, sess_options=so, providers=["CPUExecutionProvider"])
|
|
79
|
+
name = session.get_inputs()[0].name
|
|
80
|
+
for ms, blob, w, h in pool.map(prep, todo):
|
|
81
|
+
dets, logits = session.run(["dets", "labels"], {name: blob})
|
|
82
|
+
out.write(json.dumps({"ms": ms, "persons": boxes(dets, logits, w, h)}) + "\n")
|
|
83
|
+
print(json.dumps({"looks": len(wanted), "detected": len(todo), "already": len(done)}))
|
|
84
|
+
return 0
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
sys.exit(main())
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""OpenVINO against ONNX Runtime on real frames: the plan v7 W8 parity bar and gain.
|
|
2
|
+
|
|
3
|
+
Runs the SHIPPED pipeline: `session.preprocess` (Pillow stretch + ImageNet),
|
|
4
|
+
the shipped artifact, ORT's CPU session exactly as `OnnxDetector` builds it, and
|
|
5
|
+
`execution.OpenVinoSession` (OpenVINO used directly, FP32 on the CPU; `--gpu-precision`
|
|
6
|
+
adds the integrated GPU). Per frame it compares every engine's outputs with ORT's:
|
|
7
|
+
|
|
8
|
+
person_diff the largest person-probability gap over queries either engine scores
|
|
9
|
+
at or above 0.2 (session.PARITY_FLOOR: where detections live)
|
|
10
|
+
mismatches (query, class) pairs kept at an operating threshold (0.25, 0.2939, 0.5)
|
|
11
|
+
by one engine and not the other, selected exactly as postprocess selects
|
|
12
|
+
box_shift the largest box-coordinate gap among pairs both engines keep (frame fraction)
|
|
13
|
+
floor_0.05 the same set comparison at the uniform rule's 0.05 fixtures floor, where
|
|
14
|
+
OpenVINO is NOT used (execution.OPENVINO_MIN_CONFIDENCE)
|
|
15
|
+
persons person detections ORT keeps at 0.25 (what the bar is about)
|
|
16
|
+
|
|
17
|
+
and times each engine interleaved, frame by frame, so a noisy host affects both
|
|
18
|
+
alike. Bar (plan v7 W8): identical detections (0 mismatches) and person scores
|
|
19
|
+
within 1e-3 of ORT on the 360-frame and the 134-frame sets.
|
|
20
|
+
|
|
21
|
+
usage: python -I bench/openvino_parity.py --model rfdetr-medium.onnx --frames LIST
|
|
22
|
+
[--frames LIST2 ...] [--threads N] [--gpu-precision f16 --gpu-precision f32]
|
|
23
|
+
[--avx2-only] --out result.json
|
|
24
|
+
|
|
25
|
+
`--avx2-only` sets ONEDNN_MAX_CPU_ISA=AVX2 for OpenVINO's CPU plugin before it
|
|
26
|
+
loads, to approximate an AVX2-only box (the Texas i7-7700) on a newer CPU.
|
|
27
|
+
"""
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
import argparse
|
|
31
|
+
import hashlib
|
|
32
|
+
import json
|
|
33
|
+
import os
|
|
34
|
+
import platform
|
|
35
|
+
import statistics
|
|
36
|
+
import sys
|
|
37
|
+
import time
|
|
38
|
+
from pathlib import Path
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def main(argv=None) -> int:
|
|
42
|
+
ap = argparse.ArgumentParser()
|
|
43
|
+
ap.add_argument("--model", required=True)
|
|
44
|
+
ap.add_argument("--frames", action="append", required=True, help="a file listing JPEG paths, one per line")
|
|
45
|
+
ap.add_argument("--threads", type=int, default=None)
|
|
46
|
+
ap.add_argument("--gpu-precision", action="append", default=[])
|
|
47
|
+
ap.add_argument("--avx2-only", action="store_true")
|
|
48
|
+
ap.add_argument("--warmup", type=int, default=3)
|
|
49
|
+
ap.add_argument("--out", required=True)
|
|
50
|
+
a = ap.parse_args(argv)
|
|
51
|
+
if a.avx2_only:
|
|
52
|
+
os.environ["ONEDNN_MAX_CPU_ISA"] = "AVX2"
|
|
53
|
+
|
|
54
|
+
import numpy as np
|
|
55
|
+
import onnxruntime as ort
|
|
56
|
+
from trillboards_detector.execution import OpenVinoSession, openvino_version
|
|
57
|
+
from trillboards_detector.labels import RFDETR_MEDIUM
|
|
58
|
+
from trillboards_detector.session import NUM_SELECT, OPERATING_THRESHOLDS, PARITY_FLOOR, _sigmoid, preprocess
|
|
59
|
+
|
|
60
|
+
model_bytes = Path(a.model).read_bytes()
|
|
61
|
+
sha = hashlib.sha256(model_bytes).hexdigest()
|
|
62
|
+
so = ort.SessionOptions()
|
|
63
|
+
so.log_severity_level = 3
|
|
64
|
+
if a.threads:
|
|
65
|
+
so.intra_op_num_threads = a.threads
|
|
66
|
+
ref = ort.InferenceSession(model_bytes, sess_options=so, providers=["CPUExecutionProvider"])
|
|
67
|
+
in_name = ref.get_inputs()[0].name
|
|
68
|
+
size = ref.get_inputs()[0].shape[2]
|
|
69
|
+
engines = {"openvino_cpu": OpenVinoSession(model_bytes, "CPU", "f32", threads=a.threads)}
|
|
70
|
+
for precision in a.gpu_precision:
|
|
71
|
+
try:
|
|
72
|
+
engines[f"openvino_gpu_{precision}"] = OpenVinoSession(model_bytes, "GPU", precision)
|
|
73
|
+
except Exception as error: # report, never hide: a GPU that does not bind is a result
|
|
74
|
+
engines[f"openvino_gpu_{precision}"] = error
|
|
75
|
+
person = next(slot for slot, name in RFDETR_MEDIUM.slot_names.items() if name == "person")
|
|
76
|
+
|
|
77
|
+
def outputs(session, blob):
|
|
78
|
+
return session.run(["dets", "labels"], {in_name: blob})
|
|
79
|
+
|
|
80
|
+
def kept_at(prob, threshold):
|
|
81
|
+
flat = prob.reshape(-1)
|
|
82
|
+
order = np.argsort(-flat, kind="stable")[:NUM_SELECT]
|
|
83
|
+
return {int(i) for i in order[flat[order] > threshold]}
|
|
84
|
+
|
|
85
|
+
def grade(reference, candidate):
|
|
86
|
+
p_ref, p_cand = _sigmoid(reference[1][0]), _sigmoid(candidate[1][0])
|
|
87
|
+
live = (p_ref >= PARITY_FLOOR) | (p_cand >= PARITY_FLOOR)
|
|
88
|
+
diff = np.where(live, np.abs(p_ref - p_cand), 0.0)
|
|
89
|
+
mismatches, shift, n_classes = 0, 0.0, p_ref.shape[1]
|
|
90
|
+
for threshold in OPERATING_THRESHOLDS:
|
|
91
|
+
a, b = kept_at(p_ref, threshold), kept_at(p_cand, threshold)
|
|
92
|
+
mismatches += len(a ^ b)
|
|
93
|
+
for index in a & b:
|
|
94
|
+
q = index // n_classes
|
|
95
|
+
shift = max(shift, float(np.abs(reference[0][0][q] - candidate[0][0][q]).max()))
|
|
96
|
+
low = len(kept_at(p_ref, 0.05) ^ kept_at(p_cand, 0.05))
|
|
97
|
+
return float(diff[:, person].max()), float(diff.max()), mismatches, shift, low
|
|
98
|
+
|
|
99
|
+
result = {"model_sha256": sha, "openvino": openvino_version(), "onnxruntime": ort.__version__,
|
|
100
|
+
"host": {"platform": platform.platform(), "processor": platform.processor(),
|
|
101
|
+
"cpu_count": os.cpu_count(), "avx2_only": a.avx2_only, "threads": a.threads},
|
|
102
|
+
"sets": {}}
|
|
103
|
+
live = {name: s for name, s in engines.items() if not isinstance(s, Exception)}
|
|
104
|
+
for name, s in engines.items():
|
|
105
|
+
if isinstance(s, Exception):
|
|
106
|
+
result.setdefault("unavailable", {})[name] = f"{type(s).__name__}: {s}"[:500]
|
|
107
|
+
for listing in a.frames:
|
|
108
|
+
paths = [p for p in Path(listing).read_text().split() if p]
|
|
109
|
+
times = {"ort": [], **{name: [] for name in live}}
|
|
110
|
+
rows = {name: {"frames": 0, "max_person_diff": 0.0, "max_score_diff": 0.0, "mismatches": 0,
|
|
111
|
+
"max_box_shift": 0.0, "floor_0.05_mismatches": 0, "mismatch_frames": []} for name in live}
|
|
112
|
+
persons = 0
|
|
113
|
+
for i, path in enumerate(paths):
|
|
114
|
+
blob, _w, _h = preprocess(Path(path).read_bytes(), size, size)
|
|
115
|
+
blob = np.ascontiguousarray(blob)
|
|
116
|
+
if i < a.warmup:
|
|
117
|
+
outputs(ref, blob)
|
|
118
|
+
for s in live.values():
|
|
119
|
+
outputs(s, blob)
|
|
120
|
+
t = time.perf_counter(); reference = outputs(ref, blob); times["ort"].append((time.perf_counter() - t) * 1000)
|
|
121
|
+
for name, s in live.items():
|
|
122
|
+
t = time.perf_counter(); candidate = outputs(s, blob); times[name].append((time.perf_counter() - t) * 1000)
|
|
123
|
+
pd, sd, mm, shift, low = grade(reference, candidate)
|
|
124
|
+
row = rows[name]
|
|
125
|
+
row["frames"] += 1
|
|
126
|
+
row["max_person_diff"] = max(row["max_person_diff"], pd)
|
|
127
|
+
row["max_score_diff"] = max(row["max_score_diff"], sd)
|
|
128
|
+
row["mismatches"] += mm
|
|
129
|
+
row["max_box_shift"] = max(row["max_box_shift"], shift)
|
|
130
|
+
row["floor_0.05_mismatches"] += low
|
|
131
|
+
if mm:
|
|
132
|
+
row["mismatch_frames"].append(path)
|
|
133
|
+
persons += int((_sigmoid(reference[1][0])[:, person] > 0.25).sum())
|
|
134
|
+
summary = {"frames": len(paths), "ort_persons_at_0.25": persons,
|
|
135
|
+
"ms_p50": {k: round(statistics.median(v), 1) for k, v in times.items() if v},
|
|
136
|
+
"engines": {}}
|
|
137
|
+
for name, row in rows.items():
|
|
138
|
+
row["passes"] = row["mismatches"] == 0 and row["max_person_diff"] <= 1e-3 and row["max_box_shift"] <= 0.01
|
|
139
|
+
row["max_box_shift"] = float(f"{row['max_box_shift']:.3e}")
|
|
140
|
+
row["speedup_vs_ort_p50"] = round(statistics.median(times["ort"]) / statistics.median(times[name]), 3)
|
|
141
|
+
row["max_person_diff"] = float(f"{row['max_person_diff']:.3e}")
|
|
142
|
+
row["max_score_diff"] = float(f"{row['max_score_diff']:.3e}")
|
|
143
|
+
row["mismatch_frames"] = row["mismatch_frames"][:20]
|
|
144
|
+
summary["engines"][name] = row
|
|
145
|
+
result["sets"][Path(listing).name] = summary
|
|
146
|
+
print(json.dumps({Path(listing).name: summary}), flush=True)
|
|
147
|
+
Path(a.out).write_text(json.dumps(result, indent=1))
|
|
148
|
+
return 0
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
if __name__ == "__main__":
|
|
152
|
+
sys.exit(main())
|
|
@@ -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.74a44d1fb817"
|
|
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
|
|
|
@@ -52,6 +52,15 @@ cuda = [
|
|
|
52
52
|
"nvidia-nvjitlink==13.4.92",
|
|
53
53
|
]
|
|
54
54
|
|
|
55
|
+
# Plan v7 W8: OpenVINO used directly (the ONNX Runtime OpenVINO plug-in on the
|
|
56
|
+
# pinned ORT does not compile the shipped RF-DETR artifact), installed BESIDE
|
|
57
|
+
# [cpu] on an Intel host with no NVIDIA card: ORT stays loaded as the reference
|
|
58
|
+
# every OpenVINO engine is probed against, and the fallback. Measured on the
|
|
59
|
+
# shipped artifact 2026-11-16: +36% frames/s on the CPU, person scores within
|
|
60
|
+
# 0.0004 of ORT. Serves only when the server asks (CCTV_DETECTOR_BACKEND) and the
|
|
61
|
+
# engine's own parity probe passed on that host.
|
|
62
|
+
openvino = ["openvino==2026.4.1", "openvino-telemetry==2025.2.0"]
|
|
63
|
+
|
|
55
64
|
[tool.uv]
|
|
56
65
|
conflicts = [[{extra = "cpu"}, {extra = "cuda"}]]
|
|
57
66
|
|
|
@@ -90,6 +90,38 @@ class ActorTrackingTest(unittest.TestCase):
|
|
|
90
90
|
self.assertNotEqual(a["epoch"], c["epoch"])
|
|
91
91
|
self.assertNotEqual(a["id"], c["id"])
|
|
92
92
|
|
|
93
|
+
def test_track_record_counts_observations_never_predictions(self):
|
|
94
|
+
who = self.confirmed()
|
|
95
|
+
self.track(1400, [])
|
|
96
|
+
record, = self.journal.track_records("cam_a")
|
|
97
|
+
self.assertEqual((record.actor_id, record.epoch, record.kind), (who["id"], who["epoch"], "person"))
|
|
98
|
+
self.assertEqual((record.first_seen_ms, record.last_seen_ms, record.frames), (1200, 1200, 1))
|
|
99
|
+
self.track(1600, [person(14, .9)])
|
|
100
|
+
record, = self.journal.track_records("cam_a")
|
|
101
|
+
self.assertEqual((record.first_seen_ms, record.last_seen_ms, record.frames), (1200, 1600, 2))
|
|
102
|
+
self.assertEqual(record.box, (14, 20, 40, 100))
|
|
103
|
+
self.assertEqual(record.confidence, .9)
|
|
104
|
+
self.assertIsNone(record.face)
|
|
105
|
+
self.assertEqual(self.journal.track_records("cam_b"), [])
|
|
106
|
+
|
|
107
|
+
def test_track_record_and_its_face_end_with_the_actor_and_survive_restart(self):
|
|
108
|
+
from trillboards_detector.track_records import FaceSlot
|
|
109
|
+
who = self.confirmed()
|
|
110
|
+
face = FaceSlot("face_model", "c" * 64, (0.6, 0.8), "frame_1200", 1200, .7)
|
|
111
|
+
self.assertTrue(self.journal.record_face("cam_a", who["id"], face))
|
|
112
|
+
self.assertFalse(self.journal.record_face("cam_a", "pa_unknown", face))
|
|
113
|
+
self.journal.close()
|
|
114
|
+
self.journal = ActorTrackerJournal(self.path)
|
|
115
|
+
record, = self.journal.track_records("cam_a")
|
|
116
|
+
self.assertEqual(record.face, face)
|
|
117
|
+
self.assertEqual(record.to_wire()["face"]["dims"], 2)
|
|
118
|
+
with self.assertRaises(ValueError):
|
|
119
|
+
FaceSlot.from_wire({**face.to_wire(), "dims": 3})
|
|
120
|
+
reset = self.track(10000)
|
|
121
|
+
self.assertIn(who, reset["endedActors"])
|
|
122
|
+
self.assertEqual(self.journal.track_records("cam_a"), [])
|
|
123
|
+
self.assertFalse(self.journal.record_face("cam_a", who["id"], face))
|
|
124
|
+
|
|
93
125
|
def test_restart_and_bounded_history_preserve_actor(self):
|
|
94
126
|
who = self.confirmed()
|
|
95
127
|
for at in range(1400, 62000, 200):
|
|
@@ -186,6 +218,142 @@ class ActorTrackingTest(unittest.TestCase):
|
|
|
186
218
|
with self.assertRaisesRegex(TrackingError, "Corrupt"):
|
|
187
219
|
self.track(1400)
|
|
188
220
|
|
|
221
|
+
# ── each frame's own records (server.py:669 Codex P2) ────────────────────
|
|
222
|
+
|
|
223
|
+
def track_and_records(self, at, detections=None, **kwargs):
|
|
224
|
+
return self.journal.track_and_records(
|
|
225
|
+
request(at, **kwargs), detections if detections is not None else [person()],
|
|
226
|
+
image_sha256=SHA, model_hashes=MODEL, frame_size=(640, 480))
|
|
227
|
+
|
|
228
|
+
def test_two_interleaved_requests_on_one_camera_each_get_their_own_records(self):
|
|
229
|
+
"""The bug: the server read the records with a second lock acquisition after
|
|
230
|
+
track(), so a request for the camera's next frame could commit in between and this
|
|
231
|
+
frame was answered with the next frame's records. Here the next frame's request is
|
|
232
|
+
started from INSIDE this frame's transaction; it must wait, and each answer must be
|
|
233
|
+
its own frame's."""
|
|
234
|
+
import threading
|
|
235
|
+
self.track(1000)
|
|
236
|
+
original = self.journal._write_track_records
|
|
237
|
+
other = {}
|
|
238
|
+
def write_then_start_the_next_frame(*args):
|
|
239
|
+
original(*args)
|
|
240
|
+
if "thread" not in other:
|
|
241
|
+
other["thread"] = threading.Thread(
|
|
242
|
+
target=lambda: other.setdefault("answer", self.track_and_records(1400, [person(14, .9)])))
|
|
243
|
+
other["thread"].start()
|
|
244
|
+
other["thread"].join(.3) # it cannot get in: this frame still holds the journal
|
|
245
|
+
other["waited"] = other["thread"].is_alive()
|
|
246
|
+
self.journal._write_track_records = write_then_start_the_next_frame
|
|
247
|
+
result, records = self.track_and_records(1200)
|
|
248
|
+
other["thread"].join(10)
|
|
249
|
+
self.journal._write_track_records = original
|
|
250
|
+
self.assertTrue(other["waited"])
|
|
251
|
+
record, = records
|
|
252
|
+
self.assertEqual((record["lastSeenAtMs"], record["frames"], record["box"]["x"]), (1200, 1, 10))
|
|
253
|
+
self.assertEqual(record["actorId"], result["actors"][0]["actor"]["id"])
|
|
254
|
+
_, next_records = other["answer"]
|
|
255
|
+
self.assertEqual((next_records[0]["lastSeenAtMs"], next_records[0]["frames"],
|
|
256
|
+
next_records[0]["box"]["x"]), (1400, 2, 14))
|
|
257
|
+
# The live records moved on; the first answer did not move with them.
|
|
258
|
+
live, = self.journal.track_records("cam_a")
|
|
259
|
+
self.assertEqual((live.last_seen_ms, live.frames), (1400, 2))
|
|
260
|
+
|
|
261
|
+
def test_a_replay_serves_the_frames_own_saved_records_not_the_live_ones(self):
|
|
262
|
+
self.track(1000)
|
|
263
|
+
result, records = self.track_and_records(1200)
|
|
264
|
+
self.track(1400, [person(14, .9)])
|
|
265
|
+
self.assertEqual(self.track_and_records(1200), (result, records))
|
|
266
|
+
self.journal.close()
|
|
267
|
+
self.journal = ActorTrackerJournal(self.path)
|
|
268
|
+
self.assertEqual(self.track_and_records(1200), (result, records))
|
|
269
|
+
self.assertEqual(self.track(1200), result)
|
|
270
|
+
|
|
271
|
+
def test_a_frame_with_no_records_kept_replays_no_records(self):
|
|
272
|
+
"""A frame journalled before the snapshot existed, or by an older build."""
|
|
273
|
+
import sqlite3
|
|
274
|
+
self.track(1000)
|
|
275
|
+
result, records = self.track_and_records(1200)
|
|
276
|
+
self.assertEqual(len(records), 1)
|
|
277
|
+
with sqlite3.connect(self.path) as db:
|
|
278
|
+
db.execute("DELETE FROM actor_frame_records WHERE frame_id='frame_1200'")
|
|
279
|
+
self.assertEqual(self.track_and_records(1200), (result, []))
|
|
280
|
+
|
|
281
|
+
def test_records_kept_for_different_bytes_under_the_same_frame_id_are_not_served(self):
|
|
282
|
+
import sqlite3
|
|
283
|
+
self.track(1000)
|
|
284
|
+
result, _ = self.track_and_records(1200)
|
|
285
|
+
with sqlite3.connect(self.path) as db:
|
|
286
|
+
db.execute("UPDATE actor_frame_records SET fingerprint=? WHERE frame_id='frame_1200'", ("d" * 64,))
|
|
287
|
+
self.assertEqual(self.track_and_records(1200), (result, []))
|
|
288
|
+
|
|
289
|
+
def test_a_journal_from_before_the_snapshot_gains_its_table_and_keeps_its_frames(self):
|
|
290
|
+
import sqlite3
|
|
291
|
+
self.track(1000)
|
|
292
|
+
result, _ = self.track_and_records(1200)
|
|
293
|
+
self.journal.close()
|
|
294
|
+
with sqlite3.connect(self.path) as db:
|
|
295
|
+
db.execute("DROP TABLE actor_frame_records")
|
|
296
|
+
self.journal = ActorTrackerJournal(self.path)
|
|
297
|
+
self.assertEqual(self.track_and_records(1200), (result, []))
|
|
298
|
+
_, records = self.track_and_records(1400)
|
|
299
|
+
self.assertEqual(records[0]["frames"], 2)
|
|
300
|
+
self.assertEqual(self.track_and_records(1400)[1], records)
|
|
301
|
+
|
|
302
|
+
def test_an_older_build_can_still_write_this_journal_after_a_rollback(self):
|
|
303
|
+
"""Older builds insert frames by position (7 values): actor_frame keeps its columns."""
|
|
304
|
+
import sqlite3
|
|
305
|
+
self.track(1000)
|
|
306
|
+
with sqlite3.connect(self.path) as db:
|
|
307
|
+
self.assertEqual([r[1] for r in db.execute("PRAGMA table_info(actor_frame)")],
|
|
308
|
+
["camera_id", "frame_id", "seq", "epoch", "fingerprint", "input_json", "result_json"])
|
|
309
|
+
|
|
310
|
+
def test_records_kept_beside_frames_are_pruned_with_them(self):
|
|
311
|
+
import sqlite3
|
|
312
|
+
for at in range(1000, 1000 + 300 * 200, 200):
|
|
313
|
+
self.track(at)
|
|
314
|
+
with sqlite3.connect(self.path) as db:
|
|
315
|
+
frames = db.execute("SELECT count(*) FROM actor_frame WHERE camera_id='cam_a'").fetchone()[0]
|
|
316
|
+
kept = db.execute("SELECT count(*) FROM actor_frame_records WHERE camera_id='cam_a'").fetchone()[0]
|
|
317
|
+
orphans = db.execute("SELECT count(*) FROM actor_frame_records r WHERE NOT EXISTS (SELECT 1 FROM "
|
|
318
|
+
"actor_frame f WHERE f.camera_id=r.camera_id AND f.frame_id=r.frame_id)").fetchone()[0]
|
|
319
|
+
self.assertLessEqual(frames, 256)
|
|
320
|
+
self.assertEqual((kept, orphans), (frames, 0))
|
|
321
|
+
|
|
322
|
+
def test_a_replay_serves_a_face_only_while_its_actor_still_holds_that_slot(self):
|
|
323
|
+
import sqlite3
|
|
324
|
+
from trillboards_detector.track_records import FaceSlot
|
|
325
|
+
who = self.confirmed()
|
|
326
|
+
face = FaceSlot("face_model", "c" * 64, (0.6, 0.8), "frame_1200", 1200, .7)
|
|
327
|
+
self.assertTrue(self.journal.record_face("cam_a", who["id"], face))
|
|
328
|
+
_, records = self.track_and_records(1400)
|
|
329
|
+
self.assertEqual(records[0]["face"], face.to_wire())
|
|
330
|
+
self.assertEqual(self.track_and_records(1400)[1], records)
|
|
331
|
+
# The journal row keeps the slot's digest, never the vector: a face never
|
|
332
|
+
# outlives its track (track_records.py).
|
|
333
|
+
with sqlite3.connect(self.path) as db:
|
|
334
|
+
stored = db.execute("SELECT records_json FROM actor_frame_records WHERE frame_id='frame_1400'").fetchone()[0]
|
|
335
|
+
self.assertNotIn("0.6", stored)
|
|
336
|
+
self.assertNotIn("face_model", stored)
|
|
337
|
+
# A newer slot on the live record is not the one this frame had.
|
|
338
|
+
newer = FaceSlot("face_model", "c" * 64, (0.8, 0.6), "frame_1400", 1400, .9)
|
|
339
|
+
self.assertTrue(self.journal.record_face("cam_a", who["id"], newer))
|
|
340
|
+
replayed, = self.track_and_records(1400)[1]
|
|
341
|
+
self.assertIsNone(replayed["face"])
|
|
342
|
+
self.assertEqual({k: v for k, v in replayed.items() if k != "face"},
|
|
343
|
+
{k: v for k, v in records[0].items() if k != "face"})
|
|
344
|
+
# And once the actor ends, no replay brings its face back.
|
|
345
|
+
self.assertTrue(self.journal.record_face("cam_a", who["id"], face))
|
|
346
|
+
self.track(10000)
|
|
347
|
+
self.assertIsNone(self.track_and_records(1400)[1][0]["face"])
|
|
348
|
+
|
|
349
|
+
def test_a_corrupt_records_snapshot_is_not_an_idempotent_success(self):
|
|
350
|
+
import sqlite3
|
|
351
|
+
self.confirmed()
|
|
352
|
+
with sqlite3.connect(self.path) as db:
|
|
353
|
+
db.execute("UPDATE actor_frame_records SET records_json='{\"not\":\"a list\"}' WHERE frame_id='frame_1200'")
|
|
354
|
+
with self.assertRaisesRegex(TrackingError, "Corrupt"):
|
|
355
|
+
self.track_and_records(1200)
|
|
356
|
+
|
|
189
357
|
|
|
190
358
|
if __name__ == "__main__":
|
|
191
359
|
unittest.main()
|
|
@@ -81,6 +81,28 @@ class ActorTrackingWireTest(unittest.TestCase):
|
|
|
81
81
|
with urllib.request.urlopen(self.base+"/health") as r:
|
|
82
82
|
self.assertEqual(json.load(r)["actor_tracking"]["state"],"ready")
|
|
83
83
|
|
|
84
|
+
def test_tracked_response_serves_the_live_actor_record_outside_the_proof(self):
|
|
85
|
+
_,first=self.post(1000)
|
|
86
|
+
self.assertEqual(first["tracks"],[])
|
|
87
|
+
_,second=self.post(1200)
|
|
88
|
+
actor=second["tracking"]["actors"][0]["actor"]
|
|
89
|
+
self.assertEqual(second["tracks"],[{"version":1,"actorId":actor["id"],"kind":"person",
|
|
90
|
+
"epoch":actor["epoch"],"firstSeenAtMs":1200,"lastSeenAtMs":1200,"frames":1,
|
|
91
|
+
"box":{"x":10,"y":20,"width":30,"height":80},"confidence":.95,"face":None}])
|
|
92
|
+
self.assertEqual(self.post(1400)[1]["tracks"][0]["frames"],2)
|
|
93
|
+
self.assertNotIn("tracks",self.post(1600,tracking=None)[1])
|
|
94
|
+
|
|
95
|
+
def test_a_replayed_frame_serves_its_own_tracks_not_the_live_ones(self):
|
|
96
|
+
self.post(1000)
|
|
97
|
+
_,second=self.post(1200)
|
|
98
|
+
_,third=self.post(1400)
|
|
99
|
+
self.assertEqual(third["tracks"][0]["frames"],2)
|
|
100
|
+
status,replayed=self.post(1200)
|
|
101
|
+
self.assertEqual(status,200)
|
|
102
|
+
self.assertEqual(replayed["tracking"],second["tracking"])
|
|
103
|
+
self.assertEqual(replayed["tracks"],second["tracks"])
|
|
104
|
+
self.assertEqual(replayed["tracks"][0]["frames"],1)
|
|
105
|
+
|
|
84
106
|
def test_invalid_or_unavailable_tracking_never_becomes_an_empty_scene(self):
|
|
85
107
|
for change in [{"tracking":{}},{"min_confidence":.5},{"expected_model":None},
|
|
86
108
|
{"classes":["cell phone"]}]:
|
|
@@ -13,6 +13,7 @@ property of `/health` — both of which are about `DetectorLoader` specifically.
|
|
|
13
13
|
|
|
14
14
|
from __future__ import annotations
|
|
15
15
|
|
|
16
|
+
import importlib.util
|
|
16
17
|
import unittest
|
|
17
18
|
|
|
18
19
|
try:
|
|
@@ -42,6 +43,30 @@ if HAVE_RUNTIME:
|
|
|
42
43
|
)
|
|
43
44
|
|
|
44
45
|
|
|
46
|
+
# The loader imports on a runner without Pillow or NumPy (guards-fast's detector step); the
|
|
47
|
+
# warm-up frame needs both, so this case skips there on its own, with its reason.
|
|
48
|
+
@unittest.skipUnless(HAVE_RUNTIME and importlib.util.find_spec("numpy") and importlib.util.find_spec("PIL"),
|
|
49
|
+
"onnxruntime/numpy/Pillow are not installed")
|
|
50
|
+
class TestFullSizeWarmup(unittest.TestCase):
|
|
51
|
+
def test_the_warmup_frame_is_a_textured_live_sized_jpeg_at_the_probes_threshold(self):
|
|
52
|
+
import io
|
|
53
|
+
from PIL import Image
|
|
54
|
+
calls = []
|
|
55
|
+
|
|
56
|
+
class Session:
|
|
57
|
+
def detect(self, jpeg, min_confidence, wanted):
|
|
58
|
+
calls.append((jpeg, min_confidence, wanted))
|
|
59
|
+
|
|
60
|
+
DetectorLoader._warm_full_size(Session())
|
|
61
|
+
(jpeg, min_confidence, wanted), = calls
|
|
62
|
+
image = Image.open(io.BytesIO(jpeg))
|
|
63
|
+
self.assertEqual((image.format, image.size), ("JPEG", (640, 480)))
|
|
64
|
+
self.assertEqual((min_confidence, wanted), (0.99, None))
|
|
65
|
+
# Texture, not a flat fill: a flat frame decodes in no time and would warm
|
|
66
|
+
# the forward pass but not the decode a live frame costs.
|
|
67
|
+
self.assertGreater(len(jpeg), 20_000)
|
|
68
|
+
|
|
69
|
+
|
|
45
70
|
@unittest.skipUnless(HAVE_RUNTIME, "onnxruntime/numpy/Pillow are not installed")
|
|
46
71
|
class TestBuildCatalogue(unittest.TestCase):
|
|
47
72
|
def test_non_box_paths_do_not_inherit_the_detector_only_override(self):
|