PrarthanaTS commited on
Commit
ca858e5
·
1 Parent(s): b386bfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -10
app.py CHANGED
@@ -63,7 +63,7 @@ scaled_anchors = (
63
  * torch.tensor(config.S).unsqueeze(1).unsqueeze(1).repeat(1, 3, 2)
64
  )
65
 
66
- def process_image_and_plot(image,iou_threshold=0.5, threshold=0.4,target_layer=-2):
67
 
68
  transformed_image = transforms(image=image)["image"].unsqueeze(0)
69
  output = model(transformed_image)
@@ -80,13 +80,7 @@ def process_image_and_plot(image,iou_threshold=0.5, threshold=0.4,target_layer=-
80
  bboxes[0], iou_threshold=iou_threshold, threshold=threshold, box_format="midpoint",
81
  )
82
  fig = plot_image(transformed_image[0].permute(1, 2, 0), nms_boxes)
83
-
84
- if target_layer == -2:
85
- layer = [model.model.layers[-2]]
86
- else:
87
- layer = [model.model.layers[-1]]
88
-
89
- cam = YoloCAM(model=model, target_layers=layer, use_cuda=False)
90
 
91
  grayscale_cam = cam(transformed_image, scaled_anchors)[0, :, :]
92
  img = cv2.resize(image, (416, 416))
@@ -129,8 +123,7 @@ description_with_icon = f"""
129
  demo = gr.Interface(process_image_and_plot,
130
  inputs=[gr.Image(label="Input Image"),
131
  gr.Slider(0, 1, value=0.5, label="Intersection over Union (IOU) Threshold",info="Determines how much overlap between two boxes, Set it low to filter out weaker predicts"),
132
- gr.Slider(0, 1, value=0.4, label="Threshold"),
133
- gr.Slider(-2, -1, value=-1, step=1, label="Which Layer?"),],
134
  outputs=[
135
  gr.Plot(label="Output with Classes",),
136
  gr.Image(shape=(32, 32), label="GradCAM Output"),
 
63
  * torch.tensor(config.S).unsqueeze(1).unsqueeze(1).repeat(1, 3, 2)
64
  )
65
 
66
+ def process_image_and_plot(image,iou_threshold=0.5, threshold=0.4):
67
 
68
  transformed_image = transforms(image=image)["image"].unsqueeze(0)
69
  output = model(transformed_image)
 
80
  bboxes[0], iou_threshold=iou_threshold, threshold=threshold, box_format="midpoint",
81
  )
82
  fig = plot_image(transformed_image[0].permute(1, 2, 0), nms_boxes)
83
+ cam = YoloCAM(model=model, target_layers=model.model.layers[-2], use_cuda=False)
 
 
 
 
 
 
84
 
85
  grayscale_cam = cam(transformed_image, scaled_anchors)[0, :, :]
86
  img = cv2.resize(image, (416, 416))
 
123
  demo = gr.Interface(process_image_and_plot,
124
  inputs=[gr.Image(label="Input Image"),
125
  gr.Slider(0, 1, value=0.5, label="Intersection over Union (IOU) Threshold",info="Determines how much overlap between two boxes, Set it low to filter out weaker predicts"),
126
+ gr.Slider(0, 1, value=0.4, label="Threshold"),],
 
127
  outputs=[
128
  gr.Plot(label="Output with Classes",),
129
  gr.Image(shape=(32, 32), label="GradCAM Output"),