Spaces:
Sleeping
Sleeping
Upload decisions_users.py
Browse files- utils/decisions_users.py +73 -43
utils/decisions_users.py
CHANGED
@@ -176,48 +176,48 @@ def visualize_bar_plot(df_data):
|
|
176 |
fig = px.bar(df_data, x="probability", y="class", orientation='h')
|
177 |
return fig
|
178 |
|
179 |
-
def run_instance_exp(img_path, img_path_list,prob_list,grad_vis_path_list):
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
|
222 |
|
223 |
|
@@ -254,8 +254,8 @@ def run_instance_exp_keras_model(img_path, new_model, feature_extractor_model):
|
|
254 |
# middle_column.write("Probabilities")
|
255 |
|
256 |
# grad img
|
257 |
-
|
258 |
-
right_column.image(cv2.resize(roi_img, display_image.shape[:2]),caption = "GradCAM ROI")
|
259 |
|
260 |
# seed_id = 900
|
261 |
seed_id = test_id_list.index(org_img_path)
|
@@ -272,6 +272,21 @@ def run_instance_exp_keras_model(img_path, new_model, feature_extractor_model):
|
|
272 |
# st.plotly_chart(plot_n_similar(seed_id,closest_fns, img_path,n=10, scale=4), use_container_width=True)
|
273 |
st.pyplot(plot_n_similar(seed_id,closest_fns_tmp, img_path,n=10,scale=4))
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
def main():
|
276 |
|
277 |
new_model = get_model(MODEL_PATH)
|
@@ -340,9 +355,24 @@ def main():
|
|
340 |
|
341 |
if pressed:
|
342 |
st.empty()
|
343 |
-
st.
|
344 |
run_instance_exp_keras_model(option, new_model,feature_extractor_model)
|
345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
|
347 |
# # new_model = load_model(MODEL_PATH)
|
348 |
# option = st.sidebar.selectbox('Please select a sample image, then click Explain Me button', IMG_PATH_LISTS)
|
|
|
176 |
fig = px.bar(df_data, x="probability", y="class", orientation='h')
|
177 |
return fig
|
178 |
|
179 |
+
# def run_instance_exp(img_path, img_path_list,prob_list,grad_vis_path_list):
|
180 |
+
|
181 |
+
# st.subheader('Instance Exploration')
|
182 |
+
# # st.columns((1,1,1)) with row4_2:
|
183 |
+
# LABELS = ['CNV', 'DRUSEN', 'DME', 'NORMAL']
|
184 |
+
|
185 |
+
# left_column, middle_column, right_column = st.columns((1,1,1))
|
186 |
+
# display_image = load_image(img_path)
|
187 |
+
# # fig = px.imshow(display_image)
|
188 |
+
# # left_column.plotly_chart(fig, use_container_width=True)
|
189 |
+
# left_column.image(cv2.resize(display_image, (180,180)),caption = "Selected Input")
|
190 |
+
|
191 |
+
# # get class probabilities
|
192 |
+
# indx = img_path_list.index(img_path)
|
193 |
+
# print(img_path)
|
194 |
+
# prb_tmp = prob_list[indx]
|
195 |
+
# print(f"{prb_tmp[1:-1]}")
|
196 |
+
# clss_probs = literal_eval('"'+prb_tmp[1:-1]+'"')
|
197 |
+
# print(clss_probs[1:-1].split(' '))
|
198 |
+
# prob_cls = [float(p) for p in clss_probs[1:-1].split(' ')]
|
199 |
+
# tmp_df = pd.DataFrame.from_dict({'class':LABELS,'probability':prob_cls})
|
200 |
+
# print(tmp_df.head())
|
201 |
+
# fig = plt.figure(figsize=(15, 13))
|
202 |
+
# sns.barplot(x='probability', y='class', data=tmp_df)
|
203 |
+
# middle_column.pyplot(fig)
|
204 |
+
# # st.caption('Predictions')
|
205 |
+
|
206 |
+
# tmp_grad_img = GRAD_CAM_IMAGE_DIR + img_path.split("\\")[-2] +'/'+img_path.split("\\") [-1]
|
207 |
|
208 |
+
# display_image = load_image(tmp_grad_img,replace=False)
|
209 |
+
# # left_column.plotly_chart(fig, use_container_width=True)
|
210 |
+
# right_column.image(display_image,caption = "ROI")
|
211 |
|
212 |
+
# # seed_id = 900
|
213 |
+
# seed_id = test_id_list.index(img_path)
|
214 |
+
# query_item = test_features[seed_id]
|
215 |
+
# print(query_item.shape)
|
216 |
+
# closest_idxs = annoy_matching(annoy_tree,query_item, seed_id, 10)
|
217 |
+
# closest_fns = [train_ids[close_i] for close_i in closest_idxs]
|
218 |
+
# st.subheader('Top-10 Similar Samples from Gallery Set')
|
219 |
+
# st.plotly_chart(plot_n_similar(seed_id,closest_fns, img_path,n=10, scale=4), use_container_width=True)
|
220 |
+
# # st.pyplot(plot_n_similar(seed_id,closest_fns, img_path,n=10, scale=4))
|
221 |
|
222 |
|
223 |
|
|
|
254 |
# middle_column.write("Probabilities")
|
255 |
|
256 |
# grad img
|
257 |
+
right_column.image(roi_img, caption = "Decision ROI")
|
258 |
+
# right_column.image(cv2.resize(roi_img, display_image.shape[:2]),caption = "GradCAM ROI")
|
259 |
|
260 |
# seed_id = 900
|
261 |
seed_id = test_id_list.index(org_img_path)
|
|
|
272 |
# st.plotly_chart(plot_n_similar(seed_id,closest_fns, img_path,n=10, scale=4), use_container_width=True)
|
273 |
st.pyplot(plot_n_similar(seed_id,closest_fns_tmp, img_path,n=10,scale=4))
|
274 |
|
275 |
+
with st.expander('Correct Decision'):
|
276 |
+
st.info("Correct th decision if it is not valid. This sample will be added to next training bucket.")
|
277 |
+
tmp_col1, tmp_col2 = st.columns(2)
|
278 |
+
with tmp_col1:
|
279 |
+
label_correect = st.radio(
|
280 |
+
"Choose label visibility π",
|
281 |
+
["CNV", "DME", "NORMAL","DRUSEN"],
|
282 |
+
horizontal=True)
|
283 |
+
with tmp_col2:
|
284 |
+
tmp_btn = st.button('ADD TO TRAINING BUCKET')
|
285 |
+
if tmp_btn:
|
286 |
+
st.warning("Sample added to training set..")
|
287 |
+
|
288 |
+
|
289 |
+
|
290 |
def main():
|
291 |
|
292 |
new_model = get_model(MODEL_PATH)
|
|
|
355 |
|
356 |
if pressed:
|
357 |
st.empty()
|
358 |
+
st.write('Please wait for the magic to happen! This may take up to a minute.')
|
359 |
run_instance_exp_keras_model(option, new_model,feature_extractor_model)
|
360 |
|
361 |
+
# with st.expander('Correct Decision'):
|
362 |
+
# st.info("Correct th decision if it is not valid. This sample will be added to next training bucket.")
|
363 |
+
# tmp_col1, tmp_col2 = st.columns(2)
|
364 |
+
# with tmp_col1:
|
365 |
+
# label_correect = st.radio(
|
366 |
+
# "Choose label visibility π",
|
367 |
+
# ["CNV", "DME", "NORMAL","DRUSEN"],
|
368 |
+
# key="visibility",
|
369 |
+
# horizontal=True)
|
370 |
+
# with tmp_col2:
|
371 |
+
# tmp_btn = st.button('ADD TO TRAINING BUCKET')
|
372 |
+
# if tmp_btn:
|
373 |
+
# st.warning("Sample added to training set..")
|
374 |
+
|
375 |
+
|
376 |
|
377 |
# # new_model = load_model(MODEL_PATH)
|
378 |
# option = st.sidebar.selectbox('Please select a sample image, then click Explain Me button', IMG_PATH_LISTS)
|