mirror of
https://github.com/azaion/gps-denied-onboard.git
synced 2026-06-22 15:21:14 +00:00
[AZ-338] [AZ-283] C2 NetVLAD mandatory simple-baseline VprStrategy
NetVLAD is the C2 comparative baseline per the engine rule (every production-default backbone ships with a simple-baseline alongside). Runs on the C7 PyTorch FP16 runtime (NOT TRT) so a TRT engine compile bug cannot simultaneously break NetVLAD AND UltraVPR. Production changes: - c2_vpr/net_vlad.py — NetVladStrategy + module-level create() factory. Constructor wires InferenceRuntimeCut + DescriptorIndexCut + NetVladBackbonePreprocessor + DescriptorNormaliser + FaissBridge. embed_query pipeline: preprocess -> runtime.infer -> dual-stage normalisation (intra-cluster THEN global L2) -> VprQuery. retrieve_topk delegates one-line to FaissBridge. - c2_vpr/_net_vlad_architecture.py — Arandjelovic et al. 2016 NetVLAD layer over torchvision VGG16 features + optional Linear PCA projection to descriptor_dim (default 4096; published Pittsburgh reference uses K*D=64*512=32768 raw + Linear(32768, 4096) PCA). - c2_vpr/_preprocessor_net_vlad.py — OpenCV-based image preprocessor: decode -> centre-crop square -> resize (480, 480) -> ImageNet normalisation -> FP16 NCHW. Calibration is not consumed (NetVLAD is calibration-agnostic per published preprocessing chain). - c2_vpr/inference_runtime_cut.py — NEW AZ-507 consumer-side cut mirroring C7 InferenceRuntime; lets c2_vpr stay AZ-507-clean. - c2_vpr/config.py — added netvlad_descriptor_dim: int = 4096 knob. - helpers/descriptor_normaliser.py — added intra_cluster_normalise (DescriptorNormaliser v1.0.0 -> v1.1.0; backward-compatible add). - runtime_root/vpr_factory.py — added _register_strategy_architecture helper that binds (MODEL_NAME, architecture_factory(descriptor_dim)) to C7's architecture registry before delegating to the strategy's create() factory. Keeps the c7 import at L4, preserves AZ-507. - fdr_client/records.py — registered vpr.embed_query, vpr.backbone_error, vpr.preprocess_error record kinds. Tests: - tests/unit/c2_vpr/test_net_vlad.py — 31 tests covering all 11 ACs + preprocessor contract + architecture factory + constructor validation + FDR record emission. - tests/unit/test_az283_descriptor_normaliser.py — +8 tests for the new intra_cluster_normalise. - tests/unit/test_az272_fdr_record_schema.py — +3 fixture payloads. Full unit suite: 1608 passed / 80 env-skipped (+43 new tests). Per-batch code review (batch_46_review.md): PASS_WITH_WARNINGS (4 Low-severity hygiene findings; no Critical/High/Medium). Architectural notes: - The spec implied c2_vpr.net_vlad.create() registers the architecture with C7. That violates AZ-507 (no cross-component imports). Resolved by exposing MODEL_NAME + architecture_factory(descriptor_dim) on the strategy module and having the composition root perform the C7 bind. - C7 PyTorch runtime API names in the spec (forward, load_engine) were outdated; aligned implementation with the live v1.0.0 Protocol (infer, compile_engine + deserialize_engine). Spec hygiene flagged in review F2. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -314,6 +314,46 @@ KNOWN_PAYLOAD_KEYS: Final[dict[str, frozenset[str]]] = {
|
||||
"latency_us",
|
||||
}
|
||||
),
|
||||
# AZ-338 / E-C2: emitted by each concrete C2 ``VprStrategy`` on every
|
||||
# successful ``embed_query(...)`` call (post-flight forensic record
|
||||
# of the embedding pipeline; complements ``vpr.retrieve_topk`` for the
|
||||
# subsequent FAISS lookup). ``frame_id`` echoes
|
||||
# ``NavCameraFrame.frame_id``; ``backbone_label`` is the strategy's
|
||||
# lowercase ``BUILD_VPR_<variant>`` token (e.g. ``"net_vlad"``);
|
||||
# ``descriptor_dim`` is the strategy's stable embedding dim;
|
||||
# ``latency_us`` is the strategy-internal ``Clock.monotonic_ns``
|
||||
# delta around the backbone forward, in integer microseconds.
|
||||
"vpr.embed_query": frozenset(
|
||||
{
|
||||
"frame_id",
|
||||
"backbone_label",
|
||||
"descriptor_dim",
|
||||
"latency_us",
|
||||
}
|
||||
),
|
||||
# AZ-338 / E-C2: emitted when ``embed_query`` raises a
|
||||
# :class:`VprBackboneError` (forward-pass failure: CUDA OOM, TRT
|
||||
# engine deserialize mismatch, etc.). One record per occurrence;
|
||||
# logged at ERROR alongside.
|
||||
"vpr.backbone_error": frozenset(
|
||||
{
|
||||
"frame_id",
|
||||
"backbone_label",
|
||||
"error_type",
|
||||
"error_message",
|
||||
}
|
||||
),
|
||||
# AZ-338 / E-C2: emitted when ``embed_query`` raises a
|
||||
# :class:`VprPreprocessError` (image decode / shape / dtype
|
||||
# violation in the per-strategy preprocessor).
|
||||
"vpr.preprocess_error": frozenset(
|
||||
{
|
||||
"frame_id",
|
||||
"backbone_label",
|
||||
"error_type",
|
||||
"error_message",
|
||||
}
|
||||
),
|
||||
}
|
||||
|
||||
KNOWN_KINDS: Final[frozenset[str]] = frozenset(KNOWN_PAYLOAD_KEYS.keys())
|
||||
|
||||
Reference in New Issue
Block a user