Commit ·
4fea6f8
1
Parent(s): 3da361f
face recognition
Browse files
app/Hackathon_setup/SVC (1).sav
ADDED
|
Binary file (3.54 kB). View file
|
|
|
app/Hackathon_setup/face_recognition.py
CHANGED
|
@@ -108,9 +108,12 @@ def get_face_class(img1):
|
|
| 108 |
|
| 109 |
# 1 Load the Decision Tree classifier
|
| 110 |
# clf_path = os.path.join(BASE_DIR, "decision_tree_model.sav")
|
| 111 |
-
clf_path = os.path.join(BASE_DIR, "
|
| 112 |
clf = joblib.load(clf_path)
|
| 113 |
|
|
|
|
|
|
|
|
|
|
| 114 |
# 2 Load the Siamese feature extractor
|
| 115 |
myModel = Siamese().to(device)
|
| 116 |
ckpt_path = os.path.join(BASE_DIR, "siamese_model.t7")
|
|
@@ -133,11 +136,22 @@ def get_face_class(img1):
|
|
| 133 |
embedding = embedding.view(embedding.size(0), -1).cpu().numpy() # shape (1, embedding_dim)
|
| 134 |
|
| 135 |
# 6 Predict class using Decision Tree
|
| 136 |
-
pred_label = clf.predict(embedding)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
# 7 Optional: return class name (if available)
|
| 139 |
# If you have the dataset available:
|
| 140 |
# class_names = finalClassifierDset.classes
|
| 141 |
# return class_names[pred_label]
|
|
|
|
|
|
|
| 142 |
class_names = ['Aayush', 'Aditya', 'Vikram']
|
| 143 |
-
return class_names[pred_label]
|
|
|
|
| 108 |
|
| 109 |
# 1 Load the Decision Tree classifier
|
| 110 |
# clf_path = os.path.join(BASE_DIR, "decision_tree_model.sav")
|
| 111 |
+
clf_path = os.path.join(BASE_DIR, "logistic_regression_2.sav")
|
| 112 |
clf = joblib.load(clf_path)
|
| 113 |
|
| 114 |
+
scaler_path = os.path.join(BASE_DIR, "standard_scaler.sav")
|
| 115 |
+
scaler = joblib.load(scaler_path)
|
| 116 |
+
|
| 117 |
# 2 Load the Siamese feature extractor
|
| 118 |
myModel = Siamese().to(device)
|
| 119 |
ckpt_path = os.path.join(BASE_DIR, "siamese_model.t7")
|
|
|
|
| 136 |
embedding = embedding.view(embedding.size(0), -1).cpu().numpy() # shape (1, embedding_dim)
|
| 137 |
|
| 138 |
# 6 Predict class using Decision Tree
|
| 139 |
+
# pred_label = clf.predict(scaler.transform(embedding))[0]
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
# --- Predict ---
|
| 143 |
+
scaled_emb = scaler.transform(embedding)
|
| 144 |
+
probs = clf.predict_proba(scaled_emb)
|
| 145 |
+
pred_label = np.argmax(probs)
|
| 146 |
+
confidence = probs[0, pred_label]
|
| 147 |
+
|
| 148 |
+
|
| 149 |
|
| 150 |
# 7 Optional: return class name (if available)
|
| 151 |
# If you have the dataset available:
|
| 152 |
# class_names = finalClassifierDset.classes
|
| 153 |
# return class_names[pred_label]
|
| 154 |
+
# class_names = ['Aayush', 'Aditya', 'Vikram']
|
| 155 |
+
# return class_names[pred_label] + " " + str(pred_label)
|
| 156 |
class_names = ['Aayush', 'Aditya', 'Vikram']
|
| 157 |
+
return f"{class_names[pred_label]} ({confidence:.2f})"
|
app/Hackathon_setup/logistic_regression_2.sav
ADDED
|
Binary file (1.02 kB). View file
|
|
|
app/Hackathon_setup/standar_scaler.sav
ADDED
|
Binary file (719 Bytes). View file
|
|
|