ChristopherMarais commited on
Commit
03f0f35
·
1 Parent(s): a20c383

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -23
app.py CHANGED
@@ -126,29 +126,29 @@ def predict_beetle(img):
126
  print("Detecting & classifying beetles...")
127
  # Split image into smaller images of detected objects
128
  # image_lst = detect_objects(og_image=img, model=od_model, prompt="bug . insect", device="cpu")
129
- # pre_process = pre_process_image(manual_thresh_buffer=0.15, image = img) # use image_dir if directory of image used
130
- # pre_process.segment(cluster_num=2,
131
- # image_edge_buffer=50)
132
- # image_lst = pre_process.col_image_lst
133
- # print("Objects detected")
134
- # # get predictions for all segments
135
- # conf_dict_lst = []
136
- # output_lst = []
137
- # img_cnt = len(image_lst)
138
- # for i in range(0,img_cnt):
139
- # prob_ar = np.array(bc_model.predict(image_lst[i])[2])
140
- # print(f"Beetle classified - {i}")
141
- # unkown_prob = unkown_prob_calc(probs=prob_ar, wedge_threshold=0.85, wedge_magnitude=5, wedge='dynamic')
142
- # prob_ar = np.append(prob_ar, unkown_prob)
143
- # prob_ar = np.around(prob_ar*100, decimals=1)
144
- # # only show the top 5 predictions
145
- # # Sorting the dictionary by value in descending order and taking the top items
146
- # top_num = 3
147
- # conf_dict = {labels[i]: float(prob_ar[i]) for i in range(len(prob_ar))}
148
- # conf_dict = dict(sorted(conf_dict.items(), key=lambda item: item[1], reverse=True)[:top_num])
149
- # conf_dict_lst.append(str(conf_dict)[1:-1]) # remove dictionary brackets
150
- # result = list(zip(image_lst, conf_dict_lst))
151
- # print(f"Classification processed - {i}")
152
  result = list(zip([img], ["labelzzzzz"]))
153
  return(result)
154
 
 
126
  print("Detecting & classifying beetles...")
127
  # Split image into smaller images of detected objects
128
  # image_lst = detect_objects(og_image=img, model=od_model, prompt="bug . insect", device="cpu")
129
+ pre_process = pre_process_image(manual_thresh_buffer=0.15, image = img) # use image_dir if directory of image used
130
+ pre_process.segment(cluster_num=2,
131
+ image_edge_buffer=50)
132
+ image_lst = pre_process.col_image_lst
133
+ print("Objects detected")
134
+ # get predictions for all segments
135
+ conf_dict_lst = []
136
+ output_lst = []
137
+ img_cnt = len(image_lst)
138
+ for i in range(0,img_cnt):
139
+ prob_ar = np.array(bc_model.predict(image_lst[i])[2])
140
+ print(f"Beetle classified - {i}")
141
+ unkown_prob = unkown_prob_calc(probs=prob_ar, wedge_threshold=0.85, wedge_magnitude=5, wedge='dynamic')
142
+ prob_ar = np.append(prob_ar, unkown_prob)
143
+ prob_ar = np.around(prob_ar*100, decimals=1)
144
+ # only show the top 5 predictions
145
+ # Sorting the dictionary by value in descending order and taking the top items
146
+ top_num = 3
147
+ conf_dict = {labels[i]: float(prob_ar[i]) for i in range(len(prob_ar))}
148
+ conf_dict = dict(sorted(conf_dict.items(), key=lambda item: item[1], reverse=True)[:top_num])
149
+ conf_dict_lst.append(str(conf_dict)[1:-1]) # remove dictionary brackets
150
+ result = list(zip(image_lst, conf_dict_lst))
151
+ print(f"Classification processed - {i}")
152
  result = list(zip([img], ["labelzzzzz"]))
153
  return(result)
154