feat: face clustering pipeline improvements and Rust/Swift face processing
- Add Rust face processor module (detection, embedding, tracking, qdrant) - Add Facenet CoreML/ONNX conversion scripts and tests - Refactor swift_face into Sources/swift_face with ArgumentParser support - Update store_traced_faces to handle face.json correctly - Fix ASRX parsing and TKG bbox reading from Qdrant - Improve admin_config and trace_agent APIs - Add M4 workspace docs for face clustering, dedup, and Facenet validation - Fix worker heartbeat TTL (poll_interval x 3, min 60s) for offline detection
This commit is contained in:
@@ -142,6 +142,29 @@ def run_face_tracker(
|
||||
# Copy face.json to traced_json_path (no re-tracking needed)
|
||||
import shutil
|
||||
shutil.copy(face_json_path, traced_json_path)
|
||||
|
||||
# ✅ Fix: Update Qdrant trace_id even when skipping tracking
|
||||
# Build trace_mapping from the copied face_traced.json
|
||||
with open(traced_json_path) as f:
|
||||
traced_data = json.load(f)
|
||||
|
||||
trace_mapping = {}
|
||||
for frame in traced_data.get("frames", []):
|
||||
frame_num = str(frame.get("frame", 0))
|
||||
for face in frame.get("faces", []):
|
||||
trace_id = face.get("trace_id")
|
||||
if trace_id is not None:
|
||||
if trace_id not in trace_mapping:
|
||||
trace_mapping[trace_id] = []
|
||||
trace_mapping[trace_id].append({
|
||||
"frame": int(frame_num),
|
||||
"face_idx": len(trace_mapping[trace_id])
|
||||
})
|
||||
|
||||
if trace_mapping:
|
||||
print(f"[TRACE] Updating Qdrant trace_ids for {len(trace_mapping)} traces")
|
||||
update_trace_ids(file_uuid, trace_mapping)
|
||||
|
||||
return traced_json_path
|
||||
|
||||
# V2.0 uses list format (FaceResult), convert to dict for face_tracker
|
||||
@@ -285,15 +308,31 @@ def store_traced_faces(file_uuid: str, traced_json_path: str, schema: str = SCHE
|
||||
|
||||
# Build trace_mapping for Qdrant update: {frame: {bbox_key: trace_id}}
|
||||
trace_mapping = {}
|
||||
for frame_num_str, frame_data in sorted(frames.items(), key=lambda x: int(x[0])):
|
||||
frame_num = int(frame_num_str)
|
||||
trace_mapping[frame_num] = {}
|
||||
for face in frame_data.get("faces", []):
|
||||
trace_id = face.get("trace_id")
|
||||
if trace_id is None:
|
||||
# Handle both dict and list formats for frames
|
||||
if isinstance(frames, list):
|
||||
# New format: frames is a list of frame objects
|
||||
for frame_data in sorted(frames, key=lambda x: x.get('frame', 0)):
|
||||
frame_num = frame_data.get('frame')
|
||||
if frame_num is None:
|
||||
continue
|
||||
bbox_key = f"{face['x']}_{face['y']}_{face['width']}_{face['height']}"
|
||||
trace_mapping[frame_num][bbox_key] = trace_id
|
||||
trace_mapping[frame_num] = {}
|
||||
for face in frame_data.get("faces", []):
|
||||
trace_id = face.get("trace_id")
|
||||
if trace_id is None:
|
||||
continue
|
||||
bbox_key = f"{face['x']}_{face['y']}_{face['width']}_{face['height']}"
|
||||
trace_mapping[frame_num][bbox_key] = trace_id
|
||||
else:
|
||||
# Old format: frames is a dict with frame numbers as keys
|
||||
for frame_num_str, frame_data in sorted(frames.items(), key=lambda x: int(x[0])):
|
||||
frame_num = int(frame_num_str)
|
||||
trace_mapping[frame_num] = {}
|
||||
for face in frame_data.get("faces", []):
|
||||
trace_id = face.get("trace_id")
|
||||
if trace_id is None:
|
||||
continue
|
||||
bbox_key = f"{face['x']}_{face['y']}_{face['width']}_{face['height']}"
|
||||
trace_mapping[frame_num][bbox_key] = trace_id
|
||||
|
||||
# Update Qdrant _faces collection with trace_id.
|
||||
# return_trace_ids=True makes update_trace_ids also return the trace_id set seen
|
||||
@@ -310,12 +349,21 @@ def store_traced_faces(file_uuid: str, traced_json_path: str, schema: str = SCHE
|
||||
# Unique trace count from the update scroll (no extra full scan needed).
|
||||
qdrant_trace_count = len(trace_ids)
|
||||
|
||||
total_faces = sum(
|
||||
1
|
||||
for fd in frames.values()
|
||||
for f in fd.get("faces", [])
|
||||
if f.get("trace_id") is not None
|
||||
)
|
||||
# Count total faces with trace_id (handle both list and dict formats)
|
||||
if isinstance(frames, list):
|
||||
total_faces = sum(
|
||||
1
|
||||
for fd in frames
|
||||
for f in fd.get("faces", [])
|
||||
if f.get("trace_id") is not None
|
||||
)
|
||||
else:
|
||||
total_faces = sum(
|
||||
1
|
||||
for fd in frames.values()
|
||||
for f in fd.get("faces", [])
|
||||
if f.get("trace_id") is not None
|
||||
)
|
||||
|
||||
print(
|
||||
f"[TRACE] Updated {qdrant_updated} Qdrant points with trace_id, {qdrant_trace_count} unique traces"
|
||||
|
||||
Reference in New Issue
Block a user