Julián Tachella commited on
Commit
501b516
·
1 Parent(s): c771378
Files changed (1) hide show
  1. app.py +26 -8
app.py CHANGED
@@ -1,21 +1,39 @@
1
  import gradio as gr
2
- import os
3
  import deepinv as dinv
4
  import torch
 
5
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  def image_mod(image):
 
8
  denoiser = dinv.models.MedianFilter()
9
- image = torch.tensor(image).unsqueeze(0)
10
- image = denoiser(image, 0.1)
11
- image = image.squeeze(0).cpu().detach().numpy()
12
- return image
 
 
 
 
 
 
13
 
14
  demo = gr.Interface(
15
  image_mod,
16
- gr.Image(type="pil"),
17
- "image",
18
- flagging_options=["blurry", "incorrect", "other"],
19
  )
20
 
21
  demo.launch()
 
1
  import gradio as gr
 
2
  import deepinv as dinv
3
  import torch
4
+ import numpy as np
5
 
6
+ def pil_to_torch(image):
7
+ image = np.array(image)
8
+ image = image.transpose((2, 0, 1))
9
+ image = torch.tensor(image)
10
+ return image.unsqueeze(0)
11
+
12
+ def torch_to_pil(image):
13
+ image = image.squeeze(0)
14
+ image = image.numpy()
15
+ image = image.transpose((1, 2, 0))
16
+ return image
17
 
18
  def image_mod(image):
19
+ image = pil_to_torch(image)
20
  denoiser = dinv.models.MedianFilter()
21
+ noisy = image + torch.randn_like(image) * 0.1
22
+ estimated = denoiser(image, 0.1)
23
+ return torch_to_pil(noisy), torch_to_pil(estimated)
24
+
25
+
26
+ input_image = gr.inputs.Image()
27
+ output_images = gr.outputs.Image(label='Denoised Image')
28
+ noise_image = gr.outputs.Image(label='Noisy Image')
29
+ input_image_output = gr.outputs.Image(label='Input Image')
30
+
31
 
32
  demo = gr.Interface(
33
  image_mod,
34
+ inputs=input_image,
35
+ outputs=[noise_image, output_images],
36
+ title="Image Denoising with DeepInverse",
37
  )
38
 
39
  demo.launch()