Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,13 @@ inference = torch.load('fine_tune_resnet.pth')
|
|
8 |
inference.eval()
|
9 |
|
10 |
def classifier(image):
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
|
15 |
return f'{label_dict[prediction.item()]} (Confidence: {confidence}%)'
|
16 |
|
|
|
8 |
inference.eval()
|
9 |
|
10 |
def classifier(image):
|
11 |
+
if torch.cuda.is_available():
|
12 |
+
inference.cpu()
|
13 |
+
|
14 |
+
with torch.no_grad():
|
15 |
+
output = inference(test_transform(Image.open('/content/1000-ml-plastic-water-bottle-500x500.webp')).unsqueeze(0))
|
16 |
+
_, prediction = torch.max(output,1)
|
17 |
+
confidence = round(torch.softmax(output,1).max().item(),4)*100
|
18 |
|
19 |
return f'{label_dict[prediction.item()]} (Confidence: {confidence}%)'
|
20 |
|