-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunProject.py
More file actions
71 lines (56 loc) · 3.37 KB
/
Copy pathRunProject.py
File metadata and controls
71 lines (56 loc) · 3.37 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from Parameters import *
from FacialDetector import *
import pdb
from Visualize import *
params: Parameters = Parameters()
params.dim_window = 100 # exemplele pozitive (fete de oameni cropate) au 36x36 pixeli
params.dim_hog_cell = 8 # dimensiunea celulei - Pentru HOG 9 -> 0.483 si imgpoz91 + poze_negative91/square
# img 100X100 cu dim window 100 si hog cell 8 -> 0.498 so tresh 2.5
params.overlap = 0.3
params.number_positive_examples = 5813 # numarul exemplelor pozitive
params.number_negative_examples = 23357 # numarul exemplelor negative imgneg91 -> 53770
params.threshold = 2.5 # toate ferestrele cu scorul > threshold si maxime locale devin detectii
params.has_annotations = True
params.use_hard_mining = False # (optional)antrenare cu exemple puternic negative
params.use_flip_images = False # adauga imaginile cu fete oglindite
if params.use_flip_images:
params.number_positive_examples *= 2
facial_detector: FacialDetector = FacialDetector(params)
# Pasii 1+2+3. Incarcam exemplele pozitive (cropate) si exemple negative generate
# verificam daca sunt deja existente
positive_features_path = os.path.join(params.dir_save_files, 'descriptoriExemplePozitive_' + str(params.dim_hog_cell) + '_' +
str(params.number_positive_examples) + '.npy')
if os.path.exists(positive_features_path):
positive_features = np.load(positive_features_path)
print('Am incarcat descriptorii pentru exemplele pozitive')
else:
print('Construim descriptorii pentru exemplele pozitive:')
positive_features = facial_detector.get_positive_descriptors()
np.save(positive_features_path, positive_features)
print('Am salvat descriptorii pentru exemplele pozitive in fisierul %s' % positive_features_path)
# exemple negative
negative_features_path = os.path.join(params.dir_save_files, 'descriptoriExempleNegative_' + str(params.dim_hog_cell) + '_' +
str(params.number_negative_examples) + '.npy')
if os.path.exists(negative_features_path):
negative_features = np.load(negative_features_path)
print('Am incarcat descriptorii pentru exemplele negative')
else:
print('Construim descriptorii pentru exemplele negative:')
negative_features = facial_detector.get_negative_descriptors()
np.save(negative_features_path, negative_features)
print('Am salvat descriptorii pentru exemplele negative in fisierul %s' % negative_features_path)
# Pasul 4. Invatam clasificatorul liniar
training_examples = np.concatenate((np.squeeze(positive_features), np.squeeze(negative_features)), axis=0)
train_labels = np.concatenate((np.ones(params.number_positive_examples), np.zeros(negative_features.shape[0])))
facial_detector.train_classifier(training_examples, train_labels)
# Pasul 5. (optional) Antrenare cu exemple puternic negative (detectii cu scor >0 din cele 274 de imagini negative)
# Daca implementati acest pas ar trebui sa modificati functia FacialDetector.run()
# astfel incat sa va returneze descriptorii detectiilor cu scor > 0 din cele 274 imagini negative
# completati codul in continuare
# TODO: (optional) completeaza codul in continuare
detections, scores, file_names = facial_detector.run()
if params.has_annotations:
facial_detector.eval_detections(detections, scores, file_names)
show_detections_with_ground_truth(detections, scores, file_names, params)
else:
show_detections_without_ground_truth(detections, scores, file_names, params)