-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_app.py
61 lines (46 loc) · 1.62 KB
/
image_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import gradio as gr
import torch
from torch.autograd import Variable
from utils import *
from networks import *
import cv2
#from torchvision import transforms
import os
model = PRN_r(6, 1)
model = model.cuda()
model.load_state_dict(torch.load('./net_latest.pth'))
iscuda = torch.cuda.is_available()
data_path = './datasets/Rain100H/'
file_list = [data_path+file_name for file_name in os.listdir(data_path)]
def deNosing(noise_img):
y = np.array(noise_img)
y = cv2.resize(y, (int(500), int(500)), interpolation=cv2.INTER_CUBIC)
y = normalize(np.float32(y))
y = np.expand_dims(y.transpose(2, 0, 1), 0)
y = Variable(torch.Tensor(y))
if iscuda:
y = y.cuda()
with torch.no_grad():
if iscuda:
torch.cuda.synchronize()
out, _ = model(y)
out = torch.clamp(out, 0., 1.)
if iscuda:
torch.cuda.synchronize()
if iscuda:
save_out = np.uint8(255 * out.data.cpu().numpy().squeeze())
else:
save_out = np.uint8(255 * out.data.numpy().squeeze())
save_out = save_out.transpose(1, 2, 0)
save_out = cv2.resize(save_out,(noise_img.width,noise_img.height),interpolation=cv2.INTER_CUBIC)
return save_out
demo = gr.Interface(fn=deNosing,
inputs=gr.components.Image(type='pil'),
outputs=gr.components.Image(type='pil'),
examples=file_list,
#allow_flagging='never',
#allow_duplication=True,
examples_per_page = 30,
title = 'Hello, My App with AI',
)
demo.launch(debug=True, share=False)