W600k-r50.onnx Portable Now
# Run inference embedding = session.run([output_name], input_name: img)[0]
def get_face_embedding(face_image: np.ndarray) -> np.ndarray: """ face_image: BGR image from OpenCV, must be 112x112 pixels already cropped and aligned. Returns: 512-dim embedding vector. """ # Convert BGR to RGB rgb = cv2.cvtColor(face_image, cv2.COLOR_BGR2RGB)
return embedding.flatten() aligned_face = cv2.imread("aligned_face.jpg") embedding = get_face_embedding(aligned_face) print(f"Embedding shape: embedding.shape") # (512,) Step 3: Face Matching To verify if two faces belong to the same person: w600k-r50.onnx
def cosine_similarity(a, b): return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b)) emb1 = get_face_embedding(face1) emb2 = get_face_embedding(face2) similarity = cosine_similarity(emb1, emb2)
| Model | Size (FP32) | LFW Accuracy | CPU Inference (Intel i7) | GPU (RTX 3060) | | :--- | :--- | :--- | :--- | :--- | | | 96 MB | 99.78% | 35 ms | 3 ms | | FaceNet (Inception) | 180 MB | 99.65% | 85 ms | 7 ms | | MobileFaceNet | 4 MB | 99.48% | 8 ms | 1 ms | | VGG-Face (16) | 500 MB | 98.95% | 120 ms | 9 ms | # Run inference embedding = session
The R50 model offers state-of-the-art accuracy (99.78% on Labeled Faces in the Wild benchmark) while being compact enough to run on a CPU at 30 FPS. Part 4: Practical Implementation – Running the Model You do not need a deep learning researcher to use this model. Here is a Python implementation using onnxruntime and opencv . Step 1: Installation pip install onnxruntime opencv-python numpy Step 2: The Inference Code import cv2 import numpy as np import onnxruntime as ort Load the model session = ort.InferenceSession("w600k-r50.onnx", providers=['CPUExecutionProvider']) input_name = session.get_inputs()[0].name output_name = session.get_outputs()[0].name
Introduction: The Hidden Engine Behind Modern Face Recognition In the rapidly evolving landscape of computer vision, face recognition has transition from a niche academic pursuit to a ubiquitous component of modern software. From unlocking smartphones and verifying identities at border control to personal photo organization and smart home security, the technology is everywhere. Part 4: Practical Implementation – Running the Model
Developed by Microsoft and Meta, is an open standard for representing machine learning models. It allows you to train a model in PyTorch (or TensorFlow) and export it to a single file that can run on any ONNX-compatible runtime.