#pragma once #include "inference/backend_config.hpp" #include inline const std::string kDefaultDetectorModel = std::string(SAE_MODELS_DIR) + "/scrfd_500m_bnkps.onnx"; inline const std::string kDefaultArcfaceModel = std::string(SAE_MODELS_DIR) + "/LVFace-B_Glint360K.onnx"; inline const std::string kDefaultSceneModel = std::string(SAE_MODELS_DIR) + "/transnetv2.onnx"; enum class Verbosity { minimal, // actor names + merged time windows only standard, // per-frame detail: bbox, similarity, unknowns logged xray, // Jellyfin-Xray format: {"second": ["Actor", ...], ...} }; // How a track's accepted frames become a reported presence window. enum class PresenceMode { // A claim IS its track's [first_seen, last_seen] (AR-012/AR-013). The // default and the only mode whose semantics the register validated. track_extent, // Flood-fill: snap each claim to the shot it sits in, so an actor seen once // anywhere in a scene is reported for the whole scene [prev_boundary, // next_boundary]. Trades precision for recall against X-Ray's per-scene cast // granularity. Snaps to TransNetV2 shot boundaries (is_scene_boundary) when a // scene detector populated them, else to the always-on histogram cuts // (is_cut). With no boundaries at all it degrades to track_extent per claim. flood, }; // debug verbosity = compile with -DSAE_DEBUG → scene_analyze_debug binary struct Config { // ── Input ───────────────────────────────────────────────────────────────── std::string movie_path; std::string gallery_path; // TRACES: IR-002 | SR-003 // "global" (matched against the whole library) or "limited" (this title's // credited cast only). The strongest single quality signal when two // manifests compete for the same cut: identical gallery_size can mean very // different recall depending on which was used. std::string gallery_scope{"global"}; // gallery.json produced by build_gallery // ── Output ─────────────────────────────────────────────────────────────── std::string output_path; // annotations.json Verbosity verbosity{Verbosity::minimal}; // When set, tee the embedder output to an HDF5 dump (schema: // scripts/optimizer/SCHEMA.md) for offline threshold-sweep replay via sae_kpn. std::string dump_embeddings_path; /// TRACES: VR-015 | PR-004 // When set, write a per-node timing and bottleneck report here (src/ // benchmark.hpp) and print it at shutdown. Costs one background thread // reading relaxed atomics on a timer, so it is safe to leave on, but a // measurement run should still be isolated (nothing else on the GPU). std::string benchmark_path; int benchmark_interval_ms{100}; // channel-occupancy sampling period // ── Sampling ───────────────────────────────────────────────────────────── float sample_fps{1.0f}; // frames to analyse per second of movie float max_decode_fps{0.f}; // wall-clock cap on source decode rate (0 = uncapped) double start_sec{0.0}; // seek to this timestamp before sampling double end_sec{-1.0}; // stop at this timestamp (-1 = end of file) // ── Detection (SCRFD-500MF via cv::dnn::Net) ────────────────────────────── std::string detector_model; std::string detector_engine; // optional path to pre-built TRT engine; bypasses ORT // TRACES: AR-003 | SR-002 // 0 = no cap, the default. A fixed cap discards the SMALLEST faces first, // which are exactly the background cast X-Ray still credits with scene // membership. Per-frame cost is contained by backpressure (AR-004) rather // than by throwing work away. Set >0 only to bound a pathological source. int max_faces{0}; float min_face_px{40.f}; // discard detections narrower or shorter than this float detector_conf{0.5f}; float detector_nms{0.4f}; /// TRACES: GR-004 | SR-001 // Gallery ↔ embedder binding. A gallery built with a different model than the // one loaded here is a hard error, always. This flag additionally promotes // "cannot prove they match" (unstamped legacy gallery, or a name-only match // because the ONNX could not be hashed) from a loud warning to a hard error. // Also settable via SAE_REQUIRE_GALLERY_STAMP=1. Measurement runs want it on. bool require_gallery_stamp{false}; // --require-gallery-stamp // ── Recognition (ArcFace ONNX) ──────────────────────────────────────────── std::string arcface_model; std::string arcface_engine; // optional path to a pre-built TRT engine; bypasses ORT int embed_batch_size{4}; // max faces per ORT Run() call — bounds per-call latency float match_prior{0.5f}; // base-rate prior; 0.5 = use calibrated sigmoid directly // Tuned by Differential Evolution against Amazon X-Ray per-second presence // over the 4-film rep4 matrix. Best model+mode: LVFace-B_Glint360K, full // gallery, expansion on. Supersedes an earlier 9-film scene-union tuning // (0.76); that metric hid out-of-cast false positives. // // **Read the provenance before trusting the value.** Two things about it: // // 1. The document it came from no longer exists under that name. It was // docs/rep4-optimizer-results.md, renamed to docs/model-bakeoff.md and // then rewritten (0bd2747). This comment pointed at the dead path for // long enough that the number looked unsourced. The original is still // readable at `git show d340da7:docs/rep4-optimizer-results.md`, where // the shipped triple appears as // `prob_threshold=0.754, anneal_sec=35.5`. // // 2. **0.754 predates a scoring bug fix and was never re-derived.** That // same rewrite reports finding "a real scoring bug in optimize.py: a // candidate whose hardest film's replay timed out was averaged over // survivors instead of penalized, silently rewarding partial coverage. // Affected 3 of 16 training combos". The corrected sweep converged // somewhere else — the surviving document records anneal_sec=59.2, // extinction_sec=59.2 against the 35.5/57.4 shipped alongside this // threshold — and no corrected prob_threshold is recorded anywhere. // (The other two constants are now withdrawn outright, which is why // only this one still matters.) // // The doc is also candid that the optimum "generalizes unevenly — strong on // 3 of 5 held-out films, badly broken on 2 (one with a 974-count misID // blowup)", and that it is shipped anyway because it still beats the old // defaults on average. That is a defensible call and not a settled, // film-agnostic optimum; it should be visible here rather than only in a // document this comment used to point at incorrectly. float prob_threshold{0.754f}; // posterior P(match | sim, prior) threshold // TRACES: AR-024 | SR-002 // match_threshold (0.45), match_ratio (0.80) and match_ratio_ceil (0.65) are // RETIRED, joining track_max_embed_dist, cut_revive_sim, expand_novelty_sim // and expand_track_spread_max. All were raw cosine distances, and they were // the accept rule whenever the calibration fit failed — so the one situation // in which the pipeline knew its probabilities were untrustworthy was the // one in which it stopped using them. An unfitted sigmoid is now the // fallback everywhere, which is at least the same wrong number in every // stage. See identity_matcher_node.hpp. // ── Presence derivation ────────────────────────────────────────────────── // How accepted frames become a reported window. flood requires scene_detect. PresenceMode presence_mode{PresenceMode::track_extent}; // ── Cut detection ──────────────────────────────────────────────────────── float cut_threshold{0.70f}; // grayscale histogram correlation below this → hard cut // ── Scene detection (TransNetV2, opt-in) ───────────────────────────────── // When enabled, the source decodes densely (native FPS) and a decimator // splits the stream: full-res 1-FPS frames to the face pipeline, and a // downscaled dense stream to the TransNetV2 scene detector. Shot boundaries // it finds are surfaced as Frame::is_scene_boundary. This is separate from // the always-on histogram cut, which flags intra-scene camera-angle changes. bool scene_detect{false}; // master switch (--scene-detect) std::string scene_model; // TransNetV2 .onnx (default set in main) std::string scene_engine; // optional pre-built TRT .engine; bypasses ORT float scene_threshold{0.60f}; // sigmoid boundary prob above this → boundary // (this export's non-boundary baseline sits // at ~0.50; real boundaries spike to ~0.7+) int scene_stride{50}; // frames advanced between windows (≤ kWindow) // Dense-decode knobs (only active with scene_detect). Dense decode of every // native-rate frame is the pipeline's cost driver, which is what made the // temporal shortcut below tempting. /// TRACES: AR-011 | SR-002 // scene_decode_fps: rate the source decodes at in dense mode. // **0 = native, and native is the only correct setting.** kWindow is 100 // frames: at native 25 fps that window spans ~4 s, which is what // TransNetV2 was trained on; at the 12 fps this used to default to it // spans ~8.3 s, so the model saw half-speed motion over twice its // temporal context. Boundary *timestamps* stay right either way — which // is exactly why the degradation was invisible, and why the compressed // separation it produced (~0.50 baseline against ~0.7+ peaks) was read // as a property of the export rather than of the input. Lowering this // buys decode time by running the model off-distribution; reach for // dense_scale or scene_stride instead, which do not. // dense_scale: downscale factor applied to decoded frames in dense mode // (0