Spaces:
Running
Running
JohnAlexander23
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,7 @@ def dict2namespace(config):
|
|
26 |
setattr(namespace, key, new_value)
|
27 |
return namespace
|
28 |
|
29 |
-
def load_img
|
30 |
img = np.array(Image.open(filename).convert("RGB"))
|
31 |
h, w = img.shape[:2]
|
32 |
|
@@ -39,20 +39,19 @@ def load_img (filename, norm=True,):
|
|
39 |
img = img.astype(np.float32)
|
40 |
return img
|
41 |
|
42 |
-
def process_img
|
43 |
img = np.array(image)
|
44 |
img = img / 255.
|
45 |
img = img.astype(np.float32)
|
46 |
-
y = torch.tensor(img).permute(2,0,1).unsqueeze(0).to(device)
|
47 |
|
48 |
with torch.no_grad():
|
49 |
x_hat = model(y)
|
50 |
|
51 |
-
restored_img = x_hat.squeeze().permute(1,2,0).clamp_(0, 1).cpu().detach().numpy()
|
52 |
-
restored_img = np.clip(restored_img, 0
|
53 |
|
54 |
restored_img = (restored_img * 255.0).round().astype(np.uint8) # float32 to uint8
|
55 |
-
#return Image.fromarray(restored_img) #
|
56 |
return (image, Image.fromarray(restored_img))
|
57 |
|
58 |
def load_network(net, load_path, strict=True, param_key='params'):
|
@@ -87,29 +86,25 @@ model = seemore.SeemoRe(scale=cfg.model.scale, in_chans=cfg.model.in_chans,
|
|
87 |
recursive=cfg.model.recursive, lr_space=cfg.model.lr_space, topk=cfg.model.topk)
|
88 |
|
89 |
model = model.to(device)
|
90 |
-
print
|
91 |
load_network(model, MODEL_NAME, strict=True, param_key='params')
|
92 |
|
93 |
|
94 |
-
|
95 |
-
|
96 |
title = "See More Details"
|
97 |
description = ''' ### See More Details: Efficient Image Super-Resolution by Experts Mining - ICML 2024, Vienna, Austria
|
98 |
-
####
|
99 |
-
#### **<sup>1</sup> University of Würzburg, Germany - <sup>2</sup> Shanghai Jiao Tong University, China - <sup>3</sup> ETH Zürich, Switzerland**
|
100 |
-
#### **<sup>*</sup> Corresponding authors**
|
101 |
<details>
|
102 |
<summary> <b> Abstract</b> (click me to read)</summary>
|
103 |
<p>
|
104 |
Reconstructing high-resolution (HR) images from low-resolution (LR) inputs poses a significant challenge in image super-resolution (SR). While recent approaches have demonstrated the efficacy of intricate operations customized for various objectives, the straightforward stacking of these disparate operations can result in a substantial computational burden, hampering their practical utility. In response, we introduce **S**eemo**R**e, an efficient SR model employing expert mining. Our approach strategically incorporates experts at different levels, adopting a collaborative methodology. At the macro scale, our experts address rank-wise and spatial-wise informative features, providing a holistic understanding. Subsequently, the model delves into the subtleties of rank choice by leveraging a mixture of low-rank experts. By tapping into experts specialized in distinct key factors crucial for accurate SR, our model excels in uncovering intricate intra-feature details. This collaborative approach is reminiscent of the concept of **see more**, allowing our model to achieve an optimal performance with minimal computational costs in efficient settings
|
105 |
</p>
|
106 |
</details>
|
107 |
-
####
|
108 |
<br>
|
109 |
<code>
|
110 |
@inproceedings{zamfir2024details,
|
111 |
title={See More Details: Efficient Image Super-Resolution by Experts Mining},
|
112 |
-
author={
|
113 |
booktitle={International Conference on Machine Learning},
|
114 |
year={2024},
|
115 |
organization={PMLR}
|
@@ -118,9 +113,6 @@ Reconstructing high-resolution (HR) images from low-resolution (LR) inputs poses
|
|
118 |
<br>
|
119 |
'''
|
120 |
|
121 |
-
|
122 |
-
article = "<p style='text-align: center'><a href='https://eduardzamfir.github.io/seemore' target='_blank'>See More Details: Efficient Image Super-Resolution by Experts Mining</a></p>"
|
123 |
-
|
124 |
#### Image,Prompts examples
|
125 |
examples = [
|
126 |
['images/0801x4.png'],
|
@@ -150,14 +142,13 @@ css = """
|
|
150 |
|
151 |
demo = gr.Interface(
|
152 |
fn=process_img,
|
153 |
-
inputs=[gr.Image(type="pil", label="Input", value="images/0878x4.png")
|
154 |
outputs=ImageSlider(label="Super-Resolved Image",
|
155 |
type="pil",
|
156 |
show_download_button=True,
|
157 |
), #[gr.Image(type="pil", label="Ouput", min_width=500)],
|
158 |
title=title,
|
159 |
description=description,
|
160 |
-
article=article,
|
161 |
examples=examples,
|
162 |
css=css,
|
163 |
)
|
|
|
26 |
setattr(namespace, key, new_value)
|
27 |
return namespace
|
28 |
|
29 |
+
def load_img(filename, norm=True):
|
30 |
img = np.array(Image.open(filename).convert("RGB"))
|
31 |
h, w = img.shape[:2]
|
32 |
|
|
|
39 |
img = img.astype(np.float32)
|
40 |
return img
|
41 |
|
42 |
+
def process_img(image):
|
43 |
img = np.array(image)
|
44 |
img = img / 255.
|
45 |
img = img.astype(np.float32)
|
46 |
+
y = torch.tensor(img).permute(2, 0, 1).unsqueeze(0).to(device)
|
47 |
|
48 |
with torch.no_grad():
|
49 |
x_hat = model(y)
|
50 |
|
51 |
+
restored_img = x_hat.squeeze().permute(1, 2, 0).clamp_(0, 1).cpu().detach().numpy()
|
52 |
+
restored_img = np.clip(restored_img, 0., 1.)
|
53 |
|
54 |
restored_img = (restored_img * 255.0).round().astype(np.uint8) # float32 to uint8
|
|
|
55 |
return (image, Image.fromarray(restored_img))
|
56 |
|
57 |
def load_network(net, load_path, strict=True, param_key='params'):
|
|
|
86 |
recursive=cfg.model.recursive, lr_space=cfg.model.lr_space, topk=cfg.model.topk)
|
87 |
|
88 |
model = model.to(device)
|
89 |
+
print("IMAGE MODEL CKPT:", MODEL_NAME)
|
90 |
load_network(model, MODEL_NAME, strict=True, param_key='params')
|
91 |
|
92 |
|
|
|
|
|
93 |
title = "See More Details"
|
94 |
description = ''' ### See More Details: Efficient Image Super-Resolution by Experts Mining - ICML 2024, Vienna, Austria
|
95 |
+
#### This work is done by DL Titans
|
|
|
|
|
96 |
<details>
|
97 |
<summary> <b> Abstract</b> (click me to read)</summary>
|
98 |
<p>
|
99 |
Reconstructing high-resolution (HR) images from low-resolution (LR) inputs poses a significant challenge in image super-resolution (SR). While recent approaches have demonstrated the efficacy of intricate operations customized for various objectives, the straightforward stacking of these disparate operations can result in a substantial computational burden, hampering their practical utility. In response, we introduce **S**eemo**R**e, an efficient SR model employing expert mining. Our approach strategically incorporates experts at different levels, adopting a collaborative methodology. At the macro scale, our experts address rank-wise and spatial-wise informative features, providing a holistic understanding. Subsequently, the model delves into the subtleties of rank choice by leveraging a mixture of low-rank experts. By tapping into experts specialized in distinct key factors crucial for accurate SR, our model excels in uncovering intricate intra-feature details. This collaborative approach is reminiscent of the concept of **see more**, allowing our model to achieve an optimal performance with minimal computational costs in efficient settings
|
100 |
</p>
|
101 |
</details>
|
102 |
+
#### Drag the slider on the super-resolution image left and right to see the changes in the image details. SeemoRe performs x4 upscaling on the input image.
|
103 |
<br>
|
104 |
<code>
|
105 |
@inproceedings{zamfir2024details,
|
106 |
title={See More Details: Efficient Image Super-Resolution by Experts Mining},
|
107 |
+
author={DL Titans},
|
108 |
booktitle={International Conference on Machine Learning},
|
109 |
year={2024},
|
110 |
organization={PMLR}
|
|
|
113 |
<br>
|
114 |
'''
|
115 |
|
|
|
|
|
|
|
116 |
#### Image,Prompts examples
|
117 |
examples = [
|
118 |
['images/0801x4.png'],
|
|
|
142 |
|
143 |
demo = gr.Interface(
|
144 |
fn=process_img,
|
145 |
+
inputs=[gr.Image(type="pil", label="Input", value="images/0878x4.png")],
|
146 |
outputs=ImageSlider(label="Super-Resolved Image",
|
147 |
type="pil",
|
148 |
show_download_button=True,
|
149 |
), #[gr.Image(type="pil", label="Ouput", min_width=500)],
|
150 |
title=title,
|
151 |
description=description,
|
|
|
152 |
examples=examples,
|
153 |
css=css,
|
154 |
)
|