-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathface_recognition.py
More file actions
35 lines (25 loc) · 1.07 KB
/
face_recognition.py
File metadata and controls
35 lines (25 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
import sklearn
from sklearn.preprocessing import StandardScaler
class Face_Recognition(object):
def __init__(self, scaler):
self.labels = None
self.features = None
self.scaler = scaler
def set(self, features, labels):
self.features = features
self.labels = labels
def evaluate(self, input_data):
if input_data is None:
print('empty')
else:
features = np.concatenate((self.features, input_data), axis=0)
sum_of_squares = np.sum(features ** 2.0, axis=1, keepdims=True)
d_mat = sum_of_squares + sum_of_squares.transpose() - (2.0 * np.dot(features, features.transpose()))
output_idx = np.argmin(d_mat[-1][:-1])
distance = np.min(d_mat[-1][:-1])
print(output_idx, distance, d_mat[-1][:-1])
new_d_mat = d_mat[-1][:-1]
mean_d_mat = np.mean(new_d_mat)
print(mean_d_mat, mean_d_mat - distance)
face_recognition = Face_Recognition(StandardScaler())