e0d04e242f
- 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
78 lines
2.2 KiB
Python
Executable File
78 lines
2.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Test Rust FaceNet integration with face_processor.py
|
|
"""
|
|
import os
|
|
import sys
|
|
import json
|
|
import subprocess
|
|
import numpy as np
|
|
from pathlib import Path
|
|
|
|
def extract_embedding_rust(image_path: str, model_path: str = "models/facenet_vggface2.onnx"):
|
|
"""Extract embedding using Rust FaceNet"""
|
|
binary = "tools/cli/rust/target/release/rust_facenet"
|
|
|
|
cmd = [binary, "--input", image_path, "--model", model_path]
|
|
result = subprocess.run(cmd, capture_output=True, text=True, cwd="/Users/accusys/momentry_core")
|
|
|
|
if result.returncode != 0:
|
|
print(f"Error: {result.stderr}")
|
|
return None
|
|
|
|
output = json.loads(result.stdout)
|
|
return np.array(output["embedding"])
|
|
|
|
def test_accuracy():
|
|
"""Test accuracy with known faces"""
|
|
print("=== Rust FaceNet Integration Test ===\n")
|
|
|
|
# Test data
|
|
test_images = [
|
|
"/tmp/test_face.jpg"
|
|
]
|
|
|
|
for img_path in test_images:
|
|
if not os.path.exists(img_path):
|
|
print(f"⚠️ Test image not found: {img_path}")
|
|
continue
|
|
|
|
print(f"Testing: {img_path}")
|
|
|
|
# Extract embedding
|
|
embedding = extract_embedding_rust(img_path)
|
|
|
|
if embedding is not None:
|
|
print(f" ✅ Embedding extracted: {len(embedding)} dims")
|
|
print(f" ✅ Norm: {np.linalg.norm(embedding):.4f}")
|
|
else:
|
|
print(f" ❌ Failed to extract embedding")
|
|
|
|
def test_batch_processing():
|
|
"""Test batch processing performance"""
|
|
print("\n=== Batch Processing Test ===\n")
|
|
|
|
# Create test images (if needed)
|
|
test_images = ["/tmp/test_face.jpg"] * 10
|
|
|
|
start_time = time.time()
|
|
|
|
for i, img_path in enumerate(test_images):
|
|
embedding = extract_embedding_rust(img_path)
|
|
if embedding is not None:
|
|
print(f" Image {i+1}: ✅")
|
|
else:
|
|
print(f" Image {i+1}: ❌")
|
|
|
|
elapsed = time.time() - start_time
|
|
avg_time = elapsed / len(test_images) * 1000
|
|
|
|
print(f"\nTotal time: {elapsed:.2f}s")
|
|
print(f"Average per image: {avg_time:.2f}ms")
|
|
|
|
if __name__ == "__main__":
|
|
import time
|
|
|
|
test_accuracy()
|
|
test_batch_processing()
|