Spaces:
Running
Running
Hu
commited on
Commit
·
64c514e
1
Parent(s):
c373d06
formatting
Browse files
app.py
CHANGED
@@ -26,10 +26,12 @@ article = """
|
|
26 |
|
27 |
# load model
|
28 |
print("Loading SRCNN model...")
|
29 |
-
device = torch.device(
|
30 |
|
31 |
model = SRCNNModel().to(device)
|
32 |
-
model.load_state_dict(
|
|
|
|
|
33 |
model.eval()
|
34 |
print("SRCNN model loaded!")
|
35 |
|
@@ -42,18 +44,37 @@ print("SRCNN model loaded!")
|
|
42 |
# w, h = imgs[0].size
|
43 |
# grid = Image.new('RGB', size=(cols*w, rows*h))
|
44 |
# grid_w, grid_h = grid.size
|
45 |
-
|
46 |
# for i, img in enumerate(imgs):
|
47 |
# grid.paste(img, box=(i%cols*w, i//cols*h))
|
48 |
# return grid
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
def sepia(image):
|
51 |
# gradio open image as np array
|
52 |
-
image = Image.fromarray(image,mode=
|
53 |
-
out_final,image_bicubic,image = pred_SRCNN(
|
|
|
|
|
54 |
# grid = image_grid([out_final,image_bicubic],1,2)
|
55 |
-
return out_final,image_bicubic
|
|
|
56 |
|
57 |
-
demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
demo.launch()
|
|
|
26 |
|
27 |
# load model
|
28 |
print("Loading SRCNN model...")
|
29 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
30 |
|
31 |
model = SRCNNModel().to(device)
|
32 |
+
model.load_state_dict(
|
33 |
+
torch.load("SRCNNmodel_trained.pt", map_location=torch.device(device))
|
34 |
+
)
|
35 |
model.eval()
|
36 |
print("SRCNN model loaded!")
|
37 |
|
|
|
44 |
# w, h = imgs[0].size
|
45 |
# grid = Image.new('RGB', size=(cols*w, rows*h))
|
46 |
# grid_w, grid_h = grid.size
|
47 |
+
|
48 |
# for i, img in enumerate(imgs):
|
49 |
# grid.paste(img, box=(i%cols*w, i//cols*h))
|
50 |
# return grid
|
51 |
+
examples = [
|
52 |
+
["LR_image.png"],
|
53 |
+
["barbara.png"],
|
54 |
+
]
|
55 |
+
|
56 |
|
57 |
def sepia(image):
|
58 |
# gradio open image as np array
|
59 |
+
image = Image.fromarray(image, mode="RGB")
|
60 |
+
out_final, image_bicubic, image = pred_SRCNN(
|
61 |
+
model=model, image=image, device=device
|
62 |
+
)
|
63 |
# grid = image_grid([out_final,image_bicubic],1,2)
|
64 |
+
return out_final, image_bicubic
|
65 |
+
|
66 |
|
67 |
+
demo = gr.Interface(
|
68 |
+
fn=sepia,
|
69 |
+
inputs=gr.inputs.Image(label="Upload image"),
|
70 |
+
outputs=[
|
71 |
+
gr.outputs.Image(label="Convolutional neural network"),
|
72 |
+
gr.outputs.Image(label="Bicubic interpoloation"),
|
73 |
+
],
|
74 |
+
title=title,
|
75 |
+
description=description,
|
76 |
+
article=article,
|
77 |
+
examples=examples,
|
78 |
+
)
|
79 |
|
80 |
+
demo.launch()
|