Spaces:
Sleeping
Sleeping
Commit
·
af03c71
1
Parent(s):
6bca9ba
bug fix
Browse files
app.py
CHANGED
@@ -41,7 +41,7 @@ def show_image(img, title):
|
|
41 |
plt.title(title)
|
42 |
|
43 |
# Visualize a Single Image
|
44 |
-
def visualize_single_image(image_path
|
45 |
img = load_image(image_path, transform).to(device)
|
46 |
|
47 |
# Run inference
|
@@ -56,46 +56,38 @@ def visualize_single_image(image_path, image_name, model, device):
|
|
56 |
# MAE reconstruction pasted with visible patches
|
57 |
im_paste = img * (1 - mask) + predicted_img * mask
|
58 |
|
59 |
-
|
60 |
-
|
61 |
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
66 |
-
|
67 |
|
68 |
-
|
69 |
-
|
70 |
|
71 |
-
|
72 |
-
|
73 |
|
74 |
-
|
75 |
|
76 |
-
return
|
77 |
-
|
78 |
-
# Example Usage
|
79 |
-
image_path = 'images/dog.jpg' # Replace with the actual path to your image
|
80 |
-
# take the string after the last '/' as the image name
|
81 |
-
image_name = image_path.split('/')[-1].split('.')[0]
|
82 |
-
visualize_single_image(image_path, image_name, model, device)
|
83 |
|
84 |
inputs_image = [
|
85 |
gr.components.Image(type="filepath", label="Input Image"),
|
86 |
]
|
87 |
|
88 |
outputs_image = [
|
89 |
-
gr.components.Image(type="
|
90 |
]
|
91 |
|
92 |
gr.Interface(
|
93 |
fn=visualize_single_image,
|
94 |
inputs=inputs_image,
|
95 |
outputs=outputs_image,
|
|
|
96 |
title="MAE-ViT Image Reconstruction",
|
97 |
description="This is a demo of the MAE-ViT model for image reconstruction.",
|
98 |
-
allow_flagging=False,
|
99 |
-
allow_screenshot=False,
|
100 |
-
allow_remote_access=False,
|
101 |
).launch()
|
|
|
41 |
plt.title(title)
|
42 |
|
43 |
# Visualize a Single Image
|
44 |
+
def visualize_single_image(image_path):
|
45 |
img = load_image(image_path, transform).to(device)
|
46 |
|
47 |
# Run inference
|
|
|
56 |
# MAE reconstruction pasted with visible patches
|
57 |
im_paste = img * (1 - mask) + predicted_img * mask
|
58 |
|
59 |
+
# # make the plt figure larger
|
60 |
+
# plt.figure(figsize=(12, 4))
|
61 |
|
62 |
+
# plt.subplot(1, 4, 1)
|
63 |
+
# show_image(img[0], "original")
|
64 |
|
65 |
+
# plt.subplot(1, 4, 2)
|
66 |
+
# show_image(im_masked[0], "masked")
|
67 |
|
68 |
+
# plt.subplot(1, 4, 3)
|
69 |
+
# show_image(predicted_img[0], "reconstruction")
|
70 |
|
71 |
+
# plt.subplot(1, 4, 4)
|
72 |
+
# show_image(im_paste[0], "reconstruction + visible")
|
73 |
|
74 |
+
# plt.tight_layout()
|
75 |
|
76 |
+
return img[0].numpy(), im_masked[0].numpy(), predicted_img[0].numpy(), im_paste[0].numpy()
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
inputs_image = [
|
79 |
gr.components.Image(type="filepath", label="Input Image"),
|
80 |
]
|
81 |
|
82 |
outputs_image = [
|
83 |
+
gr.components.Image(type="numpy", label="Output Image"),
|
84 |
]
|
85 |
|
86 |
gr.Interface(
|
87 |
fn=visualize_single_image,
|
88 |
inputs=inputs_image,
|
89 |
outputs=outputs_image,
|
90 |
+
examples=path,
|
91 |
title="MAE-ViT Image Reconstruction",
|
92 |
description="This is a demo of the MAE-ViT model for image reconstruction.",
|
|
|
|
|
|
|
93 |
).launch()
|