Spaces:
Build error
Build error
fix warning message persistence and filter miss
Browse files
app.py
CHANGED
@@ -105,28 +105,42 @@ def main():
|
|
105 |
|
106 |
# Filter index selector
|
107 |
if st.session_state.layer_name:
|
|
|
|
|
|
|
108 |
filter_select = st.selectbox("Visualize -", VIS_OPTION.keys())
|
109 |
|
110 |
if VIS_OPTION[filter_select] == 0:
|
111 |
loss, img = visualize_filter(st.session_state.feat_extract, 0)
|
112 |
st.image(img)
|
113 |
else:
|
114 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
prog_bar = st.progress(0)
|
116 |
fig, axis = plt.subplots(nrows=8, ncols=8, figsize=(14, 14))
|
117 |
-
for filter_index, ax in enumerate(axis.ravel()):
|
118 |
-
prog_bar.progress((filter_index + 1) / 64)
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
ax.set_axis_off()
|
128 |
|
129 |
st.write(fig)
|
|
|
130 |
|
131 |
|
132 |
if __name__ == "__main__":
|
|
|
105 |
|
106 |
# Filter index selector
|
107 |
if st.session_state.layer_name:
|
108 |
+
warn_ph = st.empty()
|
109 |
+
layer_ph = st.empty()
|
110 |
+
|
111 |
filter_select = st.selectbox("Visualize -", VIS_OPTION.keys())
|
112 |
|
113 |
if VIS_OPTION[filter_select] == 0:
|
114 |
loss, img = visualize_filter(st.session_state.feat_extract, 0)
|
115 |
st.image(img)
|
116 |
else:
|
117 |
+
layer = st.session_state.model.get_layer(name=st.session_state.layer_name)
|
118 |
+
num_filters = layer.get_output_at(0).get_shape().as_list()[-1]
|
119 |
+
|
120 |
+
warn_ph.warning(
|
121 |
+
":exclamation: Calculating the gradients can take a while.."
|
122 |
+
)
|
123 |
+
if num_filters < 64:
|
124 |
+
layer_ph.info(
|
125 |
+
f"{st.session_state.layer_name} has only {num_filters} filters, visualizing only those filters.."
|
126 |
+
)
|
127 |
+
|
128 |
prog_bar = st.progress(0)
|
129 |
fig, axis = plt.subplots(nrows=8, ncols=8, figsize=(14, 14))
|
130 |
+
for filter_index, ax in enumerate(axis.ravel()[: min(num_filters, 64)]):
|
131 |
+
prog_bar.progress((filter_index + 1) / min(num_filters, 64))
|
132 |
+
loss, img = visualize_filter(
|
133 |
+
st.session_state.feat_extract, filter_index
|
134 |
+
)
|
135 |
+
ax.imshow(img)
|
136 |
+
ax.set_title(filter_index + 1)
|
137 |
+
ax.set_axis_off()
|
138 |
+
else:
|
139 |
+
for ax in axis.ravel()[num_filters:]:
|
140 |
ax.set_axis_off()
|
141 |
|
142 |
st.write(fig)
|
143 |
+
warn_ph.empty()
|
144 |
|
145 |
|
146 |
if __name__ == "__main__":
|