Kalbe-x-Bangkit commited on
Commit
4055d22
1 Parent(s): aa253a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -90,6 +90,7 @@ model = load_model()
90
 
91
 
92
  # Utility Functions
 
93
  def upload_to_gcs(image_data: io.BytesIO, filename: str, content_type='application/dicom'):
94
  """Uploads an image to Google Cloud Storage."""
95
  try:
@@ -245,8 +246,17 @@ def grad_cam(input_model, img_array, cls, layer_name):
245
 
246
  # Compute Grad-CAM
247
  def compute_gradcam(model, img_path, layer_name='bn'):
 
 
 
 
 
 
 
 
 
248
  preprocessed_input = load_image(img_path)
249
- predictions = model.predict(preprocessed_input)
250
 
251
  original_image = load_image(img_path, preprocess=False)
252
 
@@ -342,10 +352,6 @@ def redirect_button(url):
342
  if button:
343
  st.markdown(f'<meta http-equiv="refresh" content="0;url={url}" />', unsafe_allow_html=True)
344
 
345
- def load_model():
346
- model = tf.keras.models.load_model('./model_renamed.h5',custom_objects={'DepthwiseConv2D': tf.keras.layers.DepthwiseConv2D})
347
- return model
348
-
349
  ###########################################################################################
350
  ########################### Streamlit Interface ###########################################
351
  ###########################################################################################
 
90
 
91
 
92
  # Utility Functions
93
+
94
  def upload_to_gcs(image_data: io.BytesIO, filename: str, content_type='application/dicom'):
95
  """Uploads an image to Google Cloud Storage."""
96
  try:
 
246
 
247
  # Compute Grad-CAM
248
  def compute_gradcam(model, img_path, layer_name='bn'):
249
+ base_model = keras.applications.DenseNet121(weights = './densenet.hdf5', include_top = False)
250
+ x = base_model.output
251
+ x = GlobalAveragePooling2D()(x)
252
+ predictions = Dense(14, activation = "sigmoid")(x)
253
+ model_gradcam = Model(inputs=base_model.input, outputs=predictions)
254
+ model_gradcam.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001),
255
+ loss='sparse_categorical_crossentropy')
256
+ model.load_weights('./pretrained_model.h5')
257
+
258
  preprocessed_input = load_image(img_path)
259
+ predictions = model_gradcam.predict(preprocessed_input)
260
 
261
  original_image = load_image(img_path, preprocess=False)
262
 
 
352
  if button:
353
  st.markdown(f'<meta http-equiv="refresh" content="0;url={url}" />', unsafe_allow_html=True)
354
 
 
 
 
 
355
  ###########################################################################################
356
  ########################### Streamlit Interface ###########################################
357
  ###########################################################################################