Spaces:
Build error
Build error
Commit
·
ed481cf
1
Parent(s):
d121302
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,7 @@ def similarity_all(query_image_name, embeddings, metric):
|
|
32 |
scores = {image_name : metric(querry_embedding, embeddings[image_name]) for image_name in images}
|
33 |
return scores
|
34 |
|
35 |
-
def
|
36 |
return np.linalg.norm(query_embedding-target_embedding)
|
37 |
|
38 |
def cosine_similarity_score(query_embedding, target_embedding):
|
@@ -47,8 +47,8 @@ def retrieve(query_image_name, embeddings_type, metric_type):
|
|
47 |
else :
|
48 |
embeddings = naive_embeddings
|
49 |
|
50 |
-
if metric_type == '
|
51 |
-
metric =
|
52 |
else :
|
53 |
metric = cosine_similarity_score
|
54 |
|
@@ -59,7 +59,7 @@ def retrieve(query_image_name, embeddings_type, metric_type):
|
|
59 |
|
60 |
input_button = gr.inputs.Dropdown(query_images, label='Choice of the query image')
|
61 |
embeddings_selection = gr.inputs.Radio(['MobileNetV2', 'BoVW', 'Baseline'], label='Embeddings')
|
62 |
-
metric_selection = gr.inputs.Radio(['
|
63 |
retrieved_images = gr.outputs.Carousel(["image"]*10, label='Retrieved images')
|
64 |
|
65 |
description = "This is a demo of the content-based image retrieval system developed as part of the IR course project, 2022. The indexed dataset is [INRIA Holidays](https://lear.inrialpes.fr/~jegou/data.php). \n\nSeveral image embeddings can be used :\n \n-**MobileNetV2** : feature extraction is performed using a MobileNet architecture trained on ImageNet.\n\n-**BoVW (Bag of Visual Words)** : embedding is the BoVW histogram using color histogram as a descriptor.\n\n-**Baseline** : basic descriptor that uses pixel values of the downsized images."
|
|
|
32 |
scores = {image_name : metric(querry_embedding, embeddings[image_name]) for image_name in images}
|
33 |
return scores
|
34 |
|
35 |
+
def euclidean_similarity_score(query_embedding, target_embedding):
|
36 |
return np.linalg.norm(query_embedding-target_embedding)
|
37 |
|
38 |
def cosine_similarity_score(query_embedding, target_embedding):
|
|
|
47 |
else :
|
48 |
embeddings = naive_embeddings
|
49 |
|
50 |
+
if metric_type == 'Euclidean' :
|
51 |
+
metric = euclidean_similarity_score
|
52 |
else :
|
53 |
metric = cosine_similarity_score
|
54 |
|
|
|
59 |
|
60 |
input_button = gr.inputs.Dropdown(query_images, label='Choice of the query image')
|
61 |
embeddings_selection = gr.inputs.Radio(['MobileNetV2', 'BoVW', 'Baseline'], label='Embeddings')
|
62 |
+
metric_selection = gr.inputs.Radio(['Euclidean', 'Cosine'], label='Similarity Metric')
|
63 |
retrieved_images = gr.outputs.Carousel(["image"]*10, label='Retrieved images')
|
64 |
|
65 |
description = "This is a demo of the content-based image retrieval system developed as part of the IR course project, 2022. The indexed dataset is [INRIA Holidays](https://lear.inrialpes.fr/~jegou/data.php). \n\nSeveral image embeddings can be used :\n \n-**MobileNetV2** : feature extraction is performed using a MobileNet architecture trained on ImageNet.\n\n-**BoVW (Bag of Visual Words)** : embedding is the BoVW histogram using color histogram as a descriptor.\n\n-**Baseline** : basic descriptor that uses pixel values of the downsized images."
|