-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraining-model-lbp.py
45 lines (38 loc) · 1.54 KB
/
training-model-lbp.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
from helpers import file_util, lbp_extract_feature, image_util
from os.path import join
from numpy import linalg as la
import numpy as np
if __name__ == '__main__':
train_folder = 'train_data'
files = file_util.listFile(train_folder)
m = len(files)
# Extract feature histograms from all training images
# Log histograms to text file
log_file = open("lbp-model/histogram.txt", "w")
count = 0
for filePath in files:
data = image_util.load_image(join(train_folder, filePath))
if not image_util.is_grayscale(join(train_folder, filePath)):
data = image_util.rgb2gray(data)
local_histograms = lbp_extract_feature.extract_face(data, log=join("lbp-model/image", filePath)) # 20x59
norm = la.norm(local_histograms, axis=1)
norm = norm.reshape((20, 1))
local_histograms = np.divide(local_histograms, norm)
if count == 0:
mean_histograms = local_histograms
else:
mean_histograms = np.add(mean_histograms, local_histograms)
count += 1
file_util.log_data(local_histograms, log_file)
log_file.write('\n')
log_file.close()
# Log width, height of lbp-model
height, width = data.shape
log_file = open("lbp-model/info.txt", "w")
log_file.write(str(height) + '\n')
log_file.write(str(width) + '\n')
log_file.close()
mean_histograms = np.divide(mean_histograms, count)
log_file = open("lbp-model/mean-histogram.txt", "w")
file_util.log_data(mean_histograms, log_file)
log_file.close()