Spaces:
Running
Running
Display scores
Browse files
app.py
CHANGED
@@ -27,6 +27,7 @@ st.markdown("""Search for medical images with natural language powered by a CLIP
|
|
27 |
[Radiology Objects in COntext (ROCO) dataset](https://github.com/razorx89/roco-dataset).""")
|
28 |
st.markdown("""Example queries:
|
29 |
* `ultrasound scans`
|
|
|
30 |
* `PET scan`""")
|
31 |
|
32 |
image_list, image_embeddings = load_image_embeddings()
|
@@ -43,11 +44,13 @@ if st.button("Search"):
|
|
43 |
query_embedding = np.asarray(query_embedding)
|
44 |
query_embedding = query_embedding / np.linalg.norm(query_embedding, axis=-1, keepdims=True)
|
45 |
dot_prod = np.sum(np.multiply(query_embedding, image_embeddings), axis=1)
|
46 |
-
|
|
|
|
|
47 |
#show images
|
48 |
|
49 |
-
for img_path in matching_images:
|
50 |
img = plt.imread(os.path.join(img_dir, img_path))
|
51 |
-
st.write(img_path)
|
52 |
st.image(img)
|
|
|
53 |
|
|
|
27 |
[Radiology Objects in COntext (ROCO) dataset](https://github.com/razorx89/roco-dataset).""")
|
28 |
st.markdown("""Example queries:
|
29 |
* `ultrasound scans`
|
30 |
+
* `pathology`
|
31 |
* `PET scan`""")
|
32 |
|
33 |
image_list, image_embeddings = load_image_embeddings()
|
|
|
44 |
query_embedding = np.asarray(query_embedding)
|
45 |
query_embedding = query_embedding / np.linalg.norm(query_embedding, axis=-1, keepdims=True)
|
46 |
dot_prod = np.sum(np.multiply(query_embedding, image_embeddings), axis=1)
|
47 |
+
topk_images = dot_prod.argsort()[-k:]
|
48 |
+
matching_images = image_list[topk_images]
|
49 |
+
top_scores = 1. - dot_prod[topk_images]
|
50 |
#show images
|
51 |
|
52 |
+
for img_path, score in zip(matching_images, top_scores):
|
53 |
img = plt.imread(os.path.join(img_dir, img_path))
|
|
|
54 |
st.image(img)
|
55 |
+
st.write(f"{img_path} ({score:.2f})", help="score")
|
56 |
|