-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict.py
61 lines (46 loc) · 1.48 KB
/
predict.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Josh Hellerstein
05/2018
"""
import cv2
import argparse
import os
from face_recognition.preprocess import *
from face_recognition.recognition import *
from face_recognition.database2 import *
def read_img(file):
im = cv2.imread(file, 0)
return im
def show_img(img):
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
def predict_face(img):
d = Database()
e = Eigenfaces(d)
img = read_img(img)
img = preprocess(img)
res = e.predict(img)
return res
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Classify \
a facial image against the database")
parser.add_argument("-i", "--img", help="The path to the image to recognize", required=False)
parser.add_argument("-e", "--evaluate", help="A flag to evaluate the accuracy of the algorithm", required=False, default=None, action='store_true')
args = parser.parse_args()
if args.evaluate:
energies = [0.85]
metrics = ['l2_norm']
tops = [5]
for energy in energies:
for metric in metrics:
for top in tops:
d = Database()
e = Eigenfaces(d, energy=energy)
res = e.evaluate(metric=metric, top=top)
print(energy, metric, top, res)
elif os.path.exists(args.img):
res = predict_face(args.img)
print(res)
else:
print("Please enter a valid path to an image to recognize")