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
58 lines
1.7 KiB
Python
Executable File
58 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Convert facenet-pytorch InceptionResnetV1 to ONNX format
|
|
"""
|
|
import os
|
|
import sys
|
|
import torch
|
|
import numpy as np
|
|
from facenet_pytorch import InceptionResnetV1
|
|
|
|
def convert_to_onnx(output_path: str = "models/facenet_vggface2.onnx"):
|
|
"""Export InceptionResnetV1 to ONNX"""
|
|
|
|
print(f"[CONVERT] Loading InceptionResnetV1 (VGGFace2)...")
|
|
model = InceptionResnetV1(pretrained='vggface2').eval()
|
|
|
|
print(f"[CONVERT] Creating dummy input...")
|
|
dummy_input = torch.randn(1, 3, 160, 160)
|
|
|
|
print(f"[CONVERT] Exporting to ONNX...")
|
|
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
|
|
|
torch.onnx.export(
|
|
model,
|
|
dummy_input,
|
|
output_path,
|
|
input_names=['input'],
|
|
output_names=['output'],
|
|
dynamic_axes={
|
|
'input': {0: 'batch_size'},
|
|
'output': {0: 'batch_size'}
|
|
},
|
|
opset_version=17,
|
|
do_constant_folding=True,
|
|
verbose=False
|
|
)
|
|
|
|
print(f"[CONVERT] ✅ Exported to: {output_path}")
|
|
|
|
# Verify
|
|
print(f"[CONVERT] Verifying ONNX model...")
|
|
import onnx
|
|
onnx_model = onnx.load(output_path)
|
|
onnx.checker.check_model(onnx_model)
|
|
print(f"[CONVERT] ✅ ONNX model is valid")
|
|
|
|
# Get model info
|
|
print(f"\n[INFO] Model details:")
|
|
print(f" File size: {os.path.getsize(output_path) / 1024 / 1024:.1f} MB")
|
|
print(f" Inputs: {[inp.name for inp in onnx_model.graph.input]}")
|
|
print(f" Outputs: {[out.name for out in onnx_model.graph.output]}")
|
|
|
|
return output_path
|
|
|
|
if __name__ == "__main__":
|
|
output_path = sys.argv[1] if len(sys.argv) > 1 else "models/facenet_vggface2.onnx"
|
|
convert_to_onnx(output_path)
|