Spaces:
Sleeping
Sleeping
File size: 1,387 Bytes
c242a30 92de542 c242a30 65217d6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | from ultralytics import YOLO
import torch, joblib
from huggingface_hub import hf_hub_download
from torchvision import transforms
import torchvision.models as models
import torch.nn as nn
import faiss, os, ast
import numpy as np
import pandas as pd
def load_db(csv_path="users/face_features.csv"):
if not os.path.exists(csv_path):
return None, [], []
df = pd.read_csv(csv_path)
df["features"] = df["features"].apply(ast.literal_eval)
features = np.array(df["features"].tolist()).astype("float32")
labels = df["label"].tolist()
d = features.shape[1]
index = faiss.IndexFlatIP(d)
faiss.normalize_L2(features)
index.add(features)
return index, labels, df
model_path = hf_hub_download(repo_id="arnabdhar/YOLOv8-Face-Detection", filename="model.pt")
face_detector = YOLO(model_path)
efficientnet_model = models.efficientnet_v2_s(weights=None)
efficientnet_model.classifier = nn.Identity()
state_dict = torch.load("faceVerificationModel/efficientnetv2_s_features.pth", map_location="cpu")
efficientnet_model.load_state_dict(state_dict)
efficientnet_model.eval()
pca_xgb = joblib.load("faceVerificationModel/pca_xgb_pipeline.pkl")
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406],
[0.229, 0.224, 0.225])
]) |