Spaces:
Sleeping
Sleeping
Harshithtd
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -31,11 +31,11 @@ def predict_image(image):
|
|
31 |
with torch.no_grad():
|
32 |
outputs = model(processed_image)
|
33 |
probabilities = torch.nn.functional.softmax(outputs, dim=1)
|
34 |
-
top_probs, top_indices = torch.topk(probabilities,
|
35 |
top_classes = [class_names[idx] for idx in top_indices[0]]
|
36 |
|
37 |
# Create a result dictionary with class names and probabilities
|
38 |
-
result = {top_classes[i]: top_probs[0][i].item() for i in range(
|
39 |
|
40 |
return result
|
41 |
|
|
|
31 |
with torch.no_grad():
|
32 |
outputs = model(processed_image)
|
33 |
probabilities = torch.nn.functional.softmax(outputs, dim=1)
|
34 |
+
top_probs, top_indices = torch.topk(probabilities, 2)
|
35 |
top_classes = [class_names[idx] for idx in top_indices[0]]
|
36 |
|
37 |
# Create a result dictionary with class names and probabilities
|
38 |
+
result = {top_classes[i]: top_probs[0][i].item() for i in range(2)}
|
39 |
|
40 |
return result
|
41 |
|