Spaces:
Runtime error
Runtime error
joselobenitezg
commited on
Commit
·
c82f96b
1
Parent(s):
f37bf63
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import numpy as np
|
3 |
+
import gradio as gr
|
4 |
+
from model import SegmentationModel
|
5 |
+
|
6 |
+
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
|
7 |
+
|
8 |
+
model = SegmentationModel()
|
9 |
+
model.to(DEVICE)
|
10 |
+
model.load_state_dict(torch.load('./best_model.pt'))
|
11 |
+
|
12 |
+
def inference(input_img):
|
13 |
+
|
14 |
+
image = torch.from_numpy(input_img).permute(2,0,1).float()
|
15 |
+
|
16 |
+
logits_mask = model(image.to(DEVICE).unsqueeze(0)) # (C, H, W) -> (1, C, H, W)
|
17 |
+
pred_mask = torch.sigmoid(logits_mask)
|
18 |
+
|
19 |
+
return pred_mask.squeeze().detach().cpu().numpy()
|
20 |
+
|
21 |
+
demo = gr.Interface(inference, gr.Image(shape=(224, 224)), "image")
|
22 |
+
demo.launch()
|