This code simulates face embeddings by flattening and normalizing small arrays as fake face images. It then compares distances between embeddings to show which faces are more similar.
import numpy as np
from sklearn.preprocessing import normalize
def dummy_face_embedding(face_image):
# Simulate embedding by flattening and normalizing image
flat = face_image.flatten()
norm = np.linalg.norm(flat)
return flat / norm if norm > 0 else flat
def compare_embeddings(emb1, emb2):
return np.linalg.norm(emb1 - emb2)
# Simulated face images as 3x3 grayscale arrays
face1 = np.array([[0, 1, 2], [1, 2, 3], [2, 3, 4]], dtype=float)
face2 = np.array([[0, 1, 2], [1, 2, 3], [2, 3, 5]], dtype=float)
face3 = np.array([[10, 10, 10], [10, 10, 10], [10, 10, 10]], dtype=float)
emb1 = dummy_face_embedding(face1)
emb2 = dummy_face_embedding(face2)
emb3 = dummy_face_embedding(face3)
dist12 = compare_embeddings(emb1, emb2)
dist13 = compare_embeddings(emb1, emb3)
print(f"Distance between face1 and face2: {dist12:.4f}")
print(f"Distance between face1 and face3: {dist13:.4f}")