Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,13 @@ import torch
|
|
3 |
import gradio as gr
|
4 |
from torchvision.transforms import Compose, Normalize, ToTensor, Resize, CenterCrop
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
inference = torch.load('fine_tune_resnet.pth', map_location=torch.device('cpu'))
|
8 |
inference.eval()
|
9 |
|
@@ -14,18 +20,17 @@ def classifier(image):
|
|
14 |
ToTensor(),
|
15 |
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
16 |
])
|
17 |
-
|
18 |
-
if torch.cuda.is_available():
|
19 |
-
inference.cpu()
|
20 |
|
21 |
with torch.no_grad():
|
22 |
-
output = inference(test_transform(
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
25 |
|
26 |
-
return f'{label_dict[prediction.item()]} (Confidence: {confidence}%)'
|
27 |
|
28 |
-
iface = gr.Interface(
|
29 |
inputs=gr.Image(type="pil"),
|
30 |
-
outputs='
|
31 |
iface.launch(share=True)
|
|
|
3 |
import gradio as gr
|
4 |
from torchvision.transforms import Compose, Normalize, ToTensor, Resize, CenterCrop
|
5 |
|
6 |
+
labels = {0: 'glass',
|
7 |
+
1: 'metal',
|
8 |
+
2: 'organic-waste',
|
9 |
+
3: 'organice-waste',
|
10 |
+
4: 'paper',
|
11 |
+
5: 'plastic',
|
12 |
+
6: 'textiles'}
|
13 |
inference = torch.load('fine_tune_resnet.pth', map_location=torch.device('cpu'))
|
14 |
inference.eval()
|
15 |
|
|
|
20 |
ToTensor(),
|
21 |
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
22 |
])
|
|
|
|
|
|
|
23 |
|
24 |
with torch.no_grad():
|
25 |
+
output = inference(test_transform(image).unsqueeze(0))
|
26 |
+
out = torch.softmax(output,1)
|
27 |
+
|
28 |
+
values,indices = torch.topk(out[0],k=7)
|
29 |
+
|
30 |
+
return {labels[i.item()]: v.item() for i, v in zip(indices,values)}
|
31 |
|
|
|
32 |
|
33 |
+
iface = gr.Interface(fn=classifier,
|
34 |
inputs=gr.Image(type="pil"),
|
35 |
+
outputs='label')
|
36 |
iface.launch(share=True)
|