-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
96 lines (78 loc) · 2.37 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import argparse
import os
from configs import lfw_path
from utils import (
get_numbers_of_images,
get_number_of_pics_to_compare_with,
get_encodings_from_path,
compare_with_other_images,
print_results,
output_results_csv,
output_results_image,
get_start_time,
get_lfw_face_encodings,
)
def run(n_people_to_compare_with, max_len_closest_matches, image_path):
start_time = get_start_time()
original_image_encodings = get_encodings_from_path(image_path)
images_and_encodings = get_lfw_face_encodings()
(
n_people_to_compare_with,
person_count,
) = get_numbers_of_images(max_len_closest_matches, n_people_to_compare_with)
file_count = get_number_of_pics_to_compare_with(
n_people_to_compare_with, lfw_path, person_count
)
all_matches_sorted = compare_with_other_images(
original_image_encodings, n_people_to_compare_with, images_and_encodings
)
closest_matches = all_matches_sorted[0:9]
closest_matches_sorted = list(
zip(closest_matches["image_path"], closest_matches["face_distance"])
)
print_results(closest_matches_sorted, image_path)
output_results_csv(
closest_matches_sorted,
start_time,
os.path.basename(image_path),
max_len_closest_matches,
file_count,
n_people_to_compare_with,
)
output_results_image(
closest_matches_sorted,
start_time,
os.path.basename(image_path),
max_len_closest_matches,
file_count,
n_people_to_compare_with,
)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-n",
"--n_people_to_compare_with",
type=int,
required=False,
help="How many people's faces do you want to compare with? (default all)",
)
parser.add_argument(
"-m",
"--max_len_closest_matches",
type=int,
default=10,
help="How many closest matches do you want to see? (default 10)",
)
parser.add_argument(
"-i",
"--image_path",
type=str,
default=10,
help="Path of image to compare against",
)
args = parser.parse_args()
run(
n_people_to_compare_with=args.n_people_to_compare_with,
max_len_closest_matches=args.max_len_closest_matches,
image_path=args.image_path,
)