emiraran commited on
Commit
d426f60
·
verified ·
1 Parent(s): 43b6e40

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -143,7 +143,7 @@ def predict_with_tta(image, n_augmentations=3):
143
  return mean_pred, std_pred
144
 
145
  def generate_gradcam(image, disease_idx):
146
- """Generate Grad-CAM visualization for specific disease"""
147
  if isinstance(image, np.ndarray):
148
  img_pil = Image.fromarray(image.astype('uint8'))
149
  else:
@@ -153,11 +153,11 @@ def generate_gradcam(image, disease_idx):
153
  img_array = np.array(img_resized) / 255.0
154
  img_array = np.expand_dims(img_array, axis=0).astype(np.float32)
155
 
156
- # Generate heatmap
157
  heatmap = make_gradcam_heatmap(img_array, model, last_conv_layer, disease_idx)
158
 
159
- # Overlay on original image
160
- overlaid_image = overlay_heatmap_on_image(img_resized, heatmap, alpha=0.4)
161
 
162
  return overlaid_image
163
 
 
143
  return mean_pred, std_pred
144
 
145
  def generate_gradcam(image, disease_idx):
146
+ """Generate improved Grad-CAM visualization for specific disease"""
147
  if isinstance(image, np.ndarray):
148
  img_pil = Image.fromarray(image.astype('uint8'))
149
  else:
 
153
  img_array = np.array(img_resized) / 255.0
154
  img_array = np.expand_dims(img_array, axis=0).astype(np.float32)
155
 
156
+ # Generate improved heatmap with noise reduction
157
  heatmap = make_gradcam_heatmap(img_array, model, last_conv_layer, disease_idx)
158
 
159
+ # Overlay with better alpha for medical images
160
+ overlaid_image = overlay_heatmap_on_image(img_resized, heatmap, alpha=0.5)
161
 
162
  return overlaid_image
163