Wolowolo commited on
Commit
bc65635
·
verified ·
1 Parent(s): e0125ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -238,6 +238,10 @@ def FSFM3C_image_detection(image):
238
  }
239
  target_category = TargetCategory(category_names_to_index[max_prob_class])
240
 
 
 
 
 
241
  grayscale_cam = cam(input_tensor=input_tensor, targets=[target_category])
242
  grayscale_cam = 1 - grayscale_cam[0, :]
243
  img = np.array(img)
@@ -250,7 +254,10 @@ def FSFM3C_image_detection(image):
250
  # Add text overlay to the heatmap
251
  # text = f"Detected: {max_prob_class}"
252
  # cv2.putText(visualization, text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
253
- output_path = "./CAM_images/output_heatmap.png"
 
 
 
254
  cv2.imwrite(output_path, visualization)
255
  return image_results, output_path, probabilities[max_prob_index]
256
 
@@ -329,8 +336,10 @@ def FSFM3C_video_detection(video, num_frames):
329
  # Paths and Constants
330
  P = os.path.abspath(__file__)
331
  FRAME_SAVE_PATH = os.path.join(os.path.dirname(P), 'frame')
 
332
  CKPT_SAVE_PATH = os.path.join(os.path.dirname(P), 'checkpoints')
333
  os.makedirs(FRAME_SAVE_PATH, exist_ok=True)
 
334
  os.makedirs(CKPT_SAVE_PATH, exist_ok=True)
335
  CKPT_NAME = [
336
  '✨Unified-detector_v1_Fine-tuned_on_4_classes',
 
238
  }
239
  target_category = TargetCategory(category_names_to_index[max_prob_class])
240
 
241
+ cam = GradCAM(model=model,
242
+ target_layers=[model.blocks[-1].norm1],
243
+ reshape_transform=reshape_transform
244
+ )
245
  grayscale_cam = cam(input_tensor=input_tensor, targets=[target_category])
246
  grayscale_cam = 1 - grayscale_cam[0, :]
247
  img = np.array(img)
 
254
  # Add text overlay to the heatmap
255
  # text = f"Detected: {max_prob_class}"
256
  # cv2.putText(visualization, text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
257
+ cam_path = os.path.join(CAM_SAVE_PATH, str(len(os.listdir(CAM_SAVE_PATH))))
258
+ os.makedirs(cam_path, exist_ok=True)
259
+ os.makedirs(os.path.join(cam_path, '0'), exist_ok=True)
260
+ output_path = os.path.join("output_heatmap.png")
261
  cv2.imwrite(output_path, visualization)
262
  return image_results, output_path, probabilities[max_prob_index]
263
 
 
336
  # Paths and Constants
337
  P = os.path.abspath(__file__)
338
  FRAME_SAVE_PATH = os.path.join(os.path.dirname(P), 'frame')
339
+ CAM_SAVE_PATH = os.path.join(os.path.dirname(P), 'cam')
340
  CKPT_SAVE_PATH = os.path.join(os.path.dirname(P), 'checkpoints')
341
  os.makedirs(FRAME_SAVE_PATH, exist_ok=True)
342
+ os.makedirs(CAM_SAVE_PATH, exist_ok=True)
343
  os.makedirs(CKPT_SAVE_PATH, exist_ok=True)
344
  CKPT_NAME = [
345
  '✨Unified-detector_v1_Fine-tuned_on_4_classes',