ChristopherMarais commited on
Commit
6cf6270
·
1 Parent(s): d599160

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -121,12 +121,14 @@ labels = np.append(np.array(bc_model.dls.vocab), "Unknown")
121
  def predict_beetle(img):
122
  # Split image into smaller images of detected objects
123
  image_lst = detect_objects(og_image=img, model=od_model, prompt="bug . insect", device="cpu")
124
- # get predictions for all segments
 
125
  conf_dict_lst = []
126
  output_lst = []
127
  img_cnt = len(image_lst)
128
  for i in range(0,img_cnt):
129
  prob_ar = np.array(bc_model.predict(image_lst[i])[2])
 
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)
@@ -137,6 +139,7 @@ def predict_beetle(img):
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
 
142
 
 
121
  def predict_beetle(img):
122
  # Split image into smaller images of detected objects
123
  image_lst = detect_objects(og_image=img, model=od_model, prompt="bug . insect", device="cpu")
124
+ print("Objects detected")
125
+ # get predictions for all segments
126
  conf_dict_lst = []
127
  output_lst = []
128
  img_cnt = len(image_lst)
129
  for i in range(0,img_cnt):
130
  prob_ar = np.array(bc_model.predict(image_lst[i])[2])
131
+ print(f"Beetle classified - {i}")
132
  unkown_prob = unkown_prob_calc(probs=prob_ar, wedge_threshold=0.85, wedge_magnitude=5, wedge='dynamic')
133
  prob_ar = np.append(prob_ar, unkown_prob)
134
  prob_ar = np.around(prob_ar*100, decimals=1)
 
139
  conf_dict = dict(sorted(conf_dict.items(), key=lambda item: item[1], reverse=True)[:top_num])
140
  conf_dict_lst.append(str(conf_dict)[1:-1]) # remove dictionary brackets
141
  result = list(zip(image_lst, conf_dict_lst))
142
+ print(f"Classification processed - {i}")
143
  return(result)
144
 
145