AI-Solutions-KK commited on
Commit
4f8e650
ยท
verified ยท
1 Parent(s): 28e88aa

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +106 -17
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
- library_name: custom
18
- base_model: custom
19
  datasets:
20
  - AI-Solutions-KK/face_recognition_demo_dataset
21
  ---
22
 
23
- # Face Recognition Model_(CNN embeddings + SVM)
24
- DEEP LEARNING & ML JOINTLY USED TO SAVE COMPUTATIONAL POWER
25
 
26
- This repository stores my trained face-recognition model.
27
- It contains the SVM classifier and supporting numpy files used in my
28
- **Face Recognition System** (Streamlit demo).
29
 
30
- The model is trained on FaceNet embeddings and is designed to run
31
- efficiently on CPU.
 
32
 
33
- ---
34
 
35
- ## ๐Ÿงฉ Files in this repo
36
 
37
- - `svc_model_retrained.pkl` โ€“ SVM classifier trained on FaceNet embeddings
38
- - `centroids.npy` โ€“ class centroids for cosine-similarity baseline
39
- - `classes.npy` โ€“ list of class labels (one per identity)
40
 
41
- (If your file names are slightly different, keep the same idea but change the names.)
 
 
 
 
 
42
 
43
  ---
44
 
45
- ## ๐Ÿš€ How to load this model in Python
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!