Spaces:
Running
Running
sunder-ali
commited on
Commit
•
254cb26
1
Parent(s):
a3034b2
Upload 2 files
Browse files- demo_app.py +60 -0
- requirements.txt +6 -0
demo_app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import os.path
|
4 |
+
import torch
|
5 |
+
from PIL import Image
|
6 |
+
from utils import utils_model
|
7 |
+
from utils import utils_image as util
|
8 |
+
import numpy as np
|
9 |
+
import cv2
|
10 |
+
|
11 |
+
st.set_page_config(layout="wide", page_title="Image Denoising Demo")
|
12 |
+
|
13 |
+
st.title("Image Real Denoising Demo")
|
14 |
+
st.write("The model removes the noise from real world images.")
|
15 |
+
st.sidebar.write("## Upload and download :gear:")
|
16 |
+
|
17 |
+
# Create the columns
|
18 |
+
col1, col2 = st.columns(2)
|
19 |
+
|
20 |
+
upfile = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
21 |
+
|
22 |
+
if upfile is not None:
|
23 |
+
img = Image.open(upfile)
|
24 |
+
img.save('test1.png')
|
25 |
+
|
26 |
+
n_channels = 3
|
27 |
+
img_U = util.imread_uint('test1.png', n_channels=n_channels)
|
28 |
+
#img = Image.open(upfile)
|
29 |
+
col1.write("Original Noisy Image")
|
30 |
+
col1.image(upfile)
|
31 |
+
|
32 |
+
|
33 |
+
model_name = 'team15_SAKDNNet'
|
34 |
+
|
35 |
+
model_path = os.path.join('model_zoo', model_name+'.pth')
|
36 |
+
|
37 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
38 |
+
|
39 |
+
from models.team15_SAKDNNet import SAKDNNet as net
|
40 |
+
model = net(in_nc=n_channels,config=[4,4,4,4,4,4,4],dim=64)
|
41 |
+
|
42 |
+
model.load_state_dict(torch.load(model_path), strict=True)
|
43 |
+
model.eval()
|
44 |
+
for k, v in model.named_parameters():
|
45 |
+
v.requires_grad = False
|
46 |
+
|
47 |
+
model = model.to(device)
|
48 |
+
img_N = util.uint2tensor4(img_U)
|
49 |
+
img_N = img_N.to(device)
|
50 |
+
|
51 |
+
img_DN = utils_model.inference(model, img_N, refield=64, min_size=512, mode=2)
|
52 |
+
img_DN = model(img_N)
|
53 |
+
img_DN = util.tensor2uint(img_DN)
|
54 |
+
|
55 |
+
col2.write("Denoised Image")
|
56 |
+
col2.image(img_DN)
|
57 |
+
|
58 |
+
#st.sidebar.markdown("\\n")
|
59 |
+
|
60 |
+
st.write("The method is included in NTIRE 2023 Image Denoising Challenge at CVPR 2023")
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
numpy
|
3 |
+
opencv-contrib-python
|
4 |
+
torchvision
|
5 |
+
einops
|
6 |
+
timm
|