Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -20,3 +20,37 @@ model.load_state_dict(checkpoints['model_state_dict'])
|
|
20 |
|
21 |
model = model.to(device)
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
model = model.to(device)
|
22 |
|
23 |
+
def load_img (filename):
|
24 |
+
img = Image.open(filename).convert("RGB")
|
25 |
+
img_tensor = pil_to_tensor(img)
|
26 |
+
return img_tensor
|
27 |
+
|
28 |
+
def process_img(image):
|
29 |
+
img = np.array(image)
|
30 |
+
img = img / 255.
|
31 |
+
img = img.astype(np.float32)
|
32 |
+
y = torch.tensor(img).permute(2,0,1).unsqueeze(0).to(device)
|
33 |
+
|
34 |
+
with torch.no_grad():
|
35 |
+
result = model(y)
|
36 |
+
|
37 |
+
|
38 |
+
restored_img = result.squeeze().permute(1,2,0).clamp_(0, 1).cpu().detach().numpy()
|
39 |
+
restored_img = np.clip(restored_img, 0. , 1.)
|
40 |
+
|
41 |
+
restored_img = (restored_img * 255.0).round().astype(np.uint8) # float32 to uint8
|
42 |
+
return Image.fromarray(restored_img)
|
43 |
+
|
44 |
+
title = "Efficient Hazy Vehicle Detection 鉁忥笍[] 馃"
|
45 |
+
description = ''' ## [Efficient Hazy Vehicle Detection](https://github.com/cidautai)
|
46 |
+
[Paula Garrido Mellado](https://github.com/paugar5)
|
47 |
+
Fundaci贸n Cidaut
|
48 |
+
> **Disclaimer:** please remember this is not a product, thus, you will notice some limitations.
|
49 |
+
**This demo expects an image with some degradations.**
|
50 |
+
Due to the GPU memory limitations, the app might crash if you feed a high-resolution image (2K, 4K).
|
51 |
+
<br>
|
52 |
+
'''
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|