Spaces:
Runtime error
Runtime error
app.py fixed
Browse files- app/app.py +10 -3
app/app.py
CHANGED
@@ -63,11 +63,18 @@ def predict(image):
|
|
63 |
with torch.no_grad():
|
64 |
output = model(image)
|
65 |
# convert to probabilities
|
66 |
-
probabilities = torch.nn.functional.softmax(
|
|
|
67 |
topk_prob, topk_label = torch.topk(probabilities, 3)
|
68 |
|
69 |
-
#
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
except Exception as e:
|
72 |
print(f"Error predicting image: {e}")
|
73 |
return []
|
|
|
63 |
with torch.no_grad():
|
64 |
output = model(image)
|
65 |
# convert to probabilities
|
66 |
+
probabilities = torch.nn.functional.softmax(output[0])
|
67 |
+
|
68 |
topk_prob, topk_label = torch.topk(probabilities, 3)
|
69 |
|
70 |
+
# convert the predictions to a list
|
71 |
+
predictions = []
|
72 |
+
for i in range(topk_prob.size(0)):
|
73 |
+
prob = topk_prob[i].item()
|
74 |
+
label = topk_label[i].item()
|
75 |
+
predictions.append((prob, label))
|
76 |
+
|
77 |
+
return predictions
|
78 |
except Exception as e:
|
79 |
print(f"Error predicting image: {e}")
|
80 |
return []
|