-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrainingFaceML.py
34 lines (24 loc) · 851 Bytes
/
trainingFaceML.py
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
from sklearn.preprocessing import LabelEncoder
from sklearn.svm import SVC
import pickle
def training():
#initilizing of embedding & recognizer
embeddingFile = "output/embeddings.pickle"
#New & Empty at initial
recognizerFile = "output/recognizer.pickle"
labelEncFile = "output/le.pickle"
print("Loading face embeddings...")
data = pickle.loads(open(embeddingFile, "rb").read())
print("Encoding labels...")
labelEnc = LabelEncoder()
labels = labelEnc.fit_transform(data["names"])
print("Training model...")
recognizer = SVC(C=1.0, kernel="linear", probability=True)
recognizer.fit(data["embeddings"], labels)
f = open(recognizerFile, "wb")
f.write(pickle.dumps(recognizer))
f.close()
f = open(labelEncFile, "wb")
f.write(pickle.dumps(labelEnc))
f.close()
training()