I want to run Face Recognition on CCTV footage. I have implemented several distance metrics for Face Embedding comparison during inference like Euclidean distance, Cosine distance, KDTree, SVM, L1 & L2 distance, etc but in the end I kept only the first two, as I was not getting expected accuracy from those it was difficult to find a good threshold.
def distance(self, embeddings1, embeddings2, distance_metric=0):
if distance_metric == 0:
# Euclidian distance
embeddings1 = embeddings1/np.linalg.norm(embeddings1, axis=1, keepdims=True)
embeddings2 = embeddings2/np.linalg.norm(embeddings2, axis=1, keepdims=True)
dist = np.sqrt(np.sum(np.square(np.subtract(embeddings1, embeddings2))))
return dist
elif distance_metric == 1:
# Distance based on cosine similarity
dot = np.sum(np.multiply(embeddings1, embeddings2), axis=1)
norm = np.linalg.norm(embeddings1, axis=1) * np.linalg.norm(embeddings2, axis=1)
similarity = dot/norm
dist = np.arccos(similarity) / math.pi
return dist[0]
else:
raise 'Undefined distance metric %d' % distance_metric
Q1: What is the best metric in terms of accuracy for Face Embedding comparison and how to set a threshold in that?
Q2: What is the fastest and better way for Face Embedding comparison other than Euclidean and Cosine distance?
Triplet-loss
? – CheckeredTriplet-loss
earlier but here I want a distance metric for face comparison during recognition, not aLoss function
. – Hessite