Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from deepface import DeepFace
|
3 |
+
|
4 |
+
def compare_faces():
|
5 |
+
results = []
|
6 |
+
|
7 |
+
# ์ฌ์ ์ด๋ฏธ์ง ํ์ผ ๊ฒฝ๋ก ๋ฆฌ์คํธ ์์ฑ
|
8 |
+
female_image_paths = [f"images/F_{i}.jpg" for i in range(1, 23)]
|
9 |
+
|
10 |
+
for male_index in range(1, 33):
|
11 |
+
# ๋จ์ ์ด๋ฏธ์ง ํ์ผ ๊ฒฝ๋ก
|
12 |
+
male_image_path = f"images/M_{male_index}.jpg"
|
13 |
+
|
14 |
+
max_similarity = -1
|
15 |
+
min_similarity = float('inf')
|
16 |
+
most_similar = None
|
17 |
+
least_similar = None
|
18 |
+
|
19 |
+
for female_image_path in female_image_paths:
|
20 |
+
result = DeepFace.verify(male_image_path, female_image_path)
|
21 |
+
similarity = 1 - result["distance"]
|
22 |
+
|
23 |
+
if similarity > max_similarity:
|
24 |
+
max_similarity = similarity
|
25 |
+
most_similar = female_image_path
|
26 |
+
|
27 |
+
if similarity < min_similarity:
|
28 |
+
min_similarity = similarity
|
29 |
+
least_similar = female_image_path
|
30 |
+
|
31 |
+
most_similar_name = os.path.basename(most_similar)
|
32 |
+
least_similar_name = os.path.basename(least_similar)
|
33 |
+
|
34 |
+
results.append(
|
35 |
+
f"๋จ์ M_{male_index}:\n"
|
36 |
+
f" ๊ฐ์ฅ ์ ์ฌ๋๊ฐ ๋์ ์ฌ๋: {most_similar_name} (์ ์ฌ๋: {max_similarity:.2f})\n"
|
37 |
+
f" ๊ฐ์ฅ ์ ์ฌ๋๊ฐ ๋ฎ์ ์ฌ๋: {least_similar_name} (์ ์ฌ๋: {min_similarity:.2f})"
|
38 |
+
)
|
39 |
+
|
40 |
+
return "\n\n".join(results)
|
41 |
+
|
42 |
+
def main():
|
43 |
+
results = compare_faces()
|
44 |
+
print(results)
|
45 |
+
|
46 |
+
if __name__ == "__main__":
|
47 |
+
main()
|