ChristopherMarais commited on
Commit
7a02a8c
·
1 Parent(s): 9567ac8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -130,10 +130,12 @@ def predict_beetle(img):
130
  unkown_prob = unkown_prob_calc(probs=prob_ar, wedge_threshold=0.85, wedge_magnitude=5, wedge='dynamic')
131
  prob_ar = np.append(prob_ar, unkown_prob)
132
  prob_ar = np.around(prob_ar*100, decimals=1)
133
-
 
 
134
  conf_dict = {labels[i]: float(prob_ar[i]) for i in range(len(prob_ar))}
135
- conf_dict = dict(sorted(conf_dict.items(), key=lambda item: item[1], reverse=True))
136
- conf_dict_lst.append(str(conf_dict))
137
  result = list(zip(image_lst, conf_dict_lst))
138
  return(result)
139
 
 
130
  unkown_prob = unkown_prob_calc(probs=prob_ar, wedge_threshold=0.85, wedge_magnitude=5, wedge='dynamic')
131
  prob_ar = np.append(prob_ar, unkown_prob)
132
  prob_ar = np.around(prob_ar*100, decimals=1)
133
+ # only show the top 5 predictions
134
+ # Sorting the dictionary by value in descending order and taking the top items
135
+ top_num = 3
136
  conf_dict = {labels[i]: float(prob_ar[i]) for i in range(len(prob_ar))}
137
+ conf_dict = dict(sorted(conf_dict.items(), key=lambda item: item[1], reverse=True)[:top_num])
138
+ conf_dict_lst.append(str(conf_dict)[1:-1]) # remove dictionary brackets
139
  result = list(zip(image_lst, conf_dict_lst))
140
  return(result)
141