Julián Tachella commited on
Commit
ece0ce5
·
1 Parent(s): 29c29f7
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -10,7 +10,14 @@ def pil_to_torch(image):
10
  image = image.transpose((2, 0, 1))
11
  image = torch.tensor(image).float() / 255
12
  image = image.unsqueeze(0)
13
- image = torch.nn.functional.interpolate(image, size=(128, 128*image.shape[3]//image.shape[2]))
 
 
 
 
 
 
 
14
  return image
15
 
16
 
@@ -27,7 +34,7 @@ def image_mod(image, noise_level, denoiser):
27
  if denoiser == 'DnCNN':
28
  denoiser = dinv.models.DnCNN()
29
  elif denoiser == 'MedianFilter':
30
- denoiser = dinv.models.MedianFilter()
31
  elif denoiser == 'BM3D':
32
  denoiser = dinv.models.BM3D()
33
  elif denoiser == 'TV':
@@ -58,7 +65,7 @@ demo = gr.Interface(
58
  examples=[['https://deepinv.github.io/deepinv/_static/deepinv_logolarge.png', 0.1, 'DnCNN']],
59
  outputs=[noise_image, output_images],
60
  title="Image Denoising with DeepInverse",
61
- description="Denoise an image using a variety of denoisers and noise levels using the deepinverse library (https://deepinv.github.io/). We only include lightweight models like DnCNN and MedianFilter as this example is intended to be run on a CPU. We also automatically resize the input image to 128 vertical pixels to reduce the computation time. For more advanced models, please run the code locally.",
62
  )
63
 
64
  demo.launch()
 
10
  image = image.transpose((2, 0, 1))
11
  image = torch.tensor(image).float() / 255
12
  image = image.unsqueeze(0)
13
+
14
+ ref_size = 256
15
+ if image.shape[2] > image.shape[3]:
16
+ size = (ref_size, ref_size * image.shape[2]//image.shape[3])
17
+ else:
18
+ size = (ref_size * image.shape[3]//image.shape[2], ref_size)
19
+
20
+ image = torch.nn.functional.interpolate(image, size=size, mode='bilinear')
21
  return image
22
 
23
 
 
34
  if denoiser == 'DnCNN':
35
  denoiser = dinv.models.DnCNN()
36
  elif denoiser == 'MedianFilter':
37
+ denoiser = dinv.models.MedianFilter(kernel_size=5)
38
  elif denoiser == 'BM3D':
39
  denoiser = dinv.models.BM3D()
40
  elif denoiser == 'TV':
 
65
  examples=[['https://deepinv.github.io/deepinv/_static/deepinv_logolarge.png', 0.1, 'DnCNN']],
66
  outputs=[noise_image, output_images],
67
  title="Image Denoising with DeepInverse",
68
+ description="Denoise an image using a variety of denoisers and noise levels using the deepinverse library (https://deepinv.github.io/). We only include lightweight models like DnCNN and MedianFilter as this example is intended to be run on a CPU. We also automatically resize the input image to 256 vertical pixels to reduce the computation time. For more advanced models, please run the code locally.",
69
  )
70
 
71
  demo.launch()