Warlord-K commited on
Commit
59ccead
·
1 Parent(s): d8622b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -21,19 +21,17 @@ for img in source_imgs:
21
  source_faces.append(extract_faces(detector, img)[0])
22
  source_embeddings = get_embeddings(model, source_faces)
23
 
24
- index = faiss.IndexFlatL2(4096)
25
- index.add(np.array(source_embeddings))
26
-
27
- # set image
28
- image = 'group.jpg'
29
-
30
  def find_names(image):
31
- imgs = extract_faces(detector, image)
32
  embeds = get_embeddings(model, imgs)
33
- D, I = index.search(np.array(embeds), 1)
 
 
 
 
34
  names = ""
35
- for i in I:
36
- names+=source_imgs[i[0]].split("/")[-1].split(".")[0]
37
  names+= ","
38
  return names
39
 
 
21
  source_faces.append(extract_faces(detector, img)[0])
22
  source_embeddings = get_embeddings(model, source_faces)
23
 
 
 
 
 
 
 
24
  def find_names(image):
25
+ imgs, _ = extract_faces(detector, image)
26
  embeds = get_embeddings(model, imgs)
27
+ d = np.zeros((len(source_embeddings), len(embeds)))
28
+ for i, s in enumerate(source_embeddings):
29
+ for j, t in enumerate(embeds):
30
+ d[i][j] = findCosineDistance(s, t)
31
+ ids = np.argmin(d, axis = 0)
32
  names = ""
33
+ for i in ids:
34
+ names+=source_imgs[i].split("/")[-1].split(".")[0]
35
  names+= ","
36
  return names
37