Spaces:
Sleeping
Sleeping
Update faceVerificationUtilization/setConfig.py
Browse files
faceVerificationUtilization/setConfig.py
CHANGED
|
@@ -4,6 +4,28 @@ from huggingface_hub import hf_hub_download
|
|
| 4 |
from torchvision import transforms
|
| 5 |
import torchvision.models as models
|
| 6 |
import torch.nn as nn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
model_path = hf_hub_download(repo_id="arnabdhar/YOLOv8-Face-Detection", filename="model.pt")
|
| 9 |
face_detector = YOLO(model_path)
|
|
@@ -22,4 +44,6 @@ transform = transforms.Compose([
|
|
| 22 |
transforms.ToTensor(),
|
| 23 |
transforms.Normalize([0.485, 0.456, 0.406],
|
| 24 |
[0.229, 0.224, 0.225])
|
| 25 |
-
])
|
|
|
|
|
|
|
|
|
| 4 |
from torchvision import transforms
|
| 5 |
import torchvision.models as models
|
| 6 |
import torch.nn as nn
|
| 7 |
+
import faiss, os, ast
|
| 8 |
+
import numpy as np
|
| 9 |
+
import pandas as pd
|
| 10 |
+
|
| 11 |
+
def load_db(csv_path="users/face_features.csv"):
|
| 12 |
+
if not os.path.exists(csv_path):
|
| 13 |
+
return None, [], []
|
| 14 |
+
|
| 15 |
+
df = pd.read_csv(csv_path)
|
| 16 |
+
|
| 17 |
+
df["features"] = df["features"].apply(ast.literal_eval)
|
| 18 |
+
features = np.array(df["features"].tolist()).astype("float32")
|
| 19 |
+
labels = df["label"].tolist()
|
| 20 |
+
|
| 21 |
+
d = features.shape[1]
|
| 22 |
+
index = faiss.IndexFlatIP(d)
|
| 23 |
+
|
| 24 |
+
faiss.normalize_L2(features)
|
| 25 |
+
|
| 26 |
+
index.add(features)
|
| 27 |
+
|
| 28 |
+
return index, labels, df
|
| 29 |
|
| 30 |
model_path = hf_hub_download(repo_id="arnabdhar/YOLOv8-Face-Detection", filename="model.pt")
|
| 31 |
face_detector = YOLO(model_path)
|
|
|
|
| 44 |
transforms.ToTensor(),
|
| 45 |
transforms.Normalize([0.485, 0.456, 0.406],
|
| 46 |
[0.229, 0.224, 0.225])
|
| 47 |
+
])
|
| 48 |
+
|
| 49 |
+
faiss_index, labels, db = load_db("users/face_features.csv")
|