marrtinagg commited on
Commit
6317a79
·
1 Parent(s): f240112

Edit app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -35,9 +35,15 @@ def make_gradcam_heatmap(img_array, model, last_conv_layer_name="conv4", pred_in
35
  )
36
  with tf.GradientTape() as tape:
37
  conv_outputs, predictions = grad_model(img_array)
 
 
 
 
 
38
  if pred_index is None:
39
  pred_index = tf.argmax(predictions[0])
40
  class_channel = predictions[:, pred_index]
 
41
  grads = tape.gradient(class_channel, conv_outputs)
42
  pooled_grads = tf.reduce_mean(grads, axis=(0, 1, 2))
43
  conv_outputs = conv_outputs[0]
@@ -87,7 +93,7 @@ def preprocess_and_predict(img_input):
87
  f"Simetría Horizontal: {sim_h}"
88
  )
89
 
90
- # 7. Grad-CAM con ZoomNet (usando la imagen en bruto)
91
  raw_resized = cv2.resize(np.array(img_input), (ROWS, COLS))
92
  raw_array = image.img_to_array(raw_resized) / 255.0
93
  raw_array = np.expand_dims(raw_array, axis=0)
 
35
  )
36
  with tf.GradientTape() as tape:
37
  conv_outputs, predictions = grad_model(img_array)
38
+
39
+ # 👇 Aseguramos que predictions sea tensor
40
+ if isinstance(predictions, list):
41
+ predictions = predictions[0]
42
+
43
  if pred_index is None:
44
  pred_index = tf.argmax(predictions[0])
45
  class_channel = predictions[:, pred_index]
46
+
47
  grads = tape.gradient(class_channel, conv_outputs)
48
  pooled_grads = tf.reduce_mean(grads, axis=(0, 1, 2))
49
  conv_outputs = conv_outputs[0]
 
93
  f"Simetría Horizontal: {sim_h}"
94
  )
95
 
96
+ # 7. Grad-CAM con ZoomNet (imagen en bruto)
97
  raw_resized = cv2.resize(np.array(img_input), (ROWS, COLS))
98
  raw_array = image.img_to_array(raw_resized) / 255.0
99
  raw_array = np.expand_dims(raw_array, axis=0)