Nicolas Burrus commited on
Commit
75bdb59
1 Parent(s): 94e846b

Start building an example.

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. app.py +39 -0
  3. examples/Bowling.png +3 -0
  4. examples/opencv.png +3 -0
  5. requirements.txt +4 -0
.gitattributes CHANGED
@@ -25,3 +25,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
28
+ *.png filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ import gradio as gr
4
+
5
+ import torch
6
+ from torch import Tensor
7
+ from torchvision import transforms
8
+
9
+ import numpy as np
10
+
11
+ import sys
12
+
13
+ model = None
14
+
15
+ def load_model():
16
+ global model
17
+ model = torch.jit.load("model.pt")
18
+
19
+ def denormalize_and_clip_as_tensor (im: Tensor) -> Tensor:
20
+ return torch.clip(im * 0.5 + 0.5, 0.0, 1.0)
21
+
22
+ def denormalize_and_clip_as_numpy (im: Tensor) -> np.ndarray:
23
+ im = im.squeeze(0)
24
+ return np.ascontiguousarray(denormalize_and_clip_as_tensor(im).permute(1,2,0).detach().cpu().numpy())
25
+
26
+ def undo_antialiasing(im):
27
+ im_torch = torch.from_numpy (im).permute(2,0,1).unsqueeze(0).float() / 255.0
28
+ im_torch = transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))(im_torch)
29
+ with torch.no_grad():
30
+ output_torch = model(im_torch)
31
+ output = denormalize_and_clip_as_numpy(output_torch.rgb)
32
+ return (output*255.99).astype(np.uint8)
33
+
34
+ load_model()
35
+ iface = gr.Interface(fn=undo_antialiasing,
36
+ inputs=gr.inputs.Image(),
37
+ outputs=gr.outputs.Image(),
38
+ examples=[['examples/Bowling.png'], ['examples/opencv.png']])
39
+ iface.launch()
examples/Bowling.png ADDED

Git LFS Details

  • SHA256: 60a1b7e7364e343df489c1c4196669899a2e2549cc59e9f1b981483ceb027707
  • Pointer size: 131 Bytes
  • Size of remote file: 246 kB
examples/opencv.png ADDED

Git LFS Details

  • SHA256: 85cf51ab2185e8084f2335f329c7b5f6ea82c5f153257c72044c77ca32744098
  • Pointer size: 130 Bytes
  • Size of remote file: 52.4 kB
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ torch
3
+ torchvision
4
+ torchaudio