Spaces:
Runtime error
Runtime error
Nicolas Burrus
commited on
Commit
•
75bdb59
1
Parent(s):
94e846b
Start building an example.
Browse files- .gitattributes +1 -0
- app.py +39 -0
- examples/Bowling.png +3 -0
- examples/opencv.png +3 -0
- 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
|
examples/opencv.png
ADDED
Git LFS Details
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
torchvision
|
4 |
+
torchaudio
|