Thiago Hersan
commited on
Commit
·
7926918
1
Parent(s):
2b921c5
try cosine distances
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import json
|
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
| 5 |
|
| 6 |
-
from sklearn.metrics import euclidean_distances
|
| 7 |
|
| 8 |
from transformers import AutoModel, AutoProcessor
|
| 9 |
|
|
@@ -27,7 +27,7 @@ def get_embedding(img):
|
|
| 27 |
|
| 28 |
def find_in_art(img):
|
| 29 |
target_embedding = get_embedding(img)
|
| 30 |
-
dists =
|
| 31 |
idxs_by_dist = dists.argsort()
|
| 32 |
all_crops_by_dist = crop_names[idxs_by_dist]
|
| 33 |
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
from sklearn.metrics.pairwise import euclidean_distances, cosine_distances
|
| 7 |
|
| 8 |
from transformers import AutoModel, AutoProcessor
|
| 9 |
|
|
|
|
| 27 |
|
| 28 |
def find_in_art(img):
|
| 29 |
target_embedding = get_embedding(img)
|
| 30 |
+
dists = cosine_distances(crop_embeddings, [target_embedding]).reshape(-1)
|
| 31 |
idxs_by_dist = dists.argsort()
|
| 32 |
all_crops_by_dist = crop_names[idxs_by_dist]
|
| 33 |
|