feat(scene): feed TransNetV2 at native rate, derive the dedup window from it

Closes both violations SPEC.md named under "Every model gets the input it
was trained for". They are one bug, not two.

The dense stream defaulted to 12 fps, so a 100-frame TransNetV2 window
spanned ~8.3 s against the ~4 s it was trained on: half-speed motion over
twice its temporal context. Boundary timestamps stayed correct throughout,
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 ONNX export rather than of the input.

Dedup then merged boundaries closer than a literal 0.04 s — one frame at
25 fps, and wider than a frame at 30, so two cuts on consecutive frames
became one. Nothing in scenes.json showed it; the file simply had fewer
boundaries. Native rate is where that constant did the most damage, which
is why fixing the decode rate without fixing the dedup would have made
things worse.

dedup_window_sec() now takes the median interval the detector was actually
fed and halves it. Half a frame rather than a whole one: the only thing
being merged is one frame scored by two overlapping windows, and two
distinct frames are a full interval apart.

Cost is real — dense decode is the pipeline's cost driver. It is accepted;
dense_scale and scene_stride remain the reductions that do not run the
model off-distribution. scene_threshold 0.60 was fitted against the 12 fps
input and is now stale, so VR-006 goes from Low to Medium: it is no longer
a refinement, it is a constant that no longer describes the input.

AR-002 rides along because it was already implemented, just untagged and
unverified — the register said Planned while the code was correct. The size
filter becomes FaceDetectorFunc::drop_undersized(), tested at the threshold
and at dense_scale 0.5, and checked end to end against the superhero dump,
whose smallest face is exactly its recorded 32 px minimum, so the fixture
check cannot pass vacuously.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

TRACES: AR-002, AR-011 | SR-002 | UT-002, UT-003, IT-001
This commit is contained in:
2026-08-04 21:17:57 +02:00
co-authored by Claude Opus 5
parent 079b490ede
commit f33403fff8
10 changed files with 378 additions and 44 deletions
+42 -1
View File
@@ -1,6 +1,6 @@
// Replay tests — the real tracker and registry driven from committed fixtures.
//
// TRACES: AR-004, AR-012, AR-013 | VR-001, VR-002 | IT-001
// TRACES: AR-002, AR-004, AR-012, AR-013 | VR-001, VR-002 | IT-001
//
// Tier T2: composition, not units. The registry tests construct awkward states
// directly; these check that the pieces behave when wired together and fed real
@@ -27,6 +27,7 @@
#include <algorithm>
#include <cmath>
#include <limits>
#include <memory>
#include <string>
#include <vector>
@@ -44,6 +45,8 @@ struct Dump {
std::vector<Embedding> emb;
std::vector<float> bbox; // 4 per face
std::string embedder;
float min_face_px{0.f}; // AR-002, as the run was configured
float bbox_upscale{1.f}; // bbox × this = original resolution
std::size_t frames() const { return ts.size(); }
std::size_t faces() const { return emb.size(); }
@@ -97,6 +100,17 @@ Dump load(const std::string& path) {
H5::StrType vlen(H5::PredType::C_S1, H5T_VARIABLE);
f.openAttribute("embedder_model").read(vlen, d.embedder);
}
// AR-002: the threshold the run was configured with, and the scale its boxes
// are in. Read from the dump rather than assumed, so the check is against
// what this fixture was actually generated with — the hero clips predate the
// move to 40 px and were dumped at 32.
if (f.attrExists("min_face_px"))
f.openAttribute("min_face_px").read(H5::PredType::NATIVE_FLOAT,
&d.min_face_px);
if (f.attrExists("bbox_upscale"))
f.openAttribute("bbox_upscale").read(H5::PredType::NATIVE_FLOAT,
&d.bbox_upscale);
return d;
}
@@ -167,6 +181,33 @@ TEST_CASE("superhero fixture is complete", "[replay][VR-001]") {
CHECK(static_cast<std::size_t>(running) == d.faces());
}
// ── AR-002 — the size filter held, all the way to the dump ───────────────────
// The T1 arithmetic is in test_face_detector_node.cpp. This is the other half:
// that the rule was applied on real footage and nothing downstream of it let an
// undersized face back in.
TEST_CASE("no dumped face is below the configured minimum size",
"[replay][AR-002]") {
Dump d = load(fixture("superhero.h5"));
// A dump that did not record its threshold cannot be checked against one.
REQUIRE(d.min_face_px > 0.f);
REQUIRE(d.bbox_upscale > 0.f);
float smallest_side = std::numeric_limits<float>::max();
for (std::size_t i = 0; i < d.faces(); ++i) {
const float w = d.bbox[i * 4 + 2] * d.bbox_upscale; // original resolution
const float h = d.bbox[i * 4 + 3] * d.bbox_upscale;
REQUIRE(w >= d.min_face_px);
REQUIRE(h >= d.min_face_px);
smallest_side = std::min({smallest_side, w, h});
}
// And the filter was binding, not vacuously satisfied. 480x360 footage puts
// faces right on the cutoff, which is what makes this fixture worth checking:
// if the threshold stopped being applied the assertions above would still
// pass on a corpus of close-ups.
CHECK(smallest_side < d.min_face_px * 1.05f);
}
TEST_CASE("replaying the superhero fixture twice gives identical tracks",
"[replay][VR-002]") {
Dump d = load(fixture("superhero.h5"));