Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- utils/data_users.py +19 -28
- utils/decisions_users.py +51 -9
- utils/eval_users.py +16 -7
utils/data_users.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import os
|
|
|
3 |
|
4 |
ROOT_FIG_DIR = f'{os.getcwd()}/figures/'
|
5 |
def get_product_dev_page_layout():
|
@@ -68,25 +70,22 @@ def get_product_dev_page_layout():
|
|
68 |
with row4_2:
|
69 |
st.subheader('Exploratory Data Stats')
|
70 |
with st.expander('Training Data Info'):
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
st.caption('Number of Images per Category')
|
75 |
-
st.image(f'{ROOT_FIG_DIR}/train_raw_category_dist.png')
|
76 |
-
with col2:
|
77 |
-
st.caption('Aspect ratio')
|
78 |
-
st.image(f'{ROOT_FIG_DIR}/train_raw_aspectratio_dist.png')
|
79 |
-
st.caption('Image Samples')
|
80 |
-
st.image(f'{ROOT_FIG_DIR}/train_samples.png')
|
81 |
|
82 |
with st.expander('Test Data Info'):
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
st.
|
89 |
-
|
|
|
|
|
|
|
|
|
90 |
|
91 |
with row4_3:
|
92 |
# st.write("**Post Processesd Data Details**")
|
@@ -107,17 +106,9 @@ def get_product_dev_page_layout():
|
|
107 |
st.code(code, language='python')
|
108 |
|
109 |
with st.expander('Training Data Info after Representative Sampling'):
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
with col1:
|
114 |
-
st.caption('Number of Images per Category')
|
115 |
-
st.image(f'{ROOT_FIG_DIR}/train_filter_category_dist.png')
|
116 |
-
with col2:
|
117 |
-
st.caption('Aspect ratio')
|
118 |
-
st.image(f'{ROOT_FIG_DIR}/train_filter_aspectratio_dist.png')
|
119 |
-
st.caption('Image Samples')
|
120 |
-
st.image(f'{ROOT_FIG_DIR}/train_samples.png')
|
121 |
st.write("Model Input Size Resizing: 180x180x3")
|
122 |
# st.caption('Post Processing Steps:')
|
123 |
# code = '''def representative_sampling():
|
|
|
1 |
import streamlit as st
|
2 |
+
import streamlit.components.v1 as components
|
3 |
import os
|
4 |
+
# import cv2
|
5 |
|
6 |
ROOT_FIG_DIR = f'{os.getcwd()}/figures/'
|
7 |
def get_product_dev_page_layout():
|
|
|
70 |
with row4_2:
|
71 |
st.subheader('Exploratory Data Stats')
|
72 |
with st.expander('Training Data Info'):
|
73 |
+
HtmlFile = open(f'{ROOT_FIG_DIR}/train_set_report.html', 'r', encoding='utf-8')
|
74 |
+
source_code = HtmlFile.read()
|
75 |
+
components.html(source_code,scrolling=True, height=500)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
with st.expander('Test Data Info'):
|
78 |
+
HtmlFile = open(f'{ROOT_FIG_DIR}/test_set_report.html', 'r', encoding='utf-8')
|
79 |
+
source_code = HtmlFile.read()
|
80 |
+
components.html(source_code,scrolling=True, height=500)
|
81 |
+
|
82 |
+
with st.expander('Sample Visualization for each Category'):
|
83 |
+
clss = st.selectbox('Select a category(class)', ["CNV","DME", "NORMAL", "DRUSEN"])
|
84 |
+
img_path = f'{ROOT_FIG_DIR}/{clss}_samples.png'
|
85 |
+
st.image(img_path)
|
86 |
+
# HtmlFile = open(f'{ROOT_FIG_DIR}/test_set_report.html', 'r', encoding='utf-8')
|
87 |
+
# source_code = HtmlFile.read()
|
88 |
+
# components.html(source_code,scrolling=True, height=500)
|
89 |
|
90 |
with row4_3:
|
91 |
# st.write("**Post Processesd Data Details**")
|
|
|
106 |
st.code(code, language='python')
|
107 |
|
108 |
with st.expander('Training Data Info after Representative Sampling'):
|
109 |
+
HtmlFile = open(f'{ROOT_FIG_DIR}/filtered_set_report.html', 'r', encoding='utf-8')
|
110 |
+
source_code = HtmlFile.read()
|
111 |
+
components.html(source_code,scrolling=True, height=500)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
st.write("Model Input Size Resizing: 180x180x3")
|
113 |
# st.caption('Post Processing Steps:')
|
114 |
# code = '''def representative_sampling():
|
utils/decisions_users.py
CHANGED
@@ -86,11 +86,47 @@ def annoy_matching(annoy_f,query_item, query_index, n=10):
|
|
86 |
def get_img(fn ,thumbnail=False):
|
87 |
img = Image.open(fn)
|
88 |
if thumbnail:
|
89 |
-
img.thumbnail((
|
90 |
return img
|
91 |
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
def plot_n_similar(seed_id,similar_ids, test_path,n=10, scale=5):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
f,ax = plt.subplots(1,n+1,figsize=((n+1)*scale,scale))
|
95 |
# print(os.path.basename(test_labels[seed_id])[:-4])
|
96 |
title = "SEED ID:{0}\nLabel:{1}".format(seed_id,os.path.basename(test_labels[seed_id]))
|
@@ -98,17 +134,19 @@ def plot_n_similar(seed_id,similar_ids, test_path,n=10, scale=5):
|
|
98 |
ax[0].imshow(get_img(test_path.replace("F:/","E:/")),cmap='gray')
|
99 |
ax[0].set_title(title,fontsize=12)
|
100 |
for i in range(len(similar_ids)):
|
|
|
101 |
ax[i+1].imshow(get_img(similar_ids[i].replace("F:/","E:/")),cmap='gray')
|
102 |
title = "ID:{0}\nDistance: {1:.3f}\nLabel:{2}".format(i,0.1223,os.path.basename(similar_ids[i])[:-4])
|
103 |
ax[i+1].set_title(title,fontsize=10)
|
104 |
f.suptitle("Images similar to seed_id {0}".format(seed_id),fontsize=18)
|
105 |
-
plt.subplots_adjust(top=0.
|
|
|
106 |
return f
|
107 |
|
108 |
def load_image(filename,change_url=True):
|
109 |
# if change_url:
|
110 |
-
print(filename)
|
111 |
-
print(os.path.exists(filename))
|
112 |
img = cv2.imread(filename)
|
113 |
return img
|
114 |
|
@@ -178,7 +216,8 @@ def run_instance_exp(img_path, img_path_list,prob_list,grad_vis_path_list):
|
|
178 |
closest_idxs = annoy_matching(annoy_tree,query_item, seed_id, 10)
|
179 |
closest_fns = [train_ids[close_i] for close_i in closest_idxs]
|
180 |
st.subheader('Top-10 Similar Samples from Gallery Set')
|
181 |
-
st.
|
|
|
182 |
|
183 |
|
184 |
|
@@ -197,7 +236,8 @@ def run_instance_exp_keras_model(img_path, new_model, feature_extractor_model):
|
|
197 |
display_image = load_image(img_path)
|
198 |
# fig = px.imshow(display_image)
|
199 |
# left_column.plotly_chart(fig, use_container_width=True)
|
200 |
-
left_column.image(
|
|
|
201 |
|
202 |
|
203 |
roi_img, probs = get_predictions_and_roi(img_path, new_model)
|
@@ -208,13 +248,14 @@ def run_instance_exp_keras_model(img_path, new_model, feature_extractor_model):
|
|
208 |
prob_cls =np.asarray(probs)[0]
|
209 |
# print(prob_cls)
|
210 |
tmp_df = pd.DataFrame.from_dict({'class':LABELS,'probability':prob_cls})
|
211 |
-
fig = plt.figure(figsize=(
|
212 |
sns.barplot(x='probability', y='class', data=tmp_df)
|
213 |
middle_column.pyplot(fig)
|
214 |
# middle_column.write("Probabilities")
|
215 |
|
216 |
# grad img
|
217 |
-
right_column.image(roi_img, caption = "Decision ROI")
|
|
|
218 |
|
219 |
# seed_id = 900
|
220 |
seed_id = test_id_list.index(org_img_path)
|
@@ -228,7 +269,8 @@ def run_instance_exp_keras_model(img_path, new_model, feature_extractor_model):
|
|
228 |
for each_fn in closest_fns]
|
229 |
# print(closest_fns)
|
230 |
st.subheader('Top-10 Similar Samples from Gallery Set')
|
231 |
-
st.
|
|
|
232 |
|
233 |
def main():
|
234 |
|
|
|
86 |
def get_img(fn ,thumbnail=False):
|
87 |
img = Image.open(fn)
|
88 |
if thumbnail:
|
89 |
+
img.thumbnail((150,150))
|
90 |
return img
|
91 |
|
92 |
+
def open_gray(fn):
|
93 |
+
img = cv2.cvtColor(cv2.imread(fn), cv2.COLOR_BGR2GRAY)
|
94 |
+
img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
|
95 |
+
img = cv2.resize(img,(224,224))
|
96 |
+
return img
|
97 |
|
98 |
def plot_n_similar(seed_id,similar_ids, test_path,n=10, scale=5):
|
99 |
+
# img_list = []
|
100 |
+
# title_list = ["SEED ID:{0} <br> Label:{1}".format(seed_id,os.path.basename(test_labels[seed_id]))]
|
101 |
+
# # for indx,row in cnv_cls_df.iterrows():
|
102 |
+
# img_list.append(open_gray(test_path.replace("F:/","E:/")))
|
103 |
+
# for i in range(len(similar_ids)):
|
104 |
+
# print("PATH:",similar_ids[i].replace("F:/","E:/"))
|
105 |
+
# img_list.append(open_gray(similar_ids[i].replace("F:/","E:/")))
|
106 |
+
# # ax[i+1].imshow(get_img(similar_ids[i].replace("F:/","E:/")),cmap='gray')
|
107 |
+
# title = "ID:{0} <br> Distance: {1:.3f} <br> Label:{2}".format(i,0.1223,os.path.basename(similar_ids[i])[:-4])
|
108 |
+
# title_list.append(title)
|
109 |
+
|
110 |
+
|
111 |
+
# fig = px.imshow(np.array(img_list), facet_col=0, binary_string=True,facet_row_spacing=0.002,facet_col_spacing=0.002)
|
112 |
+
# # Set facet titles
|
113 |
+
# for i, sigma in enumerate(title_list):
|
114 |
+
# fig.layout.annotations[i]['text'] = sigma
|
115 |
+
# fig.layout.annotations[i]['yshift'] = -40
|
116 |
+
# # fig.layout.tex
|
117 |
+
# fig.update_layout(
|
118 |
+
# margin=dict(
|
119 |
+
# l=10,
|
120 |
+
# r=10,
|
121 |
+
# b=10,
|
122 |
+
# t=40,
|
123 |
+
# pad=1
|
124 |
+
# ),
|
125 |
+
# )
|
126 |
+
# fig.update_xaxes(showticklabels=False)
|
127 |
+
# fig.update_yaxes(showticklabels=False)
|
128 |
+
# fig.show()
|
129 |
+
|
130 |
f,ax = plt.subplots(1,n+1,figsize=((n+1)*scale,scale))
|
131 |
# print(os.path.basename(test_labels[seed_id])[:-4])
|
132 |
title = "SEED ID:{0}\nLabel:{1}".format(seed_id,os.path.basename(test_labels[seed_id]))
|
|
|
134 |
ax[0].imshow(get_img(test_path.replace("F:/","E:/")),cmap='gray')
|
135 |
ax[0].set_title(title,fontsize=12)
|
136 |
for i in range(len(similar_ids)):
|
137 |
+
# print("PATH:", similar_ids[i])
|
138 |
ax[i+1].imshow(get_img(similar_ids[i].replace("F:/","E:/")),cmap='gray')
|
139 |
title = "ID:{0}\nDistance: {1:.3f}\nLabel:{2}".format(i,0.1223,os.path.basename(similar_ids[i])[:-4])
|
140 |
ax[i+1].set_title(title,fontsize=10)
|
141 |
f.suptitle("Images similar to seed_id {0}".format(seed_id),fontsize=18)
|
142 |
+
plt.subplots_adjust(top=0.4)
|
143 |
+
plt.tight_layout()
|
144 |
return f
|
145 |
|
146 |
def load_image(filename,change_url=True):
|
147 |
# if change_url:
|
148 |
+
# print(filename)
|
149 |
+
# print(os.path.exists(filename))
|
150 |
img = cv2.imread(filename)
|
151 |
return img
|
152 |
|
|
|
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 |
|
|
|
236 |
display_image = load_image(img_path)
|
237 |
# fig = px.imshow(display_image)
|
238 |
# left_column.plotly_chart(fig, use_container_width=True)
|
239 |
+
left_column.image(display_image,caption = "Selected Input")
|
240 |
+
# left_column.image(cv2.resize(display_image, (180,180)),caption = "Selected Input")
|
241 |
|
242 |
|
243 |
roi_img, probs = get_predictions_and_roi(img_path, new_model)
|
|
|
248 |
prob_cls =np.asarray(probs)[0]
|
249 |
# print(prob_cls)
|
250 |
tmp_df = pd.DataFrame.from_dict({'class':LABELS,'probability':prob_cls})
|
251 |
+
fig = plt.figure(figsize=(8, 9))
|
252 |
sns.barplot(x='probability', y='class', data=tmp_df)
|
253 |
middle_column.pyplot(fig)
|
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)
|
|
|
269 |
for each_fn in closest_fns]
|
270 |
# print(closest_fns)
|
271 |
st.subheader('Top-10 Similar Samples from Gallery Set')
|
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 |
|
utils/eval_users.py
CHANGED
@@ -36,13 +36,22 @@ def get_product_dev_page_layout():
|
|
36 |
# # st.caption('Test Set Results:')
|
37 |
st.subheader('Test Set Confusion Matrix')
|
38 |
st.image(f'{ROOT_FIG_DIR}/test_confmat_20210404.png')
|
39 |
-
st.subheader('Prediction Samples')
|
40 |
-
st.caption('Correctly Classified sample predictions:')
|
41 |
-
st.image(f'{ROOT_FIG_DIR}/pred_stats.png')
|
42 |
|
43 |
-
st.caption('Miss Classified sample predictions:')
|
44 |
-
st.image(f'{ROOT_FIG_DIR}/pred_stats.png')
|
45 |
|
46 |
-
st.subheader("Class-wise Prediction Distributions")
|
47 |
-
st.image(f'{ROOT_FIG_DIR}/training_prob_stats.png')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
|
|
36 |
# # st.caption('Test Set Results:')
|
37 |
st.subheader('Test Set Confusion Matrix')
|
38 |
st.image(f'{ROOT_FIG_DIR}/test_confmat_20210404.png')
|
39 |
+
# st.subheader('Prediction Samples')
|
40 |
+
# st.caption('Correctly Classified sample predictions:')
|
41 |
+
# st.image(f'{ROOT_FIG_DIR}/pred_stats.png')
|
42 |
|
43 |
+
# st.caption('Miss Classified sample predictions:')
|
44 |
+
# st.image(f'{ROOT_FIG_DIR}/pred_stats.png')
|
45 |
|
46 |
+
# st.subheader("Class-wise Prediction Distributions")
|
47 |
+
# st.image(f'{ROOT_FIG_DIR}/training_prob_stats.png')
|
48 |
+
|
49 |
+
with row6_3:
|
50 |
+
st.write("Weencountered classimbalance issue and here is the miclassified samples...")
|
51 |
+
|
52 |
+
st.caption('Miss Classified CNV Samples:')
|
53 |
+
st.image(f'{ROOT_FIG_DIR}/cnv_missclass.png')
|
54 |
+
|
55 |
+
st.caption('Miss Classified NORMAL Samples:')
|
56 |
+
st.image(f'{ROOT_FIG_DIR}/normal_missclass.png')
|
57 |
|