Commit ·
d70573e
1
Parent(s): 79b9d94
face recognition
Browse files
app/Hackathon_setup/SVC_3.sav
ADDED
|
Binary file (3.16 kB). View file
|
|
|
app/Hackathon_setup/face_recognition.py
CHANGED
|
@@ -159,12 +159,12 @@ def get_similarity(img1, img2):
|
|
| 159 |
|
| 160 |
def get_face_class(img1):
|
| 161 |
|
| 162 |
-
device = torch.device("cuda
|
| 163 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 164 |
|
| 165 |
# 1 Load the Decision Tree classifier
|
| 166 |
# clf_path = os.path.join(BASE_DIR, "decision_tree_model.sav")
|
| 167 |
-
clf_path = os.path.join(BASE_DIR, "
|
| 168 |
clf = joblib.load(clf_path)
|
| 169 |
|
| 170 |
scaler_path = os.path.join(BASE_DIR, "standar_scaler.sav")
|
|
@@ -177,7 +177,7 @@ def get_face_class(img1):
|
|
| 177 |
myModel.load_state_dict(ckpt['net_dict'])
|
| 178 |
myModel.eval()
|
| 179 |
|
| 180 |
-
img_tensor =
|
| 181 |
|
| 182 |
with torch.no_grad():
|
| 183 |
embedding = myModel.forward_once(img_tensor)
|
|
@@ -185,7 +185,7 @@ def get_face_class(img1):
|
|
| 185 |
pred_label = clf.predict(scaler.transform(embedding))[0]
|
| 186 |
|
| 187 |
class_names = ['Aayush', 'Aditya', 'Vikram']
|
| 188 |
-
return f"{class_names[pred_label]} {pred_label}"
|
| 189 |
|
| 190 |
|
| 191 |
# def get_face_class(img1):
|
|
|
|
| 159 |
|
| 160 |
def get_face_class(img1):
|
| 161 |
|
| 162 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 163 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 164 |
|
| 165 |
# 1 Load the Decision Tree classifier
|
| 166 |
# clf_path = os.path.join(BASE_DIR, "decision_tree_model.sav")
|
| 167 |
+
clf_path = os.path.join(BASE_DIR, "SVC_3.sav")
|
| 168 |
clf = joblib.load(clf_path)
|
| 169 |
|
| 170 |
scaler_path = os.path.join(BASE_DIR, "standar_scaler.sav")
|
|
|
|
| 177 |
myModel.load_state_dict(ckpt['net_dict'])
|
| 178 |
myModel.eval()
|
| 179 |
|
| 180 |
+
img_tensor = transform1(img1).unsqueeze(0)
|
| 181 |
|
| 182 |
with torch.no_grad():
|
| 183 |
embedding = myModel.forward_once(img_tensor)
|
|
|
|
| 185 |
pred_label = clf.predict(scaler.transform(embedding))[0]
|
| 186 |
|
| 187 |
class_names = ['Aayush', 'Aditya', 'Vikram']
|
| 188 |
+
return f"{class_names[pred_label]} {pred_label} {embedding}"
|
| 189 |
|
| 190 |
|
| 191 |
# def get_face_class(img1):
|
app/Hackathon_setup/face_recognition_model.py
CHANGED
|
@@ -17,6 +17,9 @@ trnscm = transforms.Compose([
|
|
| 17 |
transforms.Normalize(mean=[0.5], std=[0.5])
|
| 18 |
])
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
##Example Network
|
| 21 |
class Siamese(torch.nn.Module):
|
| 22 |
def __init__(self):
|
|
|
|
| 17 |
transforms.Normalize(mean=[0.5], std=[0.5])
|
| 18 |
])
|
| 19 |
|
| 20 |
+
transform1 = transforms.Compose([transforms.Grayscale(num_output_channels = 1),
|
| 21 |
+
transforms.Resize((100,100)), transforms.ToTensor()])
|
| 22 |
+
|
| 23 |
##Example Network
|
| 24 |
class Siamese(torch.nn.Module):
|
| 25 |
def __init__(self):
|