feat(lab): publish M4.8S fixed-class detector replay

This commit is contained in:
DCCONSTRUCTIONS
2026-08-25 16:44:35 +03:00
parent 05590867b7
commit 3679e43fe3
13 changed files with 1724 additions and 4 deletions
+18
View File
@@ -321,9 +321,27 @@ def canonical_laboratory_adapters() -> dict[str, LaboratoryAdapter]:
"canonical.e35-degradation-recovery/v1": _run_e35,
"canonical.e46j-raw-fisheye-realtime/v1": _run_e46j,
"experimental.e47-semantic-slam-shadow/v1": _run_e47,
"experimental.m48s-fixed-class-detector/v1": _run_m48s_fixed_class_detector,
}
def _run_m48s_fixed_class_detector(
request: LaboratoryRunRequest,
) -> LaboratoryAdapterResult:
from k1link.laboratory.m48s_fixed_class_detector_lab import (
build_m48s_fixed_class_detector_lab,
)
result = build_m48s_fixed_class_detector_lab(
repository_root=request.inputs["repository_root"],
output_root=request.output_root,
)
return LaboratoryAdapterResult(
result_root=result.result_root,
result_id=result.result_id,
)
def _run_m48_small_static_passage_regression(
request: LaboratoryRunRequest,
) -> LaboratoryAdapterResult:
@@ -0,0 +1,892 @@
"""Build the immutable M4.8S fixed-class detector laboratory projection."""
from __future__ import annotations
import hashlib
import json
import shutil
import tempfile
from dataclasses import dataclass
from datetime import UTC, datetime
from pathlib import Path
from typing import Any, Final, cast
from k1link.perception.fixed_class_detector_tournament import (
canonical_json,
false_authority,
sha256_path,
)
LAB_SCHEMA: Final = "missioncore.m48s-fixed-class-detector-lab/v1"
CATALOG_SCHEMA: Final = "missioncore.m48s-fixed-class-detector-frame-catalog/v1"
FRAME_SCHEMA: Final = "missioncore.m48s-fixed-class-detector-frame/v1"
REPORT_SCHEMA: Final = "missioncore.m48s-fixed-class-detector-report/v1"
METHOD_SCHEMA: Final = "missioncore.laboratory-method/v1"
RESULT_PREFIX: Final = "m48s-fixed-class-detector-lab-"
TOURNAMENT_ID: Final = (
"m48s-fixed-detector-tournament-"
"0e61d75e6dc575d53e4bb98772a41d240fe627ad642de5178beb1154636e1299"
)
DEPLOYMENT_ID: Final = (
"m48s-rf-detr-deployment-gate-2feb9e1b12a5588951ad35d63bf23cf6bdd579d54b5329d46d7696f88c444547"
)
REFERENCE_GRAPH_ID: Final = (
"m48s-reference-graph-shadow-gate-"
"e8da7a521768daba0ead1a6e4803871ce3a85f91a7d8ee36c5719ac10433e791"
)
REFERENCE_GRAPH_REPLAY_ID: Final = (
"m48s-reference-graph-replay-"
"16d69d610c22e6f42071b8378cd75dfa6b95db4ceb800f9c7508fa3673504478"
)
INTEGRATED_STATUS: Final = "complete-reference-graph-shadow-passed-production-not-authorized"
YOLOX_ID: Final = (
"m48s-yolox-all-coco-shadow-7dbe6043b3fc12c7ddb162f609f883d86b34a4f2dd3785a632795f257e192d06"
)
SOURCE_SHA256: Final = "cadd1696ff000904eb78633a0a8418104b8024f178b91f3421789021ccb160e8"
ENGINE_SHA256: Final = "986399ce706b7380472cf5e473232249fed6e628971d8007f6609e83128d46b8"
RISK_LABELS: Final = frozenset(
{
"person",
"bicycle",
"car",
"motorcycle",
"bus",
"truck",
"bird",
"cat",
"dog",
"horse",
"sheep",
"cow",
"elephant",
"bear",
"zebra",
"giraffe",
"skateboard",
}
)
FRAME_IDS: Final = (
"000121",
"000131",
"000253",
"000275",
"000443",
"000463",
"001094",
"001228",
"001454",
"001856",
"002386",
)
class M48SFixedClassDetectorLabError(RuntimeError):
"""The sealed detector evidence cannot produce an honest LAB result."""
@dataclass(frozen=True, slots=True)
class M48SFixedClassDetectorLabResult:
result_root: Path
result_id: str
manifest: dict[str, Any]
def build_m48s_fixed_class_detector_lab(
*,
repository_root: Path,
output_root: Path,
) -> M48SFixedClassDetectorLabResult:
repository = repository_root.expanduser().resolve(strict=True)
if not repository.is_dir():
raise M48SFixedClassDetectorLabError("repository root is invalid")
runtime = repository / ".runtime/compute-experiments/m48s-semantic-shadow"
tournament_path = (
runtime / "fixed-detector-tournament-results" / TOURNAMENT_ID / "manifest.json"
)
deployment_root = runtime / "rf-detr-deployment-results" / DEPLOYMENT_ID
deployment_path = deployment_root / "manifest.json"
load_path = deployment_root / "load_result.json"
reference_graph_root = runtime / "reference-graph-shadow-results" / REFERENCE_GRAPH_ID
reference_graph_path = reference_graph_root / "manifest.json"
reference_graph_worker_path = reference_graph_root / "worker-result.json"
reference_graph_replay_root = (
runtime / "reference-graph-replay-results" / REFERENCE_GRAPH_REPLAY_ID
)
reference_graph_replay_path = reference_graph_replay_root / "manifest.json"
reference_graph_replay_worker_path = reference_graph_replay_root / "worker-result.json"
reference_graph_replay_frames_path = reference_graph_replay_root / "frames.jsonl"
yolox_root = runtime / "yolox-all-coco-results" / YOLOX_ID
yolox_manifest_path = yolox_root / "manifest.json"
yolox_frames_path = yolox_root / "frames.jsonl"
candidate_root = runtime / "fixed-detector-tournament-worker"
dfine_path = candidate_root / "dfine-s-worker.json"
rf_detr_path = candidate_root / "rf-detr-large-triton-worker.json"
source_root = runtime / "raw-11-frames-v1"
profile_path = repository / "config/perception/rf-detr-large-risk-shadow-v0.json"
for path in (
tournament_path,
deployment_path,
load_path,
reference_graph_path,
reference_graph_worker_path,
reference_graph_replay_path,
reference_graph_replay_worker_path,
reference_graph_replay_frames_path,
yolox_manifest_path,
yolox_frames_path,
dfine_path,
rf_detr_path,
profile_path,
):
if path.is_symlink() or not path.is_file():
raise M48SFixedClassDetectorLabError(
f"required sealed evidence is missing: {path.name}"
)
tournament = _read_object(tournament_path)
deployment = _read_object(deployment_path)
load = _read_object(load_path)
reference_graph = _read_object(reference_graph_path)
reference_graph_worker = _read_object(reference_graph_worker_path)
reference_graph_replay = _read_object(reference_graph_replay_path)
reference_graph_replay_worker = _read_object(reference_graph_replay_worker_path)
yolox_manifest = _read_object(yolox_manifest_path)
dfine = _read_object(dfine_path)
rf_detr = _read_object(rf_detr_path)
profile = _read_object(profile_path)
yolox_frames = _read_jsonl(yolox_frames_path)
_validate_inputs(
tournament=tournament,
deployment=deployment,
load=load,
reference_graph=reference_graph,
reference_graph_worker=reference_graph_worker,
reference_graph_replay=reference_graph_replay,
reference_graph_replay_worker=reference_graph_replay_worker,
reference_graph_replay_frames_path=reference_graph_replay_frames_path,
yolox_manifest=yolox_manifest,
dfine=dfine,
rf_detr=rf_detr,
profile=profile,
yolox_frames=yolox_frames,
)
source_paths = {frame_id: source_root / f"frame-{frame_id}.jpg" for frame_id in FRAME_IDS}
if any(path.is_symlink() or not path.is_file() for path in source_paths.values()):
raise M48SFixedClassDetectorLabError("the exact 11-frame visual slice is incomplete")
source_descriptors = [
{
"frame_id": frame_id,
"source_sequence": int(frame_id),
"sha256": sha256_path(source_paths[frame_id]),
"byte_length": source_paths[frame_id].stat().st_size,
}
for frame_id in FRAME_IDS
]
method = _method(
profile=profile,
tournament=tournament,
deployment=deployment,
reference_graph=reference_graph,
)
identity = {
"schema_version": LAB_SCHEMA,
"source": {
"source_session_id": "RAVNOVES00",
"recording_sha256": SOURCE_SHA256,
"camera_source_id": "sensor.camera.right",
"camera_raster": [800, 600],
"evidence_frame_count": len(FRAME_IDS),
"replay_frame_count": 4489,
"frames": source_descriptors,
},
"configuration": {
"comparison_threshold": 0.5,
"display_modes": ["source", "yolox", "dfine", "rf-detr"],
"replay_display_modes": ["video", "camera", "3d", "plan"],
"camera_point_overlay": "factory-kb4-exact",
"world_state_delivery": "source-paced-latest-wins",
"single_inference_per_frame": True,
"risk_labels": sorted(RISK_LABELS),
"geometry_owns_static_occupancy": True,
"unknown_stationary_response": "route-around",
"unknown_moving_response": "conservative-risk",
},
"inputs": {
"tournament_result_id": TOURNAMENT_ID,
"tournament_document_sha256": sha256_path(tournament_path),
"deployment_result_id": DEPLOYMENT_ID,
"deployment_document_sha256": sha256_path(deployment_path),
"reference_graph_result_id": REFERENCE_GRAPH_ID,
"reference_graph_document_sha256": sha256_path(reference_graph_path),
"reference_graph_worker_sha256": sha256_path(reference_graph_worker_path),
"reference_graph_replay_result_id": REFERENCE_GRAPH_REPLAY_ID,
"reference_graph_replay_document_sha256": sha256_path(
reference_graph_replay_path
),
"reference_graph_replay_worker_sha256": sha256_path(
reference_graph_replay_worker_path
),
"reference_graph_replay_frames_sha256": sha256_path(
reference_graph_replay_frames_path
),
"yolox_result_id": YOLOX_ID,
"yolox_document_sha256": sha256_path(yolox_manifest_path),
},
"method": method,
"authority": false_authority(),
}
identity_sha256 = hashlib.sha256(canonical_json(identity)).hexdigest()
result_id = RESULT_PREFIX + identity_sha256
completed_utc_ns = reference_graph_replay_worker.get("completed_utc_ns")
if not isinstance(completed_utc_ns, int) or isinstance(completed_utc_ns, bool):
raise M48SFixedClassDetectorLabError(
"complete reference-graph completion time is unavailable"
)
created_at_utc = (
datetime.fromtimestamp(completed_utc_ns / 1_000_000_000, UTC)
.isoformat(timespec="microseconds")
.replace("+00:00", "Z")
)
candidates = _candidate_summaries(
tournament=tournament,
yolox_manifest=yolox_manifest,
dfine=dfine,
rf_detr=rf_detr,
deployment=deployment,
)
metrics = _metrics(
deployment=deployment,
load=load,
reference_graph=reference_graph,
candidates=candidates,
)
decision = {
"bounded_question_accepted": True,
"selected_candidate": "rf-detr",
"ready_for_reference_graph_shadow": True,
"integrated_world_state_gate_evaluated": True,
"integrated_world_state_gate_passed": True,
"full_replay_visual_published": True,
"detector_replacement_authorized": False,
"production_accepted": False,
}
limitations = [
"The 11-frame slice is diagnostic and has no independent semantic ground truth.",
(
"The complete reference-graph replay qualifies runtime behavior, but has no "
"independent track-identity or risk-policy truth."
),
"COCO has no dedicated scooter class; unknown moving objects remain conservative hazards.",
(
"Camera boxes do not replace geometry-owned occupancy or grant navigation/safety "
"authority."
),
(
"Eight source frames were superseded by the qualified latest-wins graph; their "
"camera/LiDAR source evidence remains visible without invented world state."
),
]
root = output_root.expanduser().absolute()
root.mkdir(mode=0o700, parents=True, exist_ok=True)
destination = root / result_id
if destination.exists():
raise M48SFixedClassDetectorLabError("immutable M4.8S LAB result already exists")
temporary = Path(tempfile.mkdtemp(prefix=".m48s-fixed-class-lab-", dir=root))
try:
(temporary / "frames").mkdir(mode=0o700)
yolox_by_frame = _yolox_by_frame(yolox_frames)
dfine_by_frame = _worker_by_frame(dfine)
rf_detr_by_frame = _worker_by_frame(rf_detr)
frame_descriptors: list[dict[str, object]] = []
for frame_id in FRAME_IDS:
camera_name = f"frames/frame-{frame_id}.jpg"
detail_name = f"frame-{frame_id}.json"
camera_path = temporary / camera_name
shutil.copyfile(source_paths[frame_id], camera_path)
detections_by_model: dict[str, list[dict[str, object]]] = {
"yolox": _qualified(yolox_by_frame[frame_id]),
"dfine": _qualified(dfine_by_frame[frame_id]),
"rf-detr": _qualified(rf_detr_by_frame[frame_id]),
}
frame_document = {
"schema_version": FRAME_SCHEMA,
"result_id": result_id,
"frame_id": frame_id,
"source_sequence": int(frame_id),
"camera": {
"path": camera_name,
"media_type": "image/jpeg",
"width": 800,
"height": 600,
"sha256": sha256_path(camera_path),
"exact_source_frame": True,
},
"comparison_threshold": 0.5,
"detections": detections_by_model,
"ground_truth_available": False,
"authority": false_authority(),
}
detail_path = temporary / detail_name
detail_path.write_bytes(canonical_json(frame_document) + b"\n")
frame_descriptors.append(
{
"frame_id": frame_id,
"source_sequence": int(frame_id),
"camera_path": camera_name,
"camera_sha256": sha256_path(camera_path),
"camera_byte_length": camera_path.stat().st_size,
"detail_path": detail_name,
"detail_sha256": sha256_path(detail_path),
"detail_byte_length": detail_path.stat().st_size,
"counts": {key: len(value) for key, value in detections_by_model.items()},
}
)
catalog = {
"schema_version": CATALOG_SCHEMA,
"result_id": result_id,
"frame_count": len(frame_descriptors),
"frames": frame_descriptors,
}
catalog_path = temporary / "catalog.json"
catalog_path.write_bytes(canonical_json(catalog) + b"\n")
shutil.copyfile(tournament_path, temporary / "tournament.json")
shutil.copyfile(deployment_path, temporary / "deployment.json")
shutil.copyfile(reference_graph_path, temporary / "reference-graph.json")
shutil.copyfile(
reference_graph_worker_path,
temporary / "reference-graph-worker-result.json",
)
shutil.copyfile(
reference_graph_replay_path,
temporary / "reference-graph-replay.json",
)
shutil.copyfile(
reference_graph_replay_worker_path,
temporary / "reference-graph-replay-worker-result.json",
)
shutil.copyfile(
reference_graph_replay_frames_path,
temporary / "reference-graph-replay-frames.jsonl",
)
report = {
"schema_version": REPORT_SCHEMA,
"result_id": result_id,
"source": identity["source"],
"configuration": identity["configuration"],
"method": method,
"execution": {
"detector_load": load["execution"],
"complete_reference_graph": reference_graph["identity"]["evidence"]["execution"],
},
"metrics": metrics,
"acceptance": {
"detector_load": load["checks"],
"complete_reference_graph": reference_graph["identity"]["evidence"]["checks"],
},
"decision": decision,
"limitations": limitations,
"authority": false_authority(),
"visual_evidence": {
"kind": "full-reference-graph-recorded-replay",
"frame_count": 4489,
"world_state_frame_count": 4481,
"superseded_frame_count": 8,
"modes": ["video", "camera", "3d", "plan"],
"camera_layers": ["rf-detr", "points"],
"ground_truth": False,
},
}
report_path = temporary / "report.json"
report_path.write_bytes(canonical_json(report) + b"\n")
artifacts = _artifact_manifest(temporary)
manifest = {
"schema_version": LAB_SCHEMA,
"result_id": result_id,
"identity_sha256": identity_sha256,
"identity": identity,
"created_at_utc": created_at_utc,
"status": INTEGRATED_STATUS,
"completed": True,
"bounded_question_accepted": True,
"ground_truth": False,
"catalog": {
"path": "catalog.json",
"sha256": sha256_path(catalog_path),
"byte_length": catalog_path.stat().st_size,
},
"method": method,
"metrics": metrics,
"decision": decision,
"limitations": limitations,
"authority": false_authority(),
"artifacts": artifacts,
}
(temporary / "manifest.json").write_bytes(canonical_json(manifest) + b"\n")
temporary.replace(destination)
except BaseException:
shutil.rmtree(temporary, ignore_errors=True)
raise
return M48SFixedClassDetectorLabResult(
result_root=destination,
result_id=result_id,
manifest=manifest,
)
def _validate_inputs(
*,
tournament: dict[str, Any],
deployment: dict[str, Any],
load: dict[str, Any],
reference_graph: dict[str, Any],
reference_graph_worker: dict[str, Any],
reference_graph_replay: dict[str, Any],
reference_graph_replay_worker: dict[str, Any],
reference_graph_replay_frames_path: Path,
yolox_manifest: dict[str, Any],
dfine: dict[str, Any],
rf_detr: dict[str, Any],
profile: dict[str, Any],
yolox_frames: list[dict[str, Any]],
) -> None:
decision = deployment.get("decision")
graph_identity = reference_graph.get("identity")
graph_artifacts = reference_graph.get("artifacts")
graph_decision = graph_identity.get("decision") if isinstance(graph_identity, dict) else None
graph_checks = reference_graph_worker.get("checks")
replay_identity = reference_graph_replay.get("identity")
replay_artifacts = reference_graph_replay.get("artifacts")
replay_frame_summary = (
replay_identity.get("evidence", {}).get("frame_summary")
if isinstance(replay_identity, dict)
and isinstance(replay_identity.get("evidence"), dict)
else None
)
if (
tournament.get("result_id") != TOURNAMENT_ID
or tournament.get("accepted") is not False
or deployment.get("result_id") != DEPLOYMENT_ID
or deployment.get("accepted") is not False
or not isinstance(decision, dict)
or decision.get("ready_for_reference_graph_shadow") is not True
or decision.get("production_accepted") is not False
or load.get("detector_load_gate_passed") is not True
or load.get("candidate_accepted") is not False
or reference_graph.get("result_id") != REFERENCE_GRAPH_ID
or reference_graph.get("schema_version")
!= "missioncore.m48s-reference-graph-shadow-gate/v0"
or not isinstance(graph_identity, dict)
or graph_identity.get("graph_id") != "reference-perception-graph/v2"
or graph_identity.get("accepted") is not True
or graph_identity.get("production_accepted") is not False
or graph_identity.get("authority") != false_authority()
or not isinstance(graph_decision, dict)
or graph_decision.get("complete_reference_graph_shadow_passed") is not True
or graph_decision.get("source_paced_runtime_gate_accepted") is not True
or graph_decision.get("detector_replacement_authorized") is not False
or graph_decision.get("production_accepted") is not False
or not isinstance(graph_artifacts, dict)
or graph_artifacts.get("worker-result.json")
!= hashlib.sha256(canonical_json(reference_graph_worker) + b"\n").hexdigest()
or reference_graph_worker.get("completed") is not True
or reference_graph_worker.get("integrated_runtime_gate_passed") is not True
or reference_graph_worker.get("production_accepted") is not False
or reference_graph_worker.get("authority") != false_authority()
or not isinstance(graph_checks, dict)
or not graph_checks
or not all(value is True for value in graph_checks.values())
or reference_graph_replay.get("result_id") != REFERENCE_GRAPH_REPLAY_ID
or reference_graph_replay.get("schema_version")
!= "missioncore.m48s-reference-graph-replay/v0"
or not isinstance(replay_identity, dict)
or replay_identity.get("accepted") is not True
or replay_identity.get("production_accepted") is not False
or replay_identity.get("authority") != false_authority()
or not isinstance(replay_frame_summary, dict)
or replay_frame_summary.get("source_frame_count") != 4489
or replay_frame_summary.get("world_state_frame_count") != 4481
or replay_frame_summary.get("superseded_frame_count") != 8
or not isinstance(replay_artifacts, dict)
or not isinstance(replay_artifacts.get("frames.jsonl"), dict)
or replay_artifacts["frames.jsonl"].get("sha256")
!= sha256_path(reference_graph_replay_frames_path)
or not isinstance(replay_artifacts.get("worker-result.json"), dict)
or replay_artifacts["worker-result.json"].get("sha256")
!= hashlib.sha256(canonical_json(reference_graph_replay_worker) + b"\n").hexdigest()
or reference_graph_replay_worker.get("integrated_runtime_gate_passed") is not True
or reference_graph_replay_worker.get("production_accepted") is not False
or reference_graph_replay_worker.get("authority") != false_authority()
or yolox_manifest.get("result_id") != YOLOX_ID
or dfine.get("profile_id") != "dfine-s-coco-640-fp16/v0"
or rf_detr.get("profile_id") != "rf-detr-large-coco-704-trt11-fp16/v0"
or rf_detr.get("engine_sha256") != ENGINE_SHA256
or profile.get("profile_id") != "rf-detr-large-coco-704-trt11-fp16-risk-shadow/v0"
or len(yolox_frames) != len(FRAME_IDS)
):
raise M48SFixedClassDetectorLabError("sealed M4.8S evidence identity changed")
for document in (
tournament,
deployment,
load,
reference_graph_worker,
reference_graph_replay_worker,
dfine,
rf_detr,
profile,
):
authority = document.get("authority")
if authority is not None and authority != false_authority():
raise M48SFixedClassDetectorLabError("sealed M4.8S evidence gained authority")
def _method(
*,
profile: dict[str, Any],
tournament: dict[str, Any],
deployment: dict[str, Any],
reference_graph: dict[str, Any],
) -> dict[str, object]:
candidates = tournament["candidates"]
if not isinstance(candidates, dict):
raise M48SFixedClassDetectorLabError("tournament candidates are unavailable")
dfine = candidates["dfine-s-coco-640-fp16/v0"]
rf_detr = candidates["rf-detr-large-coco-704-fp16/v0"]
if not isinstance(dfine, dict) or not isinstance(rf_detr, dict):
raise M48SFixedClassDetectorLabError("tournament candidates are invalid")
return {
"schema_version": METHOD_SCHEMA,
"completeness": "complete",
"execution_class": "ai-inference",
"pipeline_id": "raw-kb4-rf-detr-reference-graph-shadow/v1",
"components": [
{
"kind": "source",
"name": "RAVNOVES00 RIGHT",
"version": "immutable recorded source",
"role": "11-frame visual slice and 30-minute source-paced replay",
"identity_sha256": SOURCE_SHA256,
},
{
"kind": "model",
"name": "YOLOX-S COCO-80",
"version": "triton-yolox-s-raw-kb4-all-coco/v2",
"role": "regression baseline",
"identity_sha256": (
"c5c2d13e59ae883e6af3b45daea64af4833a4951c92d116ec270d9ddbe998063"
),
},
{
"kind": "model",
"name": "D-FINE-S COCO",
"version": str(dfine["upstream_revision"]),
"role": "fixed-class tournament candidate",
"identity_sha256": str(dfine["checkpoint_sha256"]),
},
{
"kind": "model",
"name": "RF-DETR-L COCO",
"version": str(rf_detr["upstream_revision"]),
"role": "selected fixed-class risk detector",
"identity_sha256": str(rf_detr["checkpoint_sha256"]),
},
{
"kind": "runtime",
"name": "TensorRT 11 + isolated Triton",
"version": "worker-006 RTX 4090 strongly-typed-fp16",
"role": "numeric parity and source-paced load qualification",
"identity_sha256": str(deployment["evidence"]["engine_sha256"]),
},
{
"kind": "algorithm",
"name": "risk-only fixed-class qualification",
"version": str(profile["profile_id"]),
"role": "emit behavior-relevant semantics while geometry owns static occupancy",
"identity_sha256": hashlib.sha256(canonical_json(profile)).hexdigest(),
},
{
"kind": "algorithm",
"name": "reference perception graph",
"version": str(reference_graph["identity"]["graph_id"]),
"role": (
"geometry, temporal identity, motion, rolling occupancy, threat, "
"and class advisory"
),
"identity_sha256": str(
reference_graph["identity"]["evidence"]["files"]["graph_config"]["sha256"]
),
},
],
}
def _candidate_summaries(
*,
tournament: dict[str, Any],
yolox_manifest: dict[str, Any],
dfine: dict[str, Any],
rf_detr: dict[str, Any],
deployment: dict[str, Any],
) -> list[dict[str, object]]:
baseline = tournament["baseline"]
candidates = tournament["candidates"]
triton_benchmark = deployment["evidence"]["triton_benchmark"]
if not isinstance(baseline, dict) or not isinstance(candidates, dict):
raise M48SFixedClassDetectorLabError("tournament summaries are invalid")
return [
{
"id": "yolox",
"label": "YOLOX-S",
"provider_id": baseline["provider_id"],
"capacity_fps": yolox_manifest["metrics"]["all_coco_core_capacity_fps"],
"p95_ms": yolox_manifest["metrics"]["timing_ms"]["all_coco_core_ms"]["p95"],
"frame_253_dog_detected": False,
"frame_253_dog_score": None,
"selected": False,
},
{
"id": "dfine",
"label": "D-FINE-S",
"provider_id": dfine["provider_id"],
"capacity_fps": dfine["metrics"]["benchmark"]["core_capacity_fps"],
"p95_ms": dfine["metrics"]["benchmark"]["timing_ms"]["p95"],
"frame_253_dog_detected": False,
"frame_253_dog_score": None,
"selected": False,
},
{
"id": "rf-detr",
"label": "RF-DETR-L",
"provider_id": rf_detr["provider_id"],
"capacity_fps": triton_benchmark["end_to_end_capacity_fps"],
"p95_ms": triton_benchmark["timing_ms"]["p95"],
"frame_253_dog_detected": True,
"frame_253_dog_score": deployment["evidence"]["tensorrt_parity"]["tensorrt_score"],
"selected": True,
},
]
def _metrics(
*,
deployment: dict[str, Any],
load: dict[str, Any],
reference_graph: dict[str, Any],
candidates: list[dict[str, object]],
) -> dict[str, object]:
graph_evidence = reference_graph["identity"]["evidence"]
graph_execution = graph_evidence["execution"]
graph_completion = graph_evidence["world_state_completion_age_ms"]
map_age = graph_evidence["local_obstacle_map_output_age_ms"]
gpu = graph_evidence["gpu"]
identity = graph_evidence["identity_continuity"]
advisory = graph_evidence["semantic_advisory"]
terminal_outcomes = graph_execution["terminal_outcomes"]
return {
"candidate_count": len(candidates),
"evidence_frame_count": len(FRAME_IDS),
"selected_candidate": "rf-detr",
"candidates": candidates,
"tensorrt_parity": deployment["evidence"]["tensorrt_parity"],
"detector_load": {
"duration_seconds": load["execution"]["wall_seconds"],
"source_frames_consumed": load["execution"]["source_frames_consumed"],
"source_frame_replacements": load["execution"]["source_frame_replacements"],
"effective_consumed_fps": load["execution"]["effective_consumed_fps"],
"end_to_end_p95_ms": load["metrics"]["end_to_end_ms"]["p95"],
"completion_age_p95_ms": load["metrics"]["detector_completion_age_ms"]["p95"],
"gpu_utilization_mean_percent": load["metrics"]["gpu"]["gpu_utilization_percent"][
"mean"
],
"gpu_utilization_maximum_percent": load["metrics"]["gpu"]["gpu_utilization_percent"][
"maximum"
],
"gpu_memory_maximum_mib": load["metrics"]["gpu"]["gpu_memory_used_mib"]["maximum"],
"queue_maximum_depth": load["execution"]["queue_maximum_depth"],
"queue_capacity": load["execution"]["queue_capacity"],
"failures": load["execution"]["failures"],
},
"integrated_world_state": {
"duration_seconds": graph_execution["source_processing_wall_seconds"],
"source_frames_admitted": graph_execution["admitted_frames"],
"delivered_world_states": graph_execution["delivered_world_states"],
"superseded_frames": terminal_outcomes["superseded"],
"effective_world_state_fps": graph_execution["effective_world_state_fps"],
"world_state_completion_age_p95_ms": graph_completion["p95"],
"world_state_completion_age_p99_ms": graph_completion["p99"],
"world_state_completion_age_maximum_ms": graph_completion["maximum"],
"local_obstacle_map_output_age_p95_ms": map_age["p95"],
"queue_high_watermarks": graph_execution["queue_high_watermarks"],
"queue_capacity": 2,
"gpu_utilization_mean_percent": gpu["gpu_utilization_percent"]["mean"],
"gpu_utilization_maximum_percent": gpu["gpu_utilization_percent"]["maximum"],
"gpu_memory_maximum_mib": gpu["gpu_memory_used_mib"]["maximum"],
"gpu_power_maximum_w": gpu["gpu_power_w"]["maximum"],
"gpu_temperature_maximum_c": gpu["gpu_temperature_c"]["maximum"],
"unique_component_count": identity["unique_component_count"],
"multi_frame_component_count": identity["multi_frame_component_count"],
"maximum_component_publications": identity["maximum_component_publications"],
"duplicate_component_ids_within_frame": identity[
"duplicate_component_ids_within_frame"
],
"advisory_family_counts": advisory["advisory_family_counts"],
"semantic_hint_counts": advisory["semantic_hint_counts"],
"motion_counts": advisory["motion_counts"],
"additional_inference_passes": advisory["additional_inference_passes"],
"failures": sum(
terminal_outcomes.get(key, 0)
for key in ("failed", "stale", "rejected", "unavailable")
),
},
}
def _qualified(detections: list[dict[str, Any]]) -> list[dict[str, object]]:
result: list[dict[str, object]] = []
for detection in detections:
label = detection.get("label")
score = detection.get("score")
bbox = detection.get("bbox_xyxy")
if (
label not in RISK_LABELS
or not isinstance(score, (int, float))
or isinstance(score, bool)
or float(score) < 0.5
or not isinstance(bbox, list)
or len(bbox) != 4
or not all(isinstance(value, (int, float)) for value in bbox)
):
continue
result.append(
{
"label": label,
"score": round(float(score), 6),
"bbox_xyxy": [round(float(value), 3) for value in bbox],
}
)
result.sort(key=lambda item: (-cast(float, item["score"]), str(item["label"])))
return result
def _yolox_by_frame(rows: list[dict[str, Any]]) -> dict[str, list[dict[str, Any]]]:
result: dict[str, list[dict[str, Any]]] = {}
for row in rows:
frame_id = _frame_id(row.get("frame_name"))
detections = row.get("all_coco_detections")
if frame_id is None or not isinstance(detections, list):
raise M48SFixedClassDetectorLabError("YOLOX frame evidence is invalid")
result[frame_id] = _objects(detections, "YOLOX detections")
if tuple(sorted(result)) != tuple(sorted(FRAME_IDS)):
raise M48SFixedClassDetectorLabError("YOLOX frame slice changed")
return result
def _worker_by_frame(document: dict[str, Any]) -> dict[str, list[dict[str, Any]]]:
frames = document.get("frames")
if not isinstance(frames, list):
raise M48SFixedClassDetectorLabError("candidate frame evidence is invalid")
result: dict[str, list[dict[str, Any]]] = {}
for row in _objects(frames, "candidate frames"):
frame_id = _frame_id(row.get("frame_name"))
detections = row.get("detections")
if frame_id is None or not isinstance(detections, list):
raise M48SFixedClassDetectorLabError("candidate frame evidence is invalid")
result[frame_id] = _objects(detections, "candidate detections")
if tuple(sorted(result)) != tuple(sorted(FRAME_IDS)):
raise M48SFixedClassDetectorLabError("candidate frame slice changed")
return result
def _frame_id(value: object) -> str | None:
if not isinstance(value, str) or not value.startswith("frame-"):
return None
stem = Path(value).stem
frame_id = stem.removeprefix("frame-")
return frame_id if frame_id in FRAME_IDS else None
def _artifact_manifest(root: Path) -> list[dict[str, object]]:
artifacts: list[dict[str, object]] = []
for path in sorted(item for item in root.rglob("*") if item.is_file()):
relative = path.relative_to(root).as_posix()
if relative == "manifest.json":
continue
media_type = "application/json"
schema_version: str | None = None
role = "supporting-evidence"
if relative.endswith(".jpg"):
media_type = "image/jpeg"
role = "visual-evidence-camera"
elif relative.startswith("frame-"):
schema_version = FRAME_SCHEMA
role = "visual-evidence-frame"
elif relative == "catalog.json":
schema_version = CATALOG_SCHEMA
role = "visual-evidence-catalog"
elif relative == "report.json":
schema_version = REPORT_SCHEMA
role = "laboratory-report"
elif relative == "tournament.json":
role = "upstream-tournament-evidence"
elif relative == "deployment.json":
role = "upstream-deployment-evidence"
elif relative == "reference-graph.json":
role = "upstream-reference-graph-evidence"
elif relative == "reference-graph-worker-result.json":
role = "upstream-reference-graph-worker-evidence"
elif relative == "reference-graph-replay.json":
role = "upstream-full-replay-evidence"
elif relative == "reference-graph-replay-worker-result.json":
role = "upstream-full-replay-worker-evidence"
elif relative == "reference-graph-replay-frames.jsonl":
media_type = "application/x-ndjson"
schema_version = "missioncore.m48s-reference-graph-frame-evidence/v0"
role = "visual-evidence-full-replay-world-state"
artifacts.append(
{
"role": role,
"path": relative,
"byte_length": path.stat().st_size,
"sha256": sha256_path(path),
"media_type": media_type,
"schema_version": schema_version,
}
)
return artifacts
def _read_object(path: Path) -> dict[str, Any]:
try:
value = json.loads(path.read_text("utf-8"))
except (OSError, json.JSONDecodeError) as exc:
raise M48SFixedClassDetectorLabError(f"invalid JSON evidence: {path.name}") from exc
if not isinstance(value, dict):
raise M48SFixedClassDetectorLabError(f"JSON evidence must be an object: {path.name}")
return value
def _read_jsonl(path: Path) -> list[dict[str, Any]]:
try:
rows = [json.loads(line) for line in path.read_text("utf-8").splitlines() if line]
except (OSError, json.JSONDecodeError) as exc:
raise M48SFixedClassDetectorLabError("invalid YOLOX frame evidence") from exc
return _objects(rows, "YOLOX frame evidence")
def _objects(value: list[object], label: str) -> list[dict[str, Any]]:
if not all(isinstance(item, dict) for item in value):
raise M48SFixedClassDetectorLabError(f"{label} must contain objects")
return [item for item in value if isinstance(item, dict)]
__all__ = [
"CATALOG_SCHEMA",
"FRAME_SCHEMA",
"LAB_SCHEMA",
"REPORT_SCHEMA",
"RESULT_PREFIX",
"M48SFixedClassDetectorLabError",
"M48SFixedClassDetectorLabResult",
"build_m48s_fixed_class_detector_lab",
]