Spaces:
Runtime error
Runtime error
Commit
·
4370987
1
Parent(s):
f9c5d15
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -3,6 +3,8 @@ import torch
|
|
| 3 |
import numpy as np
|
| 4 |
import cv2
|
| 5 |
import random
|
|
|
|
|
|
|
| 6 |
|
| 7 |
from pytorch_grad_cam.base_cam import BaseCAM
|
| 8 |
from pytorch_grad_cam.utils.svd_on_activations import get_2d_projection
|
|
@@ -181,4 +183,23 @@ def draw_bounding_boxes(image, boxes, class_labels):
|
|
| 181 |
lineType=cv2.LINE_AA,
|
| 182 |
)
|
| 183 |
|
| 184 |
-
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import cv2
|
| 5 |
import random
|
| 6 |
+
import matplotlib.patches as patches
|
| 7 |
+
import config
|
| 8 |
|
| 9 |
from pytorch_grad_cam.base_cam import BaseCAM
|
| 10 |
from pytorch_grad_cam.utils.svd_on_activations import get_2d_projection
|
|
|
|
| 183 |
lineType=cv2.LINE_AA,
|
| 184 |
)
|
| 185 |
|
| 186 |
+
return image
|
| 187 |
+
|
| 188 |
+
def get_annotations(nms_boxes_output,width, height):
|
| 189 |
+
for box in nms_boxes_output[0]:
|
| 190 |
+
class_prediction = int(box[0])
|
| 191 |
+
box = box[2:]
|
| 192 |
+
|
| 193 |
+
upper_left_x = box[0] - box[2] / 2
|
| 194 |
+
upper_left_y = box[1] - box[3] / 2
|
| 195 |
+
rect = patches.Rectangle(
|
| 196 |
+
(upper_left_x * width, upper_left_y * height),
|
| 197 |
+
box[2] * width,
|
| 198 |
+
box[3] * height,
|
| 199 |
+
linewidth=2,
|
| 200 |
+
edgecolor=colors[class_prediction],
|
| 201 |
+
facecolor="none",
|
| 202 |
+
)
|
| 203 |
+
rect = rect.get_bbox().get_points()
|
| 204 |
+
annotations.append([rect[0].astype(int).tolist()+rect[1].astype(int).tolist(),
|
| 205 |
+
config.PASCAL_CLASSES[class_prediction]])
|