BhumikaMak commited on
Commit
08cda32
·
verified ·
1 Parent(s): 2c5bc35
Files changed (1) hide show
  1. yolov5.py +6 -5
yolov5.py CHANGED
@@ -90,7 +90,6 @@ def xai_yolov5(image,target_lyr = -5, n_components = 8):
90
 
91
  rgb_img_float, batch_explanations, result = dff_nmf(image, target_lyr = -5, n_components = 8)
92
  #result = np.hstack(result)
93
- print("sample...",rgb_img_float.shape,batch_explanations.shape )
94
  im = visualize_batch_explanations(rgb_img_float, batch_explanations) ##########to be displayed
95
 
96
  # Combine results
@@ -234,21 +233,23 @@ def dff_nmf(image, target_lyr, n_components):
234
 
235
  fig.canvas.draw() # Draw the canvas to make sure the image is rendered
236
  image_array = np.array(fig.canvas.renderer.buffer_rgba()) # Convert to numpy array
 
237
  image_resized = cv2.resize(image_array, (640, 640))
238
  rgba_channels = cv2.split(image_resized)
239
- alpha_channel = rgba_channels[3]
240
  rgb_channels = np.stack(rgba_channels[:3], axis=-1)
241
  overlay_img = (alpha_channel[..., None] * image) + ((1 - alpha_channel[..., None]) * rgb_channels)
242
- print("shape....", rgb_img_float.shape, rgb_channels.shape)
243
- #visualization = show_factorization_on_image(rgb_img_float, rgb_channels , image_weight=0.3)
244
 
245
  #temp = image_array.reshape((rgb_img_float.shape[0],rgb_img_float.shape[1]) )
246
  #visualization = show_factorization_on_image(rgb_img_float, image_array.resize((rgb_img_float.shape)) , image_weight=0.3)
247
  results.append(overlay_img)
248
  plt.clf()
249
  #return image_array
 
 
250
  return rgb_img_float, batch_explanations, results
251
 
 
252
  def visualize_batch_explanations(rgb_img_float, batch_explanations, image_weight=0.7):
253
  for i, explanation in enumerate(batch_explanations):
254
  # Create visualization for each explanation
@@ -260,4 +261,4 @@ def visualize_batch_explanations(rgb_img_float, batch_explanations, image_weight
260
  plt.show() # Show the plot
261
  plt.savefig("test_w.png")
262
  print('viz', visualization.shape)
263
- return visualization
 
90
 
91
  rgb_img_float, batch_explanations, result = dff_nmf(image, target_lyr = -5, n_components = 8)
92
  #result = np.hstack(result)
 
93
  im = visualize_batch_explanations(rgb_img_float, batch_explanations) ##########to be displayed
94
 
95
  # Combine results
 
233
 
234
  fig.canvas.draw() # Draw the canvas to make sure the image is rendered
235
  image_array = np.array(fig.canvas.renderer.buffer_rgba()) # Convert to numpy array
236
+ print("____________image_arrya", image_array.shape)
237
  image_resized = cv2.resize(image_array, (640, 640))
238
  rgba_channels = cv2.split(image_resized)
239
+ alpha_channel = rgba_channels[3] / 255.0
240
  rgb_channels = np.stack(rgba_channels[:3], axis=-1)
241
  overlay_img = (alpha_channel[..., None] * image) + ((1 - alpha_channel[..., None]) * rgb_channels)
 
 
242
 
243
  #temp = image_array.reshape((rgb_img_float.shape[0],rgb_img_float.shape[1]) )
244
  #visualization = show_factorization_on_image(rgb_img_float, image_array.resize((rgb_img_float.shape)) , image_weight=0.3)
245
  results.append(overlay_img)
246
  plt.clf()
247
  #return image_array
248
+
249
+
250
  return rgb_img_float, batch_explanations, results
251
 
252
+
253
  def visualize_batch_explanations(rgb_img_float, batch_explanations, image_weight=0.7):
254
  for i, explanation in enumerate(batch_explanations):
255
  # Create visualization for each explanation
 
261
  plt.show() # Show the plot
262
  plt.savefig("test_w.png")
263
  print('viz', visualization.shape)
264
+ return visualization