Update app.py
Browse files
app.py
CHANGED
|
@@ -74,7 +74,25 @@ model = load_model()
|
|
| 74 |
# image = cv2.imdecode(file_bytes, 1)
|
| 75 |
|
| 76 |
# st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
# Utility Functions
|
| 80 |
|
|
@@ -244,7 +262,7 @@ def compute_gradcam(model_gradcam, img_path, layer_name='bn'):
|
|
| 244 |
# Load the original model
|
| 245 |
|
| 246 |
# Now use this modified model in your application
|
| 247 |
-
model_gradcam =
|
| 248 |
|
| 249 |
preprocessed_input = load_image(img_path)
|
| 250 |
predictions = model_gradcam.predict(preprocessed_input)
|
|
@@ -496,7 +514,7 @@ if uploaded_file is not None:
|
|
| 496 |
with col3:
|
| 497 |
if st.button('Generate Grad-CAM'):
|
| 498 |
st.write("Loading model...")
|
| 499 |
-
model_gradcam =
|
| 500 |
# Compute and show Grad-CAM
|
| 501 |
st.write("Generating Grad-CAM visualizations")
|
| 502 |
try:
|
|
|
|
| 74 |
# image = cv2.imdecode(file_bytes, 1)
|
| 75 |
|
| 76 |
# st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
@st.cache_resource
|
| 80 |
+
def load_gradcam_model():
|
| 81 |
+
model = keras.models.load_model('./model_renamed.h5', compile=False)
|
| 82 |
+
model.compile(
|
| 83 |
+
loss={
|
| 84 |
+
"bbox": "mse",
|
| 85 |
+
"class": "sparse_categorical_crossentropy"
|
| 86 |
+
},
|
| 87 |
+
optimizer=tf.keras.optimizers.Adam(),
|
| 88 |
+
metrics={
|
| 89 |
+
"bbox": ['mse'],
|
| 90 |
+
"class": ['accuracy']
|
| 91 |
+
}
|
| 92 |
+
)
|
| 93 |
+
return model
|
| 94 |
+
|
| 95 |
+
model_gradcam = load_gradcam_model()
|
| 96 |
|
| 97 |
# Utility Functions
|
| 98 |
|
|
|
|
| 262 |
# Load the original model
|
| 263 |
|
| 264 |
# Now use this modified model in your application
|
| 265 |
+
model_gradcam = load_gradcam_model()
|
| 266 |
|
| 267 |
preprocessed_input = load_image(img_path)
|
| 268 |
predictions = model_gradcam.predict(preprocessed_input)
|
|
|
|
| 514 |
with col3:
|
| 515 |
if st.button('Generate Grad-CAM'):
|
| 516 |
st.write("Loading model...")
|
| 517 |
+
model_gradcam = load_gradcam_model()
|
| 518 |
# Compute and show Grad-CAM
|
| 519 |
st.write("Generating Grad-CAM visualizations")
|
| 520 |
try:
|