Update README.md
Browse files
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
-
language:
|
| 4 |
- en
|
| 5 |
metrics:
|
| 6 |
- accuracy
|
|
@@ -14,35 +14,36 @@ tags:
|
|
| 14 |
- facenet
|
| 15 |
- computer_vision
|
| 16 |
- streamlit
|
| 17 |
-
|
| 18 |
-
base_model: custom
|
| 19 |
datasets:
|
| 20 |
- AI-Solutions-KK/face_recognition_demo_dataset
|
| 21 |
---
|
| 22 |
|
| 23 |
-
# Face Recognition
|
| 24 |
-
|
| 25 |
|
| 26 |
-
This repository stores my trained
|
| 27 |
-
It contains the SVM classifier and supporting numpy files used in my
|
| 28 |
-
**Face Recognition System** (Streamlit demo).
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
-
- `centroids.npy` โ class centroids for cosine-similarity baseline
|
| 39 |
-
- `classes.npy` โ list of class labels (one per identity)
|
| 40 |
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
---
|
| 44 |
|
| 45 |
-
|
| 46 |
|
| 47 |
```python
|
| 48 |
from huggingface_hub import hf_hub_download
|
|
@@ -59,3 +60,91 @@ classes_path = hf_hub_download(REPO_ID, "classes.npy")
|
|
| 59 |
svc_model = joblib.load(svc_path)
|
| 60 |
centroids = np.load(centroids_path)
|
| 61 |
class_names = np.load(classes_path, allow_pickle=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
+
language:
|
| 4 |
- en
|
| 5 |
metrics:
|
| 6 |
- accuracy
|
|
|
|
| 14 |
- facenet
|
| 15 |
- computer_vision
|
| 16 |
- streamlit
|
| 17 |
+
- cpu_friendly
|
|
|
|
| 18 |
datasets:
|
| 19 |
- AI-Solutions-KK/face_recognition_demo_dataset
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# ๐ง Face Recognition Model (CNN Embeddings + SVM)
|
| 23 |
+
### **Deep Learning + Machine Learning Combined for Efficient CPU-Based Face Recognition**
|
| 24 |
|
| 25 |
+
This repository stores my trained **Face Recognition Model** using:
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
- **FaceNet (InceptionResnetV1)** to extract 512-D face embeddings
|
| 28 |
+
- **SVM Classifier** for identity recognition
|
| 29 |
+
- **Centroid baseline** for fast cosine-similarity checks
|
| 30 |
|
| 31 |
+
Built to run **efficiently on CPU**, making it ideal for lightweight deployment, low-power systems, and Streamlit apps.
|
| 32 |
|
| 33 |
+
---
|
| 34 |
|
| 35 |
+
## ๐ Files in this Repository
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
| File | Description |
|
| 38 |
+
|------|-------------|
|
| 39 |
+
| `svc_model_retrained.pkl` | SVM classifier trained on FaceNet embeddings |
|
| 40 |
+
| `centroids.npy` | Class centroids for cosine-similarity baseline |
|
| 41 |
+
| `classes.npy` | List of all identity labels |
|
| 42 |
+
| `README.md` | This model card |
|
| 43 |
|
| 44 |
---
|
| 45 |
|
| 46 |
+
# ๐ How to Load This Model in Python
|
| 47 |
|
| 48 |
```python
|
| 49 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 60 |
svc_model = joblib.load(svc_path)
|
| 61 |
centroids = np.load(centroids_path)
|
| 62 |
class_names = np.load(classes_path, allow_pickle=True)
|
| 63 |
+
|
| 64 |
+
print("Model loaded successfully!")
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
---
|
| 68 |
+
|
| 69 |
+
# ๐ฎ Simple Inference Example (Predict Face Identity)
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
from huggingface_hub import hf_hub_download
|
| 73 |
+
import joblib
|
| 74 |
+
import numpy as np
|
| 75 |
+
from PIL import Image
|
| 76 |
+
import torch
|
| 77 |
+
from facenet_pytorch import InceptionResnetV1
|
| 78 |
+
import cv2
|
| 79 |
+
|
| 80 |
+
REPO_ID = "AI-Solutions-KK/face_recognition"
|
| 81 |
+
|
| 82 |
+
# Download model
|
| 83 |
+
svc_path = hf_hub_download(REPO_ID, "svc_model_retrained.pkl")
|
| 84 |
+
centroids_path = hf_hub_download(REPO_ID, "centroids.npy")
|
| 85 |
+
classes_path = hf_hub_download(REPO_ID, "classes.npy")
|
| 86 |
+
|
| 87 |
+
svc_model = joblib.load(svc_path)
|
| 88 |
+
centroids = np.load(centroids_path)
|
| 89 |
+
class_names = np.load(classes_path, allow_pickle=True)
|
| 90 |
+
|
| 91 |
+
# Load FaceNet backbone
|
| 92 |
+
facenet = InceptionResnetV1(pretrained="vggface2").eval()
|
| 93 |
+
|
| 94 |
+
def preprocess(img_path):
|
| 95 |
+
img = Image.open(img_path).convert("RGB")
|
| 96 |
+
img = np.array(img)
|
| 97 |
+
img = cv2.resize(img, (160, 160))
|
| 98 |
+
img = img.astype("float32") / 255.0
|
| 99 |
+
img = torch.tensor(img).permute(2, 0, 1).unsqueeze(0)
|
| 100 |
+
return img
|
| 101 |
+
|
| 102 |
+
def get_embedding(img_path):
|
| 103 |
+
img = preprocess(img_path)
|
| 104 |
+
with torch.no_grad():
|
| 105 |
+
emb = facenet(img).numpy()
|
| 106 |
+
return emb
|
| 107 |
+
|
| 108 |
+
def predict_face(img_path):
|
| 109 |
+
emb = get_embedding(img_path)
|
| 110 |
+
pred = svc_model.predict(emb)[0]
|
| 111 |
+
confidence = np.max(svc_model.decision_function(emb))
|
| 112 |
+
return pred, confidence
|
| 113 |
+
|
| 114 |
+
# -------- RUN ----------
|
| 115 |
+
img_path = "test.jpg"
|
| 116 |
+
label, prob = predict_face(img_path)
|
| 117 |
+
|
| 118 |
+
print("Predicted Identity:", label)
|
| 119 |
+
print("Confidence Score:", prob)
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
---
|
| 123 |
+
|
| 124 |
+
# ๐งโ๐ง For Developers โ Train on Your Own Dataset
|
| 125 |
+
This model is intended as a **plug-and-play template**.
|
| 126 |
+
|
| 127 |
+
Just replace the dataset with your own and retrain:
|
| 128 |
+
|
| 129 |
+
- Extract FaceNet embeddings
|
| 130 |
+
- Train SVM
|
| 131 |
+
- Upload 3 files:
|
| 132 |
+
- `svc_model.pkl`
|
| 133 |
+
- `centroids.npy`
|
| 134 |
+
- `classes.npy`
|
| 135 |
+
|
| 136 |
+
You're done.
|
| 137 |
+
|
| 138 |
+
---
|
| 139 |
+
|
| 140 |
+
If you want, I can also prepare a **professional HF Model Card** with:
|
| 141 |
+
โ Model Architecture
|
| 142 |
+
โ Training Procedure
|
| 143 |
+
โ Evaluation Metrics
|
| 144 |
+
โ Limitations
|
| 145 |
+
โ Intended Use / Misuse
|
| 146 |
+
โ Citations
|
| 147 |
+
|
| 148 |
+
Just say **โmake model card pro versionโ**.
|
| 149 |
+
|
| 150 |
+
Let me know when to update!
|