suinY00N commited on
Commit
3744cfc
โ€ข
1 Parent(s): 8078f7a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
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()