Spaces:
Running
Running
Hu
commited on
Commit
·
840ed11
1
Parent(s):
60caba2
change input output
Browse files
app.py
CHANGED
|
@@ -10,10 +10,9 @@ from PIL import Image
|
|
| 10 |
title = "Super Resolution with CNN"
|
| 11 |
description = """
|
| 12 |
|
| 13 |
-
Your low resolution image will be reconstructed to high resolution with a scale of 2 with a convolutional neural network
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
"""
|
| 19 |
|
|
@@ -28,27 +27,27 @@ model.load_state_dict(torch.load('SRCNNmodel_trained.pt',map_location=torch.devi
|
|
| 28 |
model.eval()
|
| 29 |
print("SRCNN model loaded!")
|
| 30 |
|
| 31 |
-
def image_grid(imgs, rows, cols):
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
-
def sepia(
|
| 46 |
# gradio open image as np array
|
| 47 |
-
image = Image.fromarray(
|
| 48 |
out_final,image_bicubic,image = pred_SRCNN(model=model,image=image,device=device)
|
| 49 |
-
grid = image_grid([out_final,image_bicubic],1,2)
|
| 50 |
-
return
|
| 51 |
|
| 52 |
-
demo = gr.Interface(fn = sepia, inputs=gr.Image(
|
| 53 |
|
| 54 |
demo.launch()
|
|
|
|
| 10 |
title = "Super Resolution with CNN"
|
| 11 |
description = """
|
| 12 |
|
| 13 |
+
Your low resolution image will be reconstructed to high resolution with a scale of 2 with a convolutional neural network!<br>
|
| 14 |
+
CNN output on the left, bicubic interpolation output on the right.<br>
|
| 15 |
+
Training and dataset can be found on my [github page](https://github.com/susuhu/super-resolution/blob/main/Super_Resolution.ipynb).<br>
|
|
|
|
| 16 |
|
| 17 |
"""
|
| 18 |
|
|
|
|
| 27 |
model.eval()
|
| 28 |
print("SRCNN model loaded!")
|
| 29 |
|
| 30 |
+
# def image_grid(imgs, rows, cols):
|
| 31 |
+
# '''
|
| 32 |
+
# imgs:list of PILImage
|
| 33 |
+
# '''
|
| 34 |
+
# assert len(imgs) == rows*cols
|
| 35 |
|
| 36 |
+
# w, h = imgs[0].size
|
| 37 |
+
# grid = Image.new('RGB', size=(cols*w, rows*h))
|
| 38 |
+
# grid_w, grid_h = grid.size
|
| 39 |
|
| 40 |
+
# for i, img in enumerate(imgs):
|
| 41 |
+
# grid.paste(img, box=(i%cols*w, i//cols*h))
|
| 42 |
+
# return grid
|
| 43 |
|
| 44 |
+
def sepia(image):
|
| 45 |
# gradio open image as np array
|
| 46 |
+
image = Image.fromarray(image,mode='RGB')
|
| 47 |
out_final,image_bicubic,image = pred_SRCNN(model=model,image=image,device=device)
|
| 48 |
+
# grid = image_grid([out_final,image_bicubic],1,2)
|
| 49 |
+
return out_final,image_bicubic
|
| 50 |
|
| 51 |
+
demo = gr.Interface(fn = sepia, inputs=gr.inputs.Image(label="Upload image"), [gr.outputs.Image(label="Conv net"), gr.outputs.Image(label="Bicubic interpoloation")],title=title,description = description,article = article,examples=[['LR_image.png'],['barbara.png']])
|
| 52 |
|
| 53 |
demo.launch()
|