Spaces:
Sleeping
Sleeping
backup
Browse files
app.py
CHANGED
|
@@ -91,9 +91,9 @@ def NormalizeData(data):
|
|
| 91 |
|
| 92 |
|
| 93 |
# Visualization
|
| 94 |
-
def visualize_similarities(
|
| 95 |
-
image1 = Image.fromarray(
|
| 96 |
-
image2 = Image.fromarray(
|
| 97 |
|
| 98 |
a = get_layer4(image1).squeeze()
|
| 99 |
b = get_layer4(image2).squeeze()
|
|
@@ -121,10 +121,35 @@ def visualize_similarities(image1, image2):
|
|
| 121 |
vmax=1,
|
| 122 |
)
|
| 123 |
|
|
|
|
|
|
|
|
|
|
| 124 |
fig.colorbar(im1, ax=axes[0])
|
| 125 |
fig.colorbar(im2, ax=axes[1])
|
| 126 |
plt.tight_layout()
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
|
| 130 |
# GRADIO APP
|
|
@@ -132,14 +157,15 @@ main = gr.Interface(
|
|
| 132 |
fn=visualize_similarities,
|
| 133 |
inputs=["image", "image"],
|
| 134 |
allow_flagging="never",
|
| 135 |
-
outputs="plot",
|
| 136 |
cache_examples=True,
|
| 137 |
enable_queue=False,
|
| 138 |
examples=[
|
| 139 |
[
|
| 140 |
"./examples/Red_Winged_Blackbird_0012_6015.jpg",
|
| 141 |
"./examples/Red_Winged_Blackbird_0025_5342.jpg",
|
| 142 |
-
]
|
|
|
|
| 143 |
],
|
| 144 |
)
|
| 145 |
|
|
|
|
| 91 |
|
| 92 |
|
| 93 |
# Visualization
|
| 94 |
+
def visualize_similarities(q, n):
|
| 95 |
+
image1 = Image.fromarray(q)
|
| 96 |
+
image2 = Image.fromarray(n)
|
| 97 |
|
| 98 |
a = get_layer4(image1).squeeze()
|
| 99 |
b = get_layer4(image2).squeeze()
|
|
|
|
| 121 |
vmax=1,
|
| 122 |
)
|
| 123 |
|
| 124 |
+
axes[0].set_axis_off()
|
| 125 |
+
axes[1].set_axis_off()
|
| 126 |
+
|
| 127 |
fig.colorbar(im1, ax=axes[0])
|
| 128 |
fig.colorbar(im2, ax=axes[1])
|
| 129 |
plt.tight_layout()
|
| 130 |
+
|
| 131 |
+
q_image = display_transform(image1)
|
| 132 |
+
nearest_image = display_transform(image2)
|
| 133 |
+
|
| 134 |
+
# make a binarized veruin of the Q
|
| 135 |
+
fig2, ax = plt.subplots(1, figsize=(5, 5))
|
| 136 |
+
ax.imshow(display_transform(image1))
|
| 137 |
+
|
| 138 |
+
# create a binarized version of sim1 , for value below 0.5 set to 0 and above 0.5 set to 1
|
| 139 |
+
sim1_bin = np.where(sim1 > 0.5, 1, 0)
|
| 140 |
+
print(sim1_bin)
|
| 141 |
+
# create a binarized version of sim2 , for value below 0.5 set to 0 and above 0.5 set to 1
|
| 142 |
+
sim2_bin = np.where(sim2 > 0.5, 1, 0)
|
| 143 |
+
|
| 144 |
+
ax.imshow(
|
| 145 |
+
skimage.transform.resize(sim1_bin, (224, 224)),
|
| 146 |
+
alpha=1,
|
| 147 |
+
cmap="binary",
|
| 148 |
+
vmin=0,
|
| 149 |
+
vmax=1,
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
return fig, q_image, nearest_image, fig2
|
| 153 |
|
| 154 |
|
| 155 |
# GRADIO APP
|
|
|
|
| 157 |
fn=visualize_similarities,
|
| 158 |
inputs=["image", "image"],
|
| 159 |
allow_flagging="never",
|
| 160 |
+
outputs=["plot", "image", "image", "plot"],
|
| 161 |
cache_examples=True,
|
| 162 |
enable_queue=False,
|
| 163 |
examples=[
|
| 164 |
[
|
| 165 |
"./examples/Red_Winged_Blackbird_0012_6015.jpg",
|
| 166 |
"./examples/Red_Winged_Blackbird_0025_5342.jpg",
|
| 167 |
+
],
|
| 168 |
+
["./examples/Q.jpg", "./examples/1.jpg"],
|
| 169 |
],
|
| 170 |
)
|
| 171 |
|