feat: port face clustering to Rust (rust_face_cluster) with A/B gating
- rust_face_cluster: seed-leader + agglomerative clustering port of fast_face_clustering_processor.py (Qdrant _faces scroll, trace aggregation, auto speaker bind, strict 2dp rounding parity) - A/B verified vs Python on same Qdrant snapshot: both methods match on cluster membership/trace_id/confidence (leader + agglomerative) - face_clustering.rs: USE_RUST_PROCESSORS switch with Python fallback - executor.rs: run_rust_with_output_idx_and_frames (+ QDRANT env passthrough) - appearance/pose: re-use rust runner path (previous migration) - verify_face_cluster.py / verify_pose.py / verify_appearance.py: A/B harness
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env python3
|
||||
"""A/B verify rust_pose interpolation vs Python pose_processor.py interpolate_pose."""
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import pose_processor as pp
|
||||
|
||||
VIDEO = "/Users/accusys/momentry/var/sftpgo/data/demo/IMG_9449 (1).MOV"
|
||||
SOURCE = "/Users/accusys/momentry/output/4655a0ab3c077e30c12b2298c2750650.pose.json"
|
||||
PY_OUT = "/tmp/pose_python.json"
|
||||
RS_OUT = "/tmp/pose_rust.json"
|
||||
|
||||
KP_TOL = 0.6
|
||||
BBOX_TOL = 1.0
|
||||
|
||||
def main():
|
||||
# --- Python baseline ---
|
||||
with open(SOURCE) as f:
|
||||
detected = json.load(f)
|
||||
py_result = pp.interpolate_pose(detected, VIDEO)
|
||||
# round like the real script does
|
||||
py_result = pp.round_json_numbers(py_result)
|
||||
with open(PY_OUT, "w") as f:
|
||||
json.dump(py_result, f)
|
||||
|
||||
# --- Rust ---
|
||||
rs = subprocess.run(
|
||||
[
|
||||
"/Users/accusys/momentry_core/scripts/rust_processors/target/release/rust_pose",
|
||||
VIDEO,
|
||||
SOURCE,
|
||||
RS_OUT,
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if rs.returncode != 0:
|
||||
print("RUST FAILED:\n", rs.stderr)
|
||||
sys.exit(1)
|
||||
print(rs.stderr.strip())
|
||||
|
||||
with open(PY_OUT) as f:
|
||||
py_data = json.load(f)
|
||||
with open(RS_OUT) as f:
|
||||
rs_data = json.load(f)
|
||||
|
||||
py_frames = py_data.get("frames", [])
|
||||
rs_frames = rs_data.get("frames", [])
|
||||
|
||||
print(f"Python: frame_count={py_data.get('frame_count')} fps={py_data.get('fps')} frames={len(py_frames)}")
|
||||
print(f"Rust: frame_count={rs_data.get('frame_count')} fps={rs_data.get('fps')} frames={len(rs_frames)}")
|
||||
|
||||
failures = []
|
||||
total_kps = 0
|
||||
max_kp_diff = 0.0
|
||||
bbox_mismatch = 0
|
||||
|
||||
if len(py_frames) != len(rs_frames):
|
||||
failures.append(f"frame count mismatch: {len(py_frames)} vs {len(rs_frames)}")
|
||||
|
||||
rs_by_frame = {f["frame"]: f for f in rs_frames}
|
||||
for pf in py_frames:
|
||||
fnum = pf["frame"]
|
||||
rf = rs_by_frame.get(fnum)
|
||||
if rf is None:
|
||||
failures.append(f"frame {fnum}: missing in Rust")
|
||||
continue
|
||||
if len(pf["persons"]) != len(rf["persons"]):
|
||||
failures.append(f"frame {fnum}: person count {len(pf['persons'])} vs {len(rf['persons'])}")
|
||||
for pi, (ppr, rpr) in enumerate(zip(pf["persons"], rf["persons"])):
|
||||
pbb = ppr.get("bbox", {})
|
||||
rbb = rpr.get("bbox", {})
|
||||
for key in ("x", "y", "width", "height"):
|
||||
if abs(pbb.get(key, 0) - rbb.get(key, 0)) > BBOX_TOL:
|
||||
bbox_mismatch += 1
|
||||
failures.append(f"frame {fnum} person{pi} bbox.{key}: {pbb.get(key)} vs {rbb.get(key)}")
|
||||
pk = ppr.get("keypoints", [])
|
||||
rk = rpr.get("keypoints", [])
|
||||
if len(pk) != len(rk):
|
||||
failures.append(f"frame {fnum} person{pi}: keypoint count {len(pk)} vs {len(rk)}")
|
||||
continue
|
||||
for i, (a, b) in enumerate(zip(pk, rk)):
|
||||
total_kps += 1
|
||||
for field in ("x", "y"):
|
||||
d = abs(a.get(field, 0) - b.get(field, 0))
|
||||
max_kp_diff = max(max_kp_diff, d)
|
||||
if d > KP_TOL:
|
||||
failures.append(f"frame {fnum} p{pi} kp{i}.{field}: {a.get(field)} vs {b.get(field)} (diff {d:.4f})")
|
||||
|
||||
print(f"\nTotal keypoints compared: {total_kps}, max kp diff: {max_kp_diff:.4f}, bbox mismatches: {bbox_mismatch}")
|
||||
if failures:
|
||||
print(f"\nFAIL ({len(failures)} issues)")
|
||||
for msg in failures[:80]:
|
||||
print(" ", msg)
|
||||
sys.exit(1)
|
||||
print("\nPASS")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user