-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsklearn_train.py
47 lines (31 loc) · 906 Bytes
/
sklearn_train.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
43
44
45
46
47
from sklearn import svm
import pickle
import glob
import numpy as np
W = 64
H = 64
with open('POS_data', 'rb') as fp:
Data, Label = pickle.load(fp)
with open('NEG_data', 'rb') as fp:
Data2, Label2 = pickle.load(fp)
Data += Data2
Label += Label2
shu = np.random.permutation(len(Data))
shu_data = []
shu_label = []
num = int(len(Data)/8)*7
Test_num = num/7
for i in range(len(shu)):
shu_data.append(Data[shu[i]])
shu_label.append(Label[shu[i]])
shu_data = np.array(shu_data, np.float32)
shu_label = np.array(shu_label, np.int32)
Train_data, Test_data = shu_data[:num], shu_data[num:]
Train_label, Test_label = shu_label[:num], shu_label[num:]
print("Train Start")
clf = svm.SVC(kernel='linear')
clf.fit(Train_data, Train_label)
with open('upperbody{}x{}.dat'.format(H, W), 'wb') as fp:
pickle.dump(clf, fp)
test_result = clf.score(Test_data, Test_label)
print(test_result)