Spaces:
Runtime error
Runtime error
Update face_analysis.py
Browse files- face_analysis.py +19 -1
face_analysis.py
CHANGED
|
@@ -4,6 +4,7 @@ from facenet_pytorch import InceptionResnetV1
|
|
| 4 |
from sklearn.cluster import DBSCAN
|
| 5 |
import os
|
| 6 |
import shutil
|
|
|
|
| 7 |
|
| 8 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 9 |
model = InceptionResnetV1(pretrained='vggface2').eval().to(device)
|
|
@@ -37,4 +38,21 @@ def organize_faces_by_person(embeddings_by_frame, clusters, aligned_faces_folder
|
|
| 37 |
os.makedirs(person_folder, exist_ok=True)
|
| 38 |
src = os.path.join(aligned_faces_folder, f"frame_{frame_num}_face.jpg")
|
| 39 |
dst = os.path.join(person_folder, f"frame_{frame_num}_face.jpg")
|
| 40 |
-
shutil.copy(src, dst)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from sklearn.cluster import DBSCAN
|
| 5 |
import os
|
| 6 |
import shutil
|
| 7 |
+
import mediapipe as mp
|
| 8 |
|
| 9 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 10 |
model = InceptionResnetV1(pretrained='vggface2').eval().to(device)
|
|
|
|
| 38 |
os.makedirs(person_folder, exist_ok=True)
|
| 39 |
src = os.path.join(aligned_faces_folder, f"frame_{frame_num}_face.jpg")
|
| 40 |
dst = os.path.join(person_folder, f"frame_{frame_num}_face.jpg")
|
| 41 |
+
shutil.copy(src, dst)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def draw_facial_landmarks(image, landmarks):
|
| 45 |
+
mp_face_mesh = mp.solutions.face_mesh
|
| 46 |
+
face_mesh = mp_face_mesh.FaceMesh(static_image_mode=False, max_num_faces=1, min_detection_confidence=0.6)
|
| 47 |
+
mp_drawing = mp.solutions.drawing_utils
|
| 48 |
+
mp_face_mesh = mp.solutions.face_mesh
|
| 49 |
+
drawing_spec = mp_drawing.DrawingSpec(thickness=1, circle_radius=1)
|
| 50 |
+
|
| 51 |
+
if landmarks:
|
| 52 |
+
mp_drawing.draw_landmarks(
|
| 53 |
+
image=image,
|
| 54 |
+
landmark_list=landmarks,
|
| 55 |
+
connections=mp_face_mesh.FACEMESH_TESSELATION,
|
| 56 |
+
landmark_drawing_spec=drawing_spec,
|
| 57 |
+
connection_drawing_spec=drawing_spec)
|
| 58 |
+
return image
|