-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclassifier.py
33 lines (28 loc) · 992 Bytes
/
classifier.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
# import the necessary packages
from sklearn.preprocessing import LabelEncoder
from sklearn.svm import SVC
import pickle
import numpy as np
# load the face embeddings
print("[INFO] loading Road embeddings...")
data = pickle.loads(open("embeddings.pickle", "rb").read())
# encode the labels
print("[INFO] encoding labels...")
le = LabelEncoder()
labels = le.fit_transform(data["names"])
print(np.array(data["embeddings"]).shape)
# train the model used to accept the 2622-d embeddings of the face and
# then produce the actual face recognition
print("[INFO] training model...")
clf = SVC(C=5, kernel="linear", probability=True)
#clf = SVC(C=1, kernel="rbf" ,degree=3 , probability=True)
clf.fit(data["embeddings"], labels)
print(clf.score(data["embeddings"], labels))
# write the actual face recognition model to disk
f = open("classifier.pickle", "wb")
f.write(pickle.dumps(clf))
f.close()
# write the label encoder to disk
f = open("le.pickle", "wb")
f.write(pickle.dumps(le))
f.close()