Spaces:
Sleeping
Sleeping
similarity code is updated02
Browse files
app/Hackathon_setup/face_recognition.py
CHANGED
|
@@ -94,13 +94,13 @@ def get_similarity(img1, img2):
|
|
| 94 |
|
| 95 |
output1,output2 = feature_net(Variable(face1),Variable(face2))
|
| 96 |
euclidean_distance = F.pairwise_distance(output1, output2)
|
| 97 |
-
#
|
| 98 |
-
#
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
|
| 101 |
-
dissimilarity = euclidean_distance.item()
|
| 102 |
-
|
| 103 |
-
return dissimilarity
|
| 104 |
|
| 105 |
|
| 106 |
# 1) Image captured from mobile is passed as parameter to this function in the API call, It returns the face class in the string form ex: "Person1"
|
|
|
|
| 94 |
|
| 95 |
output1,output2 = feature_net(Variable(face1),Variable(face2))
|
| 96 |
euclidean_distance = F.pairwise_distance(output1, output2)
|
| 97 |
+
#pairwise - more distance means less similarity
|
| 98 |
+
#cosine similarity - more means more similarity btwn 2 arrays
|
| 99 |
+
# Use euclidean similarity to measure the similarity between given two images
|
| 100 |
+
euc_similarity = euclidean_distance.item()
|
| 101 |
+
cos_similarity = torch.nn.functional.cosine_similarity(face1, face2).item()
|
| 102 |
|
| 103 |
+
return cos_similarity
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
|
| 106 |
# 1) Image captured from mobile is passed as parameter to this function in the API call, It returns the face class in the string form ex: "Person1"
|