-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-Training-on-Feature-Data.py
42 lines (33 loc) · 1.28 KB
/
2-Training-on-Feature-Data.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
35
36
37
38
39
40
41
42
from sklearn.preprocessing import LabelEncoder
from sklearn.svm import SVC
import pickle
# LoADING the saved data
data = pickle.load(open('features-saved/extracted-feature-data.pkl','rb'))
# print(data)
# here are two models
# 1. Face Detection Model used in Feature Extraction and Saving.py
# 2. Face Recognition used to run on top of feature extraction
le = LabelEncoder()
labels = le.fit_transform(data["labels"])
# Training the Model
print("**** training model... ****")
recognizer = SVC(C=1.0, kernel="linear", probability=True)
recognizer.fit(data["featuers"], labels)
print("**** training model... ****")
# write the actual face recognition model to disk
f = open('face-recognition-op/recognition-svm-model.pkl', "wb")
f.write(pickle.dumps(recognizer))
f.close()
print("**** SAVED : Recognition Model *****")
# write the label encoder to disk
f = open("face-recognition-op/label-encoder.pkl", "wb")
f.write(pickle.dumps(le))
f.close()
print("**** SAVED : Label Encoder Model *****")
"""
(base) D:\LearnPythonQuarantine\face recognition\trip-DL>C:/Users/pc/Anaconda3/python.exe "d:/LearnPythonQuarantine/face recognition/trip-DL/2-Training-on-Feature-Data.py"
**** training model... ****
**** training model... ****
**** SAVED : Recognition Model *****
**** SAVED : Label Encoder Model *****
"""