Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update similarity.py
Browse files- similarity.py +4 -4
similarity.py
CHANGED
@@ -32,7 +32,7 @@ def preprocess_image_for_mobilenet(image):
|
|
32 |
|
33 |
return image
|
34 |
|
35 |
-
def mobilenet_sim(img1, img2):
|
36 |
try:
|
37 |
img1_proc = preprocess_image_for_mobilenet(img1)
|
38 |
img2_proc = preprocess_image_for_mobilenet(img2)
|
@@ -42,13 +42,13 @@ def mobilenet_sim(img1, img2):
|
|
42 |
|
43 |
sim = cosine_similarity(feat1, feat2)[0][0]
|
44 |
sim_score = (sim + 1) * 50
|
45 |
-
print(f"MobileNet similarity score is {sim_score}")
|
46 |
return float(sim_score)
|
47 |
except Exception as e:
|
48 |
logging.error("Erro ao calcular similaridade com MobileNet", exc_info=True)
|
49 |
return 0
|
50 |
|
51 |
-
def orb_sim(img1, img2):
|
52 |
score = 0
|
53 |
|
54 |
try:
|
@@ -62,7 +62,7 @@ def orb_sim(img1, img2):
|
|
62 |
if len(matches) > 0:
|
63 |
score = (len(similar_regions) / len(matches)) * 100
|
64 |
if (score > 0):
|
65 |
-
logging.info(f"Orb score is {score}")
|
66 |
except Exception as e:
|
67 |
logging.error("Erro ao verificar similaridade ORB", exc_info=True)
|
68 |
|
|
|
32 |
|
33 |
return image
|
34 |
|
35 |
+
def mobilenet_sim(img1, img2, img1AssetCode, img2AssetCode):
|
36 |
try:
|
37 |
img1_proc = preprocess_image_for_mobilenet(img1)
|
38 |
img2_proc = preprocess_image_for_mobilenet(img2)
|
|
|
42 |
|
43 |
sim = cosine_similarity(feat1, feat2)[0][0]
|
44 |
sim_score = (sim + 1) * 50
|
45 |
+
print(f"MobileNet similarity score from {img1AssetCode} and {img2AssetCode} is {sim_score}")
|
46 |
return float(sim_score)
|
47 |
except Exception as e:
|
48 |
logging.error("Erro ao calcular similaridade com MobileNet", exc_info=True)
|
49 |
return 0
|
50 |
|
51 |
+
def orb_sim(img1, img2, img1AssetCode, img2AssetCode):
|
52 |
score = 0
|
53 |
|
54 |
try:
|
|
|
62 |
if len(matches) > 0:
|
63 |
score = (len(similar_regions) / len(matches)) * 100
|
64 |
if (score > 0):
|
65 |
+
logging.info(f"Orb score from {img1AssetCode} and {img2AssetCode} is {score}")
|
66 |
except Exception as e:
|
67 |
logging.error("Erro ao verificar similaridade ORB", exc_info=True)
|
68 |
|