Spaces:
Runtime error
Runtime error
fix variables again :P
Browse files
app.py
CHANGED
@@ -26,10 +26,10 @@ def find_similar(image):
|
|
26 |
photo_preprocessed = processor(text=None, images=image, return_tensors="pt", padding=True)["pixel_values"]
|
27 |
search_photo_feature = model.get_image_features(photo_preprocessed.to(device))
|
28 |
search_photo_feature /= search_photo_feature.norm(dim=-1, keepdim=True)
|
29 |
-
|
30 |
|
31 |
## Find similarity
|
32 |
-
similarities = list((
|
33 |
|
34 |
## Return best image :)
|
35 |
best_photo = sorted(zip(similarities, range(photo_features.shape[0])), key=lambda x: x[0], reverse=True)[0]
|
|
|
26 |
photo_preprocessed = processor(text=None, images=image, return_tensors="pt", padding=True)["pixel_values"]
|
27 |
search_photo_feature = model.get_image_features(photo_preprocessed.to(device))
|
28 |
search_photo_feature /= search_photo_feature.norm(dim=-1, keepdim=True)
|
29 |
+
search_photo_feature = search_photo_feature.cpu().numpy()
|
30 |
|
31 |
## Find similarity
|
32 |
+
similarities = list((search_photo_feature @ photo_features.T).squeeze(0))
|
33 |
|
34 |
## Return best image :)
|
35 |
best_photo = sorted(zip(similarities, range(photo_features.shape[0])), key=lambda x: x[0], reverse=True)[0]
|