#!/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()