Spaces:
Runtime error
Runtime error
ParisNeo
commited on
Commit
·
71a1779
1
Parent(s):
ae608e6
upgraded
Browse files
app.py
CHANGED
@@ -371,13 +371,13 @@ class UI():
|
|
371 |
nearest_distance = 1e100
|
372 |
nearest = 0
|
373 |
for i, known_face in enumerate(self.known_faces):
|
374 |
-
if self.distance_type == "cosine":
|
375 |
# Cosine distance
|
376 |
distance = self.cosine_distance(known_face["mean"], embedding)
|
377 |
-
elif self.distance_type =="L1":
|
378 |
# absolute distance
|
379 |
distance = np.abs(known_face["mean"]-embedding).sum()
|
380 |
-
elif self.distance_type == "L2":
|
381 |
# absolute distance
|
382 |
distance = np.sqrt(np.square(known_face["mean"]-embedding).sum())
|
383 |
if distance<nearest_distance:
|
@@ -402,6 +402,7 @@ class UI():
|
|
402 |
fa.process(image)
|
403 |
|
404 |
if fa.nb_faces>0:
|
|
|
405 |
for j in range(fa.nb_faces):
|
406 |
try:
|
407 |
face = fa.faces[j]
|
@@ -413,25 +414,23 @@ class UI():
|
|
413 |
nearest_distance = 1e100
|
414 |
nearest = 0
|
415 |
for i, known_face in enumerate(self.known_faces):
|
416 |
-
if self.distance_type == "cosine":
|
417 |
# Cosine distance
|
418 |
distance = self.cosine_distance(known_face["mean"], embedding)
|
419 |
-
elif self.distance_type =="L1":
|
420 |
# absolute distance
|
421 |
distance = np.abs(known_face["mean"]-embedding).sum()
|
422 |
-
elif self.distance_type == "L2":
|
423 |
# absolute distance
|
424 |
distance = np.sqrt(np.square(known_face["mean"]-embedding).sum())
|
425 |
if distance<nearest_distance:
|
426 |
nearest_distance = distance
|
427 |
nearest = i
|
428 |
|
429 |
-
if nearest_distance>self.threshold:
|
430 |
-
face.draw_bounding_box(image, thickness=1,text=f"Unknown:{nearest_distance:.3e}")
|
431 |
-
else:
|
432 |
-
face.draw_bounding_box(image, thickness=1,text=f"{self.known_faces_names[nearest]}:{nearest_distance:.3e}")
|
433 |
except Exception as ex:
|
434 |
image=face_image
|
|
|
435 |
|
436 |
# Return the resulting frame
|
437 |
return image
|
|
|
371 |
nearest_distance = 1e100
|
372 |
nearest = 0
|
373 |
for i, known_face in enumerate(self.known_faces):
|
374 |
+
if self.distance_type.value == "cosine":
|
375 |
# Cosine distance
|
376 |
distance = self.cosine_distance(known_face["mean"], embedding)
|
377 |
+
elif self.distance_type.value =="L1":
|
378 |
# absolute distance
|
379 |
distance = np.abs(known_face["mean"]-embedding).sum()
|
380 |
+
elif self.distance_type.value == "L2":
|
381 |
# absolute distance
|
382 |
distance = np.sqrt(np.square(known_face["mean"]-embedding).sum())
|
383 |
if distance<nearest_distance:
|
|
|
402 |
fa.process(image)
|
403 |
|
404 |
if fa.nb_faces>0:
|
405 |
+
bboxes_and_names=[]
|
406 |
for j in range(fa.nb_faces):
|
407 |
try:
|
408 |
face = fa.faces[j]
|
|
|
414 |
nearest_distance = 1e100
|
415 |
nearest = 0
|
416 |
for i, known_face in enumerate(self.known_faces):
|
417 |
+
if self.distance_type.value == "cosine":
|
418 |
# Cosine distance
|
419 |
distance = self.cosine_distance(known_face["mean"], embedding)
|
420 |
+
elif self.distance_type.value =="L1":
|
421 |
# absolute distance
|
422 |
distance = np.abs(known_face["mean"]-embedding).sum()
|
423 |
+
elif self.distance_type.value == "L2":
|
424 |
# absolute distance
|
425 |
distance = np.sqrt(np.square(known_face["mean"]-embedding).sum())
|
426 |
if distance<nearest_distance:
|
427 |
nearest_distance = distance
|
428 |
nearest = i
|
429 |
|
430 |
+
bboxes_and_names.append([face.bounding_box, f"Unknown:{nearest_distance:.2e}" if nearest_distance>self.threshold else f"{self.known_faces_names[nearest]}:{nearest_distance:.2e}"])
|
|
|
|
|
|
|
431 |
except Exception as ex:
|
432 |
image=face_image
|
433 |
+
image = fa.draw_names_on_bboxes(image,bboxes_and_names,upscale=2)
|
434 |
|
435 |
# Return the resulting frame
|
436 |
return image
|