-
Notifications
You must be signed in to change notification settings - Fork 22
5 kNN as Face Classifier
We created a kNN classification , You can read source code in knn.py
module.
The key is about finding best neighbors.
for x in range(len(self._samples)):
dist = self.euclidean_distance(target, self._samples[x], length)
if dist < self.thresh:
distances.append((self._samples[x], dist, self._labels[x]))
From official dlib example , If Euclidean distance of two vectors is less than 0.6 , they are from same face.
In general, if two face descriptor vectors have a Euclidean distance between them less than 0.6 then they are from the same person, otherwise they are from different people. Here we just print the vector to the screen.
Thresh value in Classifier python class is maximum value of Euclidean distance between samples.
Labels , samples and distances will extended to same list , then the list will sort with distance key. Now we can predict label of input sample using there k nearest neighbors.
I used a limit for classification. It will limit samples of each labels that will help to prevent overlapping.