pytholic commited on
Commit
d2c0b63
·
1 Parent(s): 4084d4a

app.py fixed

Browse files
Files changed (1) hide show
  1. 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(torch.exp(output[0]), dim=0)
 
67
  topk_prob, topk_label = torch.topk(probabilities, 3)
68
 
69
- # Return the top 3 predictions
70
- return {labels[i]: float(probabilities[i]) for i in range(3)}
 
 
 
 
 
 
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 []