Kalbe-x-Bangkit
commited on
Commit
•
716a982
1
Parent(s):
e1f18e1
Update app.py
Browse files
app.py
CHANGED
@@ -201,12 +201,6 @@ def load_image(img_path, preprocess=True, height=320, width=320):
|
|
201 |
x = np.expand_dims(x, axis=0)
|
202 |
return x
|
203 |
|
204 |
-
def rename_layers(model):
|
205 |
-
for layer in model.layers:
|
206 |
-
if '/' in layer.name:
|
207 |
-
layer._name = layer.name.replace('/', '_')
|
208 |
-
return model
|
209 |
-
|
210 |
def grad_cam(input_model, img_array, cls, layer_name):
|
211 |
grad_model = tf.keras.models.Model(
|
212 |
[input_model.inputs],
|
@@ -248,16 +242,9 @@ def compute_gradcam(model_gradcam, img_path, layer_name='bn'):
|
|
248 |
# loss='sparse_categorical_crossentropy')
|
249 |
# model.load_weights('./pretrained_model.h5')
|
250 |
# Load the original model
|
251 |
-
|
252 |
-
|
253 |
-
# Rename the layers
|
254 |
-
modified_model = rename_layers(original_model)
|
255 |
-
|
256 |
-
# Save the modified model
|
257 |
-
modified_model.save('./modified_gradcam_model.h5')
|
258 |
-
|
259 |
# Now use this modified model in your application
|
260 |
-
model_gradcam = keras.models.load_model('./
|
261 |
|
262 |
preprocessed_input = load_image(img_path)
|
263 |
predictions = model_gradcam.predict(preprocessed_input)
|
@@ -509,7 +496,7 @@ if uploaded_file is not None:
|
|
509 |
with col3:
|
510 |
if st.button('Generate Grad-CAM'):
|
511 |
st.write("Loading model...")
|
512 |
-
model_gradcam = keras.models.load_model('./
|
513 |
# Compute and show Grad-CAM
|
514 |
st.write("Generating Grad-CAM visualizations")
|
515 |
try:
|
|
|
201 |
x = np.expand_dims(x, axis=0)
|
202 |
return x
|
203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
def grad_cam(input_model, img_array, cls, layer_name):
|
205 |
grad_model = tf.keras.models.Model(
|
206 |
[input_model.inputs],
|
|
|
242 |
# loss='sparse_categorical_crossentropy')
|
243 |
# model.load_weights('./pretrained_model.h5')
|
244 |
# Load the original model
|
245 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
# Now use this modified model in your application
|
247 |
+
model_gradcam = keras.models.load_model('./model_renamed.h5')
|
248 |
|
249 |
preprocessed_input = load_image(img_path)
|
250 |
predictions = model_gradcam.predict(preprocessed_input)
|
|
|
496 |
with col3:
|
497 |
if st.button('Generate Grad-CAM'):
|
498 |
st.write("Loading model...")
|
499 |
+
model_gradcam = keras.models.load_model('./model_renamed.h5')
|
500 |
# Compute and show Grad-CAM
|
501 |
st.write("Generating Grad-CAM visualizations")
|
502 |
try:
|