Spaces:
Sleeping
Sleeping
Sudipta Nayak
commited on
Commit
·
df6f630
1
Parent(s):
6c8b9f2
no message
Browse files
app/Hackathon_setup/face_recognition.py
CHANGED
@@ -112,14 +112,23 @@ def get_face_class(img1):
|
|
112 |
##Hint: you need a classifier finetuned for your classes, it takes o/p of siamese as i/p to it
|
113 |
##Better Hint: Siamese experiment is covered in one of the labs
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
feature_net = SiameseNetwork() #Example Network
|
116 |
feature_net = feature_net.to(device)
|
117 |
current_path = 'app/Hackathon_setup'
|
118 |
model = torch.load(current_path + '/siamese_model_recog.t7', map_location=device)
|
119 |
feature_net.load_state_dict(model['net_dict'])
|
120 |
|
121 |
-
output1 = feature_net.forward_once(
|
122 |
-
probabilities = torch.softmax(
|
123 |
predicted_class = torch.argmax(probabilities, dim=1).item()
|
124 |
|
125 |
return predicted_class
|
|
|
112 |
##Hint: you need a classifier finetuned for your classes, it takes o/p of siamese as i/p to it
|
113 |
##Better Hint: Siamese experiment is covered in one of the labs
|
114 |
|
115 |
+
transform = transforms.Compose([
|
116 |
+
transforms.Resize((100, 100)), # Resize the image to the desired size
|
117 |
+
transforms.ToTensor(), # Convert the image to a PyTorch tensor
|
118 |
+
transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]) # Normalize if needed
|
119 |
+
])
|
120 |
+
|
121 |
+
# Apply the transformations to the image
|
122 |
+
det_img1_tensor = transform(image)
|
123 |
+
|
124 |
feature_net = SiameseNetwork() #Example Network
|
125 |
feature_net = feature_net.to(device)
|
126 |
current_path = 'app/Hackathon_setup'
|
127 |
model = torch.load(current_path + '/siamese_model_recog.t7', map_location=device)
|
128 |
feature_net.load_state_dict(model['net_dict'])
|
129 |
|
130 |
+
output1 = feature_net.forward_once(det_img1_tensor)
|
131 |
+
probabilities = torch.softmax(output1, dim=1)
|
132 |
predicted_class = torch.argmax(probabilities, dim=1).item()
|
133 |
|
134 |
return predicted_class
|