Spaces:
Sleeping
Sleeping
Download faceVerificationUtilization/setConfig.py from akhfzl/FaceVerification-SmartID: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/akhfzl/FaceVerification-SmartID/resolve/main/faceVerificationUtilization/setConfig.py
- Command line
-
hf download hf://spaces/akhfzl/FaceVerification-SmartID/faceVerificationUtilization/setConfig.py
-
curl -L -o setConfig.py https://huggingface.co/spaces/akhfzl/FaceVerification-SmartID/resolve/main/faceVerificationUtilization/setConfig.py
1.39 kB
| 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]) | |
| ]) |